Skip to content

Commit

Permalink
feat(install): add support for pre-injected packages (#900)
Browse files Browse the repository at this point in the history
  • Loading branch information
TheKevJames authored Aug 6, 2023
1 parent d8ff189 commit 871782f
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
- Move `pipx` paths to ensure compatibility with the platform-specific user directories
- [docs] Add more examples for `pipx run`
- [docs] Add subsection to make README easier to read
- Add `pipx install --preinstall` to support preinstalling build requirements

## 1.2.0

Expand Down
6 changes: 6 additions & 0 deletions src/pipx/commands/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ def install(
*,
force: bool,
include_dependencies: bool,
preinstall_packages: Optional[List[str]],
suffix: str = "",
) -> ExitCode:
"""Returns pipx exit code."""
Expand Down Expand Up @@ -58,6 +59,11 @@ def install(

try:
venv.create_venv(venv_args, pip_args)
for dep in preinstall_packages or []:
dep_name = package_name_from_spec(
dep, python, pip_args=pip_args, verbose=verbose
)
venv.upgrade_package_no_metadata(dep_name, [])
venv.install_package(
package_name=package_name,
package_or_url=package_spec,
Expand Down
1 change: 1 addition & 0 deletions src/pipx/commands/reinstall.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ def reinstall(
verbose,
force=True,
include_dependencies=venv.pipx_metadata.main_package.include_dependencies,
preinstall_packages=[],
suffix=venv.pipx_metadata.main_package.suffix,
)

Expand Down
9 changes: 9 additions & 0 deletions src/pipx/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ def run_pipx_command(args: argparse.Namespace) -> ExitCode: # noqa: C901
verbose,
force=args.force,
include_dependencies=args.include_deps,
preinstall_packages=args.preinstall,
suffix=args.suffix,
)
elif args.command == "inject":
Expand Down Expand Up @@ -350,6 +351,14 @@ def _add_install(subparsers: argparse._SubParsersAction) -> None:
f"Requires Python {MINIMUM_PYTHON_VERSION} or above."
),
)
p.add_argument(
"--preinstall",
action="append",
help=(
"Optional packages to be installed into the Virtual Environment before "
"installing the main package."
),
)
add_pip_venv_args(p)


Expand Down
4 changes: 2 additions & 2 deletions src/pipx/venv.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ def upgrade_packaging_libraries(self, pip_args: List[str]) -> None:
else:
# TODO: setuptools and wheel? Original code didn't bother
# but shared libs code does.
self._upgrade_package_no_metadata("pip", pip_args)
self.upgrade_package_no_metadata("pip", pip_args)

def uninstall_package(self, package: str, was_injected: bool = False):
try:
Expand Down Expand Up @@ -421,7 +421,7 @@ def has_app(self, app: str, filename: str) -> bool:
return True
return (self.bin_path / filename).is_file()

def _upgrade_package_no_metadata(
def upgrade_package_no_metadata(
self, package_name: str, pip_args: List[str]
) -> None:
with animate(
Expand Down

0 comments on commit 871782f

Please sign in to comment.