Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _get_list_output(
python_version: str,
python_path: Path,
package_version: str,
package: str,
new_install: bool,
exposed_binary_names: List[str],
unavailable_binary_names: List[str],
) -> str:
output = []
output.append(
f" {'installed' if new_install else ''} package {bold(shlex.quote(package))} {bold(package_version)}, {python_version}"
)
if not python_path.exists():
output.append(f" associated python path {str(python_path)} does not exist!")
if new_install and exposed_binary_names:
output.append(" These apps are now globally available")
for name in exposed_binary_names:
output.append(f" - {name}")
for name in unavailable_binary_names:
output.append(
f" - {red(name)} (symlink missing or pointing to unexpected location)"
)
return "\n".join(output)
)
except PackageInstallFailureError:
raise PipxError(
f"Could not inject package {package}. Is the name or spec correct?"
)
if include_apps:
_run_post_install_actions(
venv,
package,
constants.LOCAL_BIN_DIR,
venv_dir,
include_dependencies,
force=force,
)
print(f" injected package {bold(package)} into venv {bold(venv_dir.name)}")
print(f"done! {stars}", file=sys.stderr)
def get_package_summary(
path: Path, *, package: str = None, new_install: bool = False
) -> str:
venv = Venv(path)
python_path = venv.python_path.resolve()
if package is None:
package = path.name
if not python_path.is_file():
return f" package {red(bold(package))} has invalid interpreter {str(python_path)}"
package_metadata = venv.package_metadata[package]
if package_metadata.package_version is None:
not_installed = red("is not installed")
return f" package {bold(package)} {not_installed} in the venv {str(path)}"
apps = package_metadata.apps + package_metadata.apps_of_dependencies
exposed_app_paths = _get_exposed_app_paths_for_package(
venv.bin_path, apps, constants.LOCAL_BIN_DIR
)
exposed_binary_names = sorted(p.name for p in exposed_app_paths)
unavailable_binary_names = sorted(
set(package_metadata.apps) - set(exposed_binary_names)
)
# The following is to satisfy mypy that python_version is str and not
# Optional[str]
python_version = (
venv.pipx_metadata.python_version
if venv.pipx_metadata.python_version is not None
else ""
)