Skip to content

Commit

Permalink
Fix bug when using ipy with gnureadline and Python 3.13 (#1358)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
tleonhardt authored Nov 2, 2024
1 parent 285d959 commit 153c308
Show file tree
Hide file tree
Showing 12 changed files with 30 additions and 5 deletions.
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')

0 comments on commit 153c308

Please sign in to comment.