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(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:
logging.error("Failed to upgrade shared libraries", exc_info=True)
def _run_pip(self, cmd: List[str]) -> int:
cmd = [str(self.python_path), "-m", "pip"] + cmd
if not self.verbose:
cmd.append("-q")
return run(cmd)
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
self.pipx_metadata.python_version = self.get_python_version()
def run_app(self, app: str, app_args: List[str]) -> int:
cmd = [str(self.bin_path / app)] + app_args
try:
return run(cmd, check=False)
except KeyboardInterrupt:
return 130 # shell code for Ctrl-C