예제 #1
0
    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(f"Already upgraded libraries in {self.root}")
            return
        logging.info(f"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
            self.pip_path.touch()

        except Exception:
            logging.error("Failed to upgrade shared libraries", exc_info=True)
예제 #2
0
 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])
         # ignore installed packages to ensure no unexpected patches from the OS vendor
         # are used
         self.upgrade(["--ignore-installed"] + pip_args, verbose)
예제 #3
0
 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")
예제 #4
0
 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)
예제 #5
0
 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
예제 #6
0
 def _run_pip(self, cmd):
     cmd = [self.python_path, "-m", "pip"] + cmd
     if not self.verbose:
         cmd.append("-q")
     return run(cmd)
예제 #7
0
 def run_app(self, app: str, app_args: List[str]):
     cmd = [str(self.bin_path / app)] + app_args
     try:
         return run(cmd, check=False)
     except KeyboardInterrupt:
         pass
예제 #8
0
파일: SharedLibs.py 프로젝트: jayvdb/pipx
 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)