Skip to content

Commit

Permalink
Only insert "" to head of sys.path if a venv PEX runs in interpre…
Browse files Browse the repository at this point in the history
…ter mode (#1984)

Fixes #1983.

Note that this PR doesn't revert the code to use the prior code (`sys.path.extend(os.environ.get("PEX_EXTRA_SYS_PATH", "").split(os.pathsep))`) as that might still add `""` when `PEX_EXTRA_SYS_PATH` is not in the environment.
  • Loading branch information
thejcannon authored Nov 21, 2022
1 parent 0e20ddc commit 632a6ba
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
1 change: 1 addition & 0 deletions pex/pex.py
Original file line number Diff line number Diff line change
Expand Up @@ -628,6 +628,7 @@ def execute_interpreter(self):
# type: () -> Any

# A Python interpreter always inserts the CWD at the head of the sys.path.
# See https://docs.python.org/3/library/sys.html#sys.path
sys.path.insert(0, "")

args = sys.argv[1:]
Expand Down
9 changes: 6 additions & 3 deletions pex/venv/pex.py
Original file line number Diff line number Diff line change
Expand Up @@ -440,9 +440,6 @@ def sys_executable_paths():
os.environ["VIRTUAL_ENV"] = venv_dir
# A Python interpreter always inserts the CWD at the head of the sys.path.
sys.path.insert(0, "")
bin_path = os.environ.get("PEX_VENV_BIN_PATH", {bin_path!r})
if bin_path != "false":
PATH = os.environ.get("PATH", "").split(os.pathsep)
Expand Down Expand Up @@ -498,6 +495,12 @@ def sys_executable_paths():
if pex_interpreter
else pex_overrides.get("PEX_MODULE", {entry_point!r} or PEX_INTERPRETER_ENTRYPOINT)
)
if entry_point == PEX_INTERPRETER_ENTRYPOINT:
# A Python interpreter always inserts the CWD at the head of the sys.path.
# See https://docs.python.org/3/library/sys.html#sys.path
sys.path.insert(0, "")
if entry_point == PEX_INTERPRETER_ENTRYPOINT and len(sys.argv) > 1:
args = sys.argv[1:]
Expand Down

0 comments on commit 632a6ba

Please sign in to comment.