Skip to content

Commit 153c308

Browse files
authored
Fix bug when using ipy with gnureadline and Python 3.13 (#1358)
* Fix bug when using ipy with gnureadline and Python 3.13 * Fix mypy error with IPython stuff * Fix mypy errors when importing stuff from IPython * Updated CHANGELOG with info on bug fix * Added invoke task for cleaning ruff cache directory * Added ruff cache clean invoke task to plugins * Use the "ruff clean" command to clear all ruff cache dirs * Made cmd2/parsing.py non-executable and examples executable
1 parent 285d959 commit 153c308

12 files changed

+30
-5
lines changed

.github/workflows/mypy.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ jobs:
1111
mypy:
1212
runs-on: ubuntu-latest
1313
steps:
14-
- uses: actions/checkout@v4 # https://github.com/actions/checkout
15-
- uses: actions/setup-python@v5 # https://github.com/actions/setup-python
14+
- uses: actions/checkout@v4 # https://github.com/actions/checkout
15+
- uses: actions/setup-python@v5 # https://github.com/actions/setup-python
1616
with:
1717
python-version: 3.13
1818
allow-prereleases: true

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# 2.5.1 (November TBD, 2024)
2+
* Bug Fixes
3+
* Fixed readline bug when using `ipy` command with `gnureadline` and Python 3.13
4+
15
## 2.5.0 (October 23, 2024)
26
* Breaking Change
37
* `cmd2` 2.5 supports Python 3.8+ (removed support for Python 3.6 and 3.7)

cmd2/cmd2.py

+14-3
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,13 @@
128128
StatementParser,
129129
shlex_split,
130130
)
131+
132+
# NOTE: When using gnureadline with Python 3.13, start_ipython needs to be imported before any readline-related stuff
133+
try:
134+
from IPython import start_ipython # type: ignore[import]
135+
except ImportError:
136+
pass
137+
131138
from .rl_utils import (
132139
RlType,
133140
rl_escape_prompt,
@@ -4629,9 +4636,13 @@ def do_ipy(self, _: argparse.Namespace) -> Optional[bool]: # pragma: no cover
46294636
# Detect whether IPython is installed
46304637
try:
46314638
import traitlets.config.loader as TraitletsLoader # type: ignore[import]
4632-
from IPython import ( # type: ignore[import]
4633-
start_ipython,
4634-
)
4639+
4640+
# Allow users to install ipython from a cmd2 prompt when needed and still have ipy command work
4641+
try:
4642+
start_ipython # noqa F823
4643+
except NameError:
4644+
from IPython import start_ipython # type: ignore[import]
4645+
46354646
from IPython.terminal.interactiveshell import ( # type: ignore[import]
46364647
TerminalInteractiveShell,
46374648
)

cmd2/parsing.py

100755100644
File mode changed.

examples/argparse_completion.py

100644100755
File mode changed.

examples/default_categories.py

100644100755
File mode changed.

examples/modular_commands_basic.py

100644100755
File mode changed.

examples/modular_commands_dynamic.py

100644100755
File mode changed.

examples/modular_commands_main.py

100644100755
File mode changed.

examples/modular_subcommands.py

100644100755
File mode changed.

examples/read_input.py

100644100755
File mode changed.

tasks.py

+10
Original file line numberDiff line numberDiff line change
@@ -365,3 +365,13 @@ def format(context):
365365

366366

367367
namespace.add_task(format)
368+
369+
370+
@invoke.task()
371+
def ruff_clean(context):
372+
"""Remove .ruff_cache directory"""
373+
with context.cd(TASK_ROOT_STR):
374+
context.run("ruff clean")
375+
376+
377+
namespace_clean.add_task(ruff_clean, 'ruff')

0 commit comments

Comments
 (0)