Skip to content

Commit e097c21

Browse files
committed
Illustrate how one might leverage sitecustomize.py to make a project available on PYTHONPATH. Fixes #2165.
1 parent b4d8e47 commit e097c21

File tree

1 file changed

+30
-12
lines changed

1 file changed

+30
-12
lines changed

setuptools/tests/test_develop.py

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import subprocess
99
import platform
1010
import pathlib
11+
import textwrap
1112

1213
from setuptools.command import test
1314

@@ -201,31 +202,48 @@ def test_namespace_package_importable(self, tmpdir):
201202
with test.test.paths_on_pythonpath([str(target)]):
202203
subprocess.check_call(pkg_resources_imp)
203204

204-
@pytest.mark.xfail(reason="#2612")
205+
@staticmethod
206+
def install_workaround(site_packages):
207+
site_packages.mkdir(parents=True)
208+
sc = site_packages / 'sitecustomize.py'
209+
sc.write_text(textwrap.dedent("""
210+
import site
211+
import pathlib
212+
here = pathlib.Path(__file__).parent
213+
site.addsitedir(str(here))
214+
""").lstrip())
215+
205216
def test_editable_prefix(self, tmp_path, sample_project):
206217
"""
207218
Editable install to a prefix should be discoverable.
208219
"""
209220
prefix = tmp_path / 'prefix'
210221
prefix.mkdir()
211222

223+
# figure out where pip will likely install the package
224+
site_packages = prefix / next(
225+
pathlib.Path(path).relative_to(sys.prefix)
226+
for path in sys.path
227+
if 'site-packages' in path
228+
and path.startswith(sys.prefix)
229+
)
230+
231+
# install the workaround
232+
self.install_workaround(site_packages)
233+
234+
env = dict(PYTHONPATH=site_packages)
212235
cmd = [
213236
sys.executable,
214237
'-m', 'pip',
215238
'install',
216-
'-e', str(sample_project),
239+
'--editable',
240+
str(sample_project),
217241
'--prefix', str(prefix),
242+
'--no-build-isolation',
218243
]
219-
subprocess.check_call(cmd)
244+
subprocess.check_call(cmd, env=env)
220245

221246
# now run 'sample' with the prefix on the PYTHONPATH
222-
site_packages = prefix / next(
223-
pathlib.Path(path).relative_to(sys.prefix)
224-
for path in sys.path
225-
if 'site-packages' in path
226-
and path.startswith(sys.prefix)
227-
)
228-
env = dict(PYTHONPATH=site_packages)
229247
bin = 'Scripts' if platform.system() == 'Windows' else 'bin'
230-
sample = prefix / bin / 'sample'
231-
subprocess.check_call([sample], env=env)
248+
exe = prefix / bin / 'sample'
249+
subprocess.check_call([exe], env=env)

0 commit comments

Comments
 (0)