Skip to content

Commit

Permalink
null out pythonpath (#252)
Browse files Browse the repository at this point in the history
* fixes #233
  • Loading branch information
AlJohri authored and Chad Smith committed Nov 11, 2019
1 parent 5417f06 commit 8011c12
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 2 deletions.
1 change: 1 addition & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ dev

- Handle missing interpreters more gracefully (#146)
- Change `reinstall-all` to use system python by default for apps. Now use `--python` option to specify a different python version.
- Remove the PYTHONPATH environment variable when executing any command to prevent conflicts between pipx dependencies and package dependenies when pipx is installed via homebrew. Homebrew can use pythonpath manipulation instead of virtual environments. (#233)

0.14.0.0

Expand Down
2 changes: 1 addition & 1 deletion src/pipx/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from .util import PipxError, mkdir
from .venv import VenvContainer

__version__ = "0.14.0.0"
__version__ = "0.14.0.1"


def simple_parse_version(s, segments=4) -> Tuple[Union[int, str], ...]:
Expand Down
3 changes: 2 additions & 1 deletion src/pipx/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,12 @@ def get_site_packages(python: Path) -> Path:
def run(cmd: Sequence[Union[str, Path]], check=True) -> int:
"""Run arbitrary command as subprocess"""

env = {k: v for k, v in os.environ.items() if k.upper() != "PYTHONPATH"}
cmd_str = " ".join(str(c) for c in cmd)
logging.info(f"running {cmd_str}")
# windows cannot take Path objects, only strings
cmd_str_list = [str(c) for c in cmd]
returncode = subprocess.run(cmd_str_list).returncode
returncode = subprocess.run(cmd_str_list, env=env).returncode
if check and returncode:
raise PipxError(f"{cmd_str!r} failed")
return returncode
25 changes: 25 additions & 0 deletions tests/test_run.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#!/usr/bin/env python3
import os
import logging
import sys
import subprocess
from unittest import mock

import pytest # type: ignore
Expand Down Expand Up @@ -42,3 +44,26 @@ def test_run_script_from_internet(pipx_temp_env, capsys):
"6bdfbb6e9c1132b1c38fdd2f195d4a24c540c324/pipx-demo.py",
]
)


def test_run_ensure_null_pythonpath():
env = os.environ.copy()
env["PYTHONPATH"] = "test"
assert (
"None"
in subprocess.run(
[
sys.executable,
"-m",
"pipx",
"run",
"ipython",
"-c",
"import os; print(os.environ.get('PYTHONPATH'))",
],
universal_newlines=True,
env=env,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
).stdout
)

0 comments on commit 8011c12

Please sign in to comment.