File tree Expand file tree Collapse file tree 3 files changed +16
-11
lines changed
src/pyproject_hooks/_in_process Expand file tree Collapse file tree 3 files changed +16
-11
lines changed Original file line number Diff line number Diff line change @@ -348,6 +348,13 @@ def main():
348348 control_dir = sys .argv [2 ]
349349 if hook_name not in HOOK_NAMES :
350350 sys .exit ("Unknown hook: %s" % hook_name )
351+
352+ # Remove the parent directory from sys.path to avoid polluting the backend
353+ # import namespace with this directory.
354+ here = os .path .dirname (__file__ )
355+ if here in sys .path :
356+ sys .path .remove (here )
357+
351358 hook = globals ()[hook_name ]
352359
353360 hook_input = read_json (pjoin (control_dir , "input.json" ))
Original file line number Diff line number Diff line change 11import json
22import sys
3- from os import environ , listdir , path
3+ from os import environ , path
44
55from setuptools import setup
66
7- children = listdir ( sys .path [ 0 ])
7+ captured_sys_path = sys .path
88out = path .join (environ ["TEST_POLLUTION_OUTDIR" ], "out.json" )
99with open (out , "w" ) as f :
10- json .dump (children , f )
10+ json .dump (captured_sys_path , f )
1111
1212setup ()
Original file line number Diff line number Diff line change 1616 UnsupportedOperation ,
1717 default_subprocess_runner ,
1818)
19+ from pyproject_hooks ._in_process import _in_proc_script_path as in_proc_script_path
1920from tests .compat import tomllib
2021
2122SAMPLES_DIR = pjoin (dirname (abspath (__file__ )), "samples" )
@@ -196,14 +197,11 @@ def test_path_pollution():
196197 ):
197198 hooks .get_requires_for_build_wheel ({})
198199 with open (pjoin (outdir , "out.json" )) as f :
199- children = json .load (f )
200- assert set (children ) <= {
201- "__init__.py" ,
202- "__init__.pyc" ,
203- "_in_process.py" ,
204- "_in_process.pyc" ,
205- "__pycache__" ,
206- }
200+ captured_sys_path = json .load (f )
201+
202+ with in_proc_script_path () as path :
203+ assert os .path .dirname (path ) not in captured_sys_path
204+ assert captured_sys_path [0 ] == BUILDSYS_PKGS
207205
208206
209207def test_setup_py ():
You can’t perform that action at this time.
0 commit comments