Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

null out pythonpath #252

Merged
merged 11 commits into from
Nov 11, 2019
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)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

package dependencies

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry, thought I fixed this. pushed again in my branch but looks like the PR is already merged.

Copy link
Member

@cs01 cs01 Nov 12, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feel free to create another PR


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
)