Skip to content

Commit

Permalink
fix: fix the module loading of pth files for install cache
Browse files Browse the repository at this point in the history
Fix #863
  • Loading branch information
frostming committed Nov 15, 2022
1 parent 46c7e63 commit 26f2a17
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
1 change: 1 addition & 0 deletions news/863.bugfix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix the module missing error of pywin32 in a virtualenv with `install.cache` set to `true` and caching method is `pth`.
11 changes: 6 additions & 5 deletions src/pdm/installers/installers.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ def install_wheel_with_cache(
package_cache = CachedPackage(cache_path)
interpreter = str(environment.interpreter.executable)
script_kind = _get_kind(environment)
supports_symlink = (
use_symlink = (
environment.project.config["install.cache_method"] == "symlink"
and fs_supports_symlink()
)
Expand Down Expand Up @@ -228,17 +228,18 @@ def skip_files(source: WheelFile, element: WheelContentElement) -> bool:
or path.split("/")[0].endswith(".dist-info")
# We need to skip the *-nspkg.pth files generated by setuptools'
# namespace_packages merchanism. See issue#623 for details
or not supports_symlink
or not use_symlink
and path.endswith(".pth")
and not path.endswith("-nspkg.pth")
)

additional_contents: list[WheelContentElement] = []
lib_path = package_cache.scheme()["purelib"]
if not supports_symlink:
if not use_symlink:
# HACK: Prefix with aaa_ to make it processed as early as possible
filename = "aaa_" + wheel_stem.split("-")[0] + ".pth"
stream = io.BytesIO(f"{lib_path}\n".encode())
# use site.addsitedir() rather than a plain path to properly process .pth files
stream = io.BytesIO(f"import site;site.addsitedir({lib_path!r})\n".encode())
additional_contents.append(
((filename, "", str(len(stream.getvalue()))), stream, False)
)
Expand All @@ -247,7 +248,7 @@ def skip_files(source: WheelFile, element: WheelContentElement) -> bool:
scheme_dict=environment.get_paths(),
interpreter=interpreter,
script_kind=script_kind,
symlink_to=lib_path if supports_symlink else None,
symlink_to=lib_path if use_symlink else None,
)

dist_info_dir = _install_wheel(
Expand Down

0 comments on commit 26f2a17

Please sign in to comment.