Skip to content

Fix bug when using ipy with gnureadline and Python 3.13 #1358

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Nov 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/mypy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ jobs:
mypy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4 # https://github.com/actions/checkout
- uses: actions/setup-python@v5 # https://github.com/actions/setup-python
- uses: actions/checkout@v4 # https://github.com/actions/checkout
- uses: actions/setup-python@v5 # https://github.com/actions/setup-python
with:
python-version: 3.13
allow-prereleases: true
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 2.5.1 (November TBD, 2024)
* Bug Fixes
* Fixed readline bug when using `ipy` command with `gnureadline` and Python 3.13

## 2.5.0 (October 23, 2024)
* Breaking Change
* `cmd2` 2.5 supports Python 3.8+ (removed support for Python 3.6 and 3.7)
Expand Down
17 changes: 14 additions & 3 deletions cmd2/cmd2.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,13 @@
StatementParser,
shlex_split,
)

# NOTE: When using gnureadline with Python 3.13, start_ipython needs to be imported before any readline-related stuff
try:
from IPython import start_ipython # type: ignore[import]
except ImportError:
pass

from .rl_utils import (
RlType,
rl_escape_prompt,
Expand Down Expand Up @@ -4629,9 +4636,13 @@ def do_ipy(self, _: argparse.Namespace) -> Optional[bool]: # pragma: no cover
# Detect whether IPython is installed
try:
import traitlets.config.loader as TraitletsLoader # type: ignore[import]
from IPython import ( # type: ignore[import]
start_ipython,
)

# Allow users to install ipython from a cmd2 prompt when needed and still have ipy command work
try:
start_ipython # noqa F823
except NameError:
from IPython import start_ipython # type: ignore[import]

from IPython.terminal.interactiveshell import ( # type: ignore[import]
TerminalInteractiveShell,
)
Expand Down
Empty file modified cmd2/parsing.py
100755 → 100644
Empty file.
Empty file modified examples/argparse_completion.py
100644 → 100755
Empty file.
Empty file modified examples/default_categories.py
100644 → 100755
Empty file.
Empty file modified examples/modular_commands_basic.py
100644 → 100755
Empty file.
Empty file modified examples/modular_commands_dynamic.py
100644 → 100755
Empty file.
Empty file modified examples/modular_commands_main.py
100644 → 100755
Empty file.
Empty file modified examples/modular_subcommands.py
100644 → 100755
Empty file.
Empty file modified examples/read_input.py
100644 → 100755
Empty file.
10 changes: 10 additions & 0 deletions tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -365,3 +365,13 @@ def format(context):


namespace.add_task(format)


@invoke.task()
def ruff_clean(context):
"""Remove .ruff_cache directory"""
with context.cd(TASK_ROOT_STR):
context.run("ruff clean")


namespace_clean.add_task(ruff_clean, 'ruff')
Loading