Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def upgrade_package(
self,
package: str,
package_or_url: str,
pip_args: List[str],
include_dependencies: bool,
include_apps: bool,
is_main_package: bool,
) -> None:
with animate(f"upgrading package {package_or_url!r}", self.do_animation):
self._run_pip(["install"] + pip_args + ["--upgrade", package_or_url])
self._update_package_metadata(
package=package,
package_or_url=package_or_url,
pip_args=pip_args,
include_dependencies=include_dependencies,
include_apps=include_apps,
is_main_package=is_main_package,
)
def _upgrade_package_no_metadata(
self, package_or_url: str, pip_args: List[str]
) -> None:
with animate(f"upgrading package {package_or_url!r}", self.do_animation):
self._run_pip(["install"] + pip_args + ["--upgrade", package_or_url])
def upgrade(self, pip_args: List[str], verbose: bool = False):
# Don't try to upgrade multiple times per run
if self.has_been_updated_this_run:
logging.info("Already upgraded libraries in", self.root)
return
logging.info("Upgrading shared libraries in", self.root)
ignored_args = ["--editable"]
_pip_args = [arg for arg in pip_args if arg not in ignored_args]
if not verbose:
_pip_args.append("-q")
try:
with animate("upgrading shared libraries", not verbose):
run(
[
self.python_path,
"-m",
"pip",
"--disable-pip-version-check",
"install",
*_pip_args,
"--upgrade",
"pip",
"setuptools",
"wheel",
]
)
self.has_been_updated_this_run = True
except Exception:
def install_package(
self,
package: Optional[str], # if None, will be determined in this function
package_or_url: str,
pip_args: List[str],
include_dependencies: bool,
include_apps: bool,
is_main_package: bool,
) -> None:
with animate(f"installing package {package_or_url!r}", self.do_animation):
if pip_args is None:
pip_args = []
if package is None:
# If no package name is supplied, install only main package
# first in order to see what its name is
old_package_set = self.list_installed_packages()
cmd = ["install"] + pip_args + ["--no-dependencies"] + [package_or_url]
self._run_pip(cmd)
installed_packages = self.list_installed_packages() - old_package_set
if len(installed_packages) == 1:
package = installed_packages.pop()
logging.info(f"Determined package name: '{package}'")
else:
package = None
cmd = ["install"] + pip_args + [package_or_url]
self._run_pip(cmd)
def create(self, pip_args: List[str], verbose: bool = False):
if not self.is_valid:
with animate("creating shared libraries", not verbose):
run([DEFAULT_PYTHON, "-m", "venv", "--clear", self.root])
self.upgrade(pip_args, verbose)
def create_venv(self, venv_args: List[str], pip_args: List[str]) -> None:
with animate("creating virtual environment", self.do_animation):
cmd = [self._python, "-m", "venv", "--without-pip"]
run(cmd + venv_args + [str(self.root)])
shared_libs.create(pip_args, self.verbose)
pipx_pth = get_site_packages(self.python_path) / PIPX_SHARED_PTH
# write path pointing to the shared libs site-packages directory
# example pipx_pth location:
# ~/.local/pipx/venvs/black/lib/python3.8/site-packages/pipx_shared.pth
# example shared_libs.site_packages location:
# ~/.local/pipx/shared/lib/python3.6/site-packages
#
# https://docs.python.org/3/library/site.html
# A path configuration file is a file whose name has the form 'name.pth'.
# its contents are additional items (one per line) to be added to sys.path
pipx_pth.write_text(str(shared_libs.site_packages) + "\n", encoding="utf-8")
self.pipx_metadata.venv_args = venv_args