Skip to content

Commit fba672c

Browse files
committed
Use a .pth file instead of sitecustomize.py
1 parent bc1dfea commit fba672c

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

ts/utils/inherit_site_packages.py

+7-6
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,18 @@ def inherit_site_packages(venv_path):
2121
len(target_venv_glob_matches) == 1
2222
), f"{__file__} expected to find one supported python version in venv {venv_path} but found: {target_venv_glob_matches}"
2323

24-
# Create sitecustomize.py in target venv site-packages directory
25-
# Ref: https://docs.python.org/3/library/site.html#module-sitecustomize
26-
with open(os.path.join(target_venv_glob_matches[0], "sitecustomize.py"), "w") as f:
27-
f.write("import site\n\n")
24+
# Create a .pth file with site-packages directories to inherit, in the target venv site-packages directory
25+
# Ref: https://docs.python.org/3/library/site.html#module-site
26+
with open(
27+
os.path.join(target_venv_glob_matches[0], "inherited-site-packages.pth"), "w"
28+
) as f:
2829
for site_packages_dir in site.getsitepackages():
29-
f.write(f'site.addsitedir("{site_packages_dir}")\n')
30+
f.write(f"{site_packages_dir}\n")
3031
print(site_packages_dir)
3132

3233

3334
if __name__ == "__main__":
3435
assert (
3536
len(sys.argv) == 2
36-
), f"{__file__} expects one argument: path to venv that should inherit site-packages of the current venv but got {sys.argv}"
37+
), f"{__file__} expects one argument: path to venv that should inherit site-packages of the current environment but got {sys.argv}"
3738
inherit_site_packages(sys.argv[1])

0 commit comments

Comments
 (0)