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_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
) -> 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)
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 ""