Skip to content

Commit

Permalink
Fix the isolation of build env (#478)
Browse files Browse the repository at this point in the history
  • Loading branch information
frostming authored May 25, 2021
1 parent bddefa5 commit 4db146f
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 10 deletions.
1 change: 1 addition & 0 deletions news/477.bugfix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix a bug that build environment is not fully isolated with the hosted environment.
12 changes: 5 additions & 7 deletions pdm/builders/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,23 +99,21 @@ def __init__(self, executable: str, path: str) -> None:
with open(os.path.join(self.site_dir, "sitecustomize.py"), "w") as fp:
fp.write(
textwrap.dedent(
"""
f"""
import sys, os, site
original_sys_path = sys.path[:]
known_paths = set()
site.addusersitepackages(known_paths)
site.addsitepackages(known_paths)
known_paths = {{os.path.normpath(p) for p in known_paths}}
known_paths = {{os.path.normcase(p) for p in known_paths}}
original_sys_path = [
p for p in original_sys_path
if os.path.normpath(p) not in known_paths]
if os.path.normcase(p) not in known_paths]
sys.path[:] = original_sys_path
for lib_path in {lib_paths!r}:
for lib_path in {self.lib_dirs!r}:
site.addsitedir(lib_path)
""".format(
lib_paths=self.lib_dirs
)
"""
)
)

Expand Down
6 changes: 5 additions & 1 deletion pdm/cli/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,11 @@ def version_matcher(py_version: PythonInfo) -> bool:
)
)
project.python = selected_python
if old_path and Path(old_path) != Path(new_path) and not project.is_global:
if (
old_path
and Path(old_path) != Path(new_path)
and not project.environment.is_global
):
project.core.ui.echo(termui.cyan("Updating executable scripts..."))
project.environment.update_shebangs(new_path)

Expand Down
2 changes: 1 addition & 1 deletion pdm/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ def find_python_in_path(path: os.PathLike) -> Path | None:
- A valid path to the interpreter
- A Python root directory that contains the interpreter
"""
pathlib_path = Path(path).absolute()
pathlib_path = Path(path).resolve()
if pathlib_path.is_file():
return pathlib_path

Expand Down
5 changes: 4 additions & 1 deletion tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,10 @@ def test_expend_env_vars_in_auth(given, expected, monkeypatch):

def test_find_python_in_path(tmp_path):

assert utils.find_python_in_path(sys.executable) == pathlib.Path(sys.executable)
assert (
utils.find_python_in_path(sys.executable)
== pathlib.Path(sys.executable).resolve()
)

posix_path_to_executable = pathlib.Path(sys.executable).as_posix().lower()
if sys.platform == "darwin":
Expand Down

0 comments on commit 4db146f

Please sign in to comment.