From 76ac69f8291fabfa8bb7b2bda0053fa84824ef57 Mon Sep 17 00:00:00 2001 From: Chad Smith Date: Mon, 5 Nov 2018 08:21:58 -0800 Subject: [PATCH] cast all Paths to str when running subprocesses; add .exe suffix (#30) --- get-pipx.py | 22 +++++++++------------- pipx/main.py | 10 ++++++---- 2 files changed, 15 insertions(+), 17 deletions(-) diff --git a/get-pipx.py b/get-pipx.py index e012b54ade..7d1fa17306 100644 --- a/get-pipx.py +++ b/get-pipx.py @@ -80,7 +80,7 @@ def upgrade_package(self, package): self._run_pip(["install", "--upgrade", package]) def _run_pip(self, cmd): - cmd = [self.python_path, "-m", "pip"] + cmd + cmd = [str(self.python_path), "-m", "pip"] + cmd if not self.verbose: cmd.append("-q") _run(cmd) @@ -111,23 +111,19 @@ def ensure_pipx_on_path(bin_dir, modify_path): else: f.write('export PATH="%s:$PATH"\n' % bin_dir) echo("Added %s to the PATH environment variable in %s" % (bin_dir, config_file)) + echo("") echo("Open a new terminal to use pipx") else: echo( textwrap.dedent( - """ - %(sep)s + f""" + Note: + To finish installation, {str(bin_dir)!r} must be added to your PATH. + This can be done by adding the following line to your shell + config file (such as ~/.bashrc if using bash): - Note: - To finish installation, %(bin_dir)s must be added to your PATH. - This can be done by adding the following line to your shell - config file: - - export PATH=%(bin_dir)s:$PATH - - %(sep)s + export PATH={str(bin_dir)}:$PATH """ - % {"sep": "=" * 60, "bin_dir": bin_dir} ) ) @@ -153,7 +149,7 @@ def install( venv = Venv(venv_dir, python=python, verbose=verbose) venv.create_venv() venv.install_package(package) - binary = venv.bin_path / "pipx" + binary = venv.bin_path / "pipx" if not WINDOWS else venv.bin_path / "pipx.exe" if not binary.is_file(): fail(f"Expected to find {str(binary)}") diff --git a/pipx/main.py b/pipx/main.py index 0fbe6e01b3..00d1f3f22b 100644 --- a/pipx/main.py +++ b/pipx/main.py @@ -93,7 +93,8 @@ def get_package_dependencies(self, package: str) -> List[str]: ) return ( subprocess.run( - [self.python_path, "-c", get_version_script], stdout=subprocess.PIPE + [str(self.python_path), "-c", get_version_script], + stdout=subprocess.PIPE, ) .stdout.decode() .split() @@ -111,7 +112,7 @@ def get_package_version(self, package: str) -> Optional[str]: ) version = ( subprocess.run( - [self.python_path, "-c", get_version_script], + [str(self.python_path), "-c", get_version_script], stdout=subprocess.PIPE, stderr=subprocess.DEVNULL, ) @@ -167,7 +168,8 @@ def get_package_binary_paths(self, package: str) -> List[Path]: return [] binaries = ( subprocess.run( - [self.python_path, "-c", get_binaries_script], stdout=subprocess.PIPE + [str(self.python_path), "-c", get_binaries_script], + stdout=subprocess.PIPE, ) .stdout.decode() .split() @@ -550,7 +552,7 @@ def run_ephemeral_binary(args, binary_args): # download and run directly r = requests.get(binary) try: - exit(subprocess.run([args.python, "-c", r.content]).returncode) + exit(subprocess.run([str(args.python), "-c", r.content]).returncode) except KeyboardInterrupt: pass exit(0)