Skip to content

Commit

Permalink
Added with-suffix option for pipx inject command (#939)
Browse files Browse the repository at this point in the history
Co-authored-by: Bernát Gábor <[email protected]>
  • Loading branch information
chrysle and gaborbernat authored Nov 30, 2023
1 parent 51f78b7 commit d4798ea
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## dev

- Add `--with-suffix` for `pipx inject` command
- `pipx install`: emit a warning when `--force` and `--python` were passed at the same time
- Drop support for Python 3.7
- Make usage message in `pipx run` show `package_or_url`, so extra will be printed out as well
Expand Down
7 changes: 7 additions & 0 deletions src/pipx/commands/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,13 @@ def run_post_install_actions(

display_name = f"{package_name}{package_metadata.suffix}"

if (
not venv.main_package_name == package_name
and venv.package_metadata[venv.main_package_name].suffix
== package_metadata.suffix
):
package_name = display_name

if not package_metadata.apps:
if not package_metadata.apps_of_dependencies:
if venv.safe_to_remove():
Expand Down
9 changes: 8 additions & 1 deletion src/pipx/commands/inject.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ def inject_dep(
include_apps: bool,
include_dependencies: bool,
force: bool,
suffix: bool = False,
) -> bool:
if not venv_dir.exists() or not next(venv_dir.iterdir()):
raise PipxError(
Expand Down Expand Up @@ -53,14 +54,18 @@ def inject_dep(
pip_args=pip_args,
verbose=verbose,
)

if suffix:
venv_suffix = venv.package_metadata[venv.main_package_name].suffix
else:
venv_suffix = ""
venv.install_package(
package_name=package_name,
package_or_url=package_spec,
pip_args=pip_args,
include_dependencies=include_dependencies,
include_apps=include_apps,
is_main_package=False,
suffix=venv_suffix,
)
if include_apps:
run_post_install_actions(
Expand Down Expand Up @@ -89,6 +94,7 @@ def inject(
include_apps: bool,
include_dependencies: bool,
force: bool,
suffix: bool = False,
) -> ExitCode:
"""Returns pipx exit code."""
if not include_apps and include_dependencies:
Expand All @@ -106,6 +112,7 @@ def inject(
include_apps=include_apps,
include_dependencies=include_dependencies,
force=force,
suffix=suffix,
)

# Any failure to install will raise PipxError, otherwise success
Expand Down
6 changes: 6 additions & 0 deletions src/pipx/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ def run_pipx_command(args: argparse.Namespace) -> ExitCode: # noqa: C901
include_apps=args.include_apps,
include_dependencies=args.include_deps,
force=args.force,
suffix=args.with_suffix,
)
elif args.command == "uninject":
return commands.uninject(
Expand Down Expand Up @@ -392,6 +393,11 @@ def _add_inject(subparsers, venv_completer: VenvCompleter) -> None:
help="Modify existing virtual environment and files in PIPX_BIN_DIR",
)
p.add_argument("--verbose", action="store_true")
p.add_argument(
"--with-suffix",
action="store_true",
help="Add the suffix (if given) of the Virtual Environment to the packages to inject",
)


def _add_uninject(subparsers, venv_completer: VenvCompleter):
Expand Down

0 comments on commit d4798ea

Please sign in to comment.