Skip to content

Commit

Permalink
Add debug ipython command
Browse files Browse the repository at this point in the history
This can help developers to drop quite fast into a interactive python
shell with a usable pulp_ctx preconfigured.

[noissue]
  • Loading branch information
mdellweg committed Mar 14, 2024
1 parent 9572977 commit 8437376
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGES/+ipython.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Added `pulp debug ipython` command to drop into a python shell.
36 changes: 36 additions & 0 deletions pulpcore/cli/common/debug.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@
pulp_group,
)

try:
import IPython
except ImportError:
IPYTHON_AVAILABLE = False
else:
IPYTHON_AVAILABLE = True

translation = get_translation(__package__)
_ = translation.gettext

Expand All @@ -23,6 +30,35 @@ def debug() -> None:
"""


if IPYTHON_AVAILABLE:

@debug.command()
@pass_pulp_context
@click.pass_context
def ipython(
ctx: click.Context,
pulp_ctx: PulpCLIContext,
) -> None:
"""
Drop into an interactive python shell.
Prepopulated symbols:
- click
- PluginRequirement
- ctx: click.Context
- pulp_ctx: PulpContext
"""
user_ns: t.Dict[str, t.Any] = {
# modules
"click": click,
# Classes
"PluginRequirement": PluginRequirement,
# Objects
"ctx": ctx,
"pulp_ctx": pulp_ctx,
}
IPython.start_ipython(argv=[], user_ns=user_ns)


@debug.command()
@click.option("--name", required=True)
@click.option("--min-version", help=_("Succeed only if the installed version is not smaller."))
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ explicit_package_bases = true
module = [
"click_shell.*",
"gnupg.*",
"IPython.*",
"schema.*",
]
ignore_missing_imports = true

0 comments on commit 8437376

Please sign in to comment.