diff options
author | Jason R. Coombs <jaraco@jaraco.com> | 2021-03-21 03:38:43 -0400 |
---|---|---|
committer | Jason R. Coombs <jaraco@jaraco.com> | 2021-03-21 03:40:00 -0400 |
commit | cb962021c53b7130bf0a1792f75678efcc0724be (patch) | |
tree | 4074d1c1d7fb4a5bb96cf9f56712a9b7d10d50b0 | |
parent | b4d8e4755eafc786a9848333ca73bff381747745 (diff) | |
download | python-setuptools-git-cb962021c53b7130bf0a1792f75678efcc0724be.tar.gz |
Illustrate how one might leverage sitecustomize.py to make a project available on PYTHONPATH. Fixes #2612.
-rw-r--r-- | setuptools/tests/test_develop.py | 42 |
1 files changed, 30 insertions, 12 deletions
diff --git a/setuptools/tests/test_develop.py b/setuptools/tests/test_develop.py index e793c36d..0dea40bd 100644 --- a/setuptools/tests/test_develop.py +++ b/setuptools/tests/test_develop.py @@ -8,6 +8,7 @@ import io import subprocess import platform import pathlib +import textwrap from setuptools.command import test @@ -201,7 +202,17 @@ class TestNamespaces: with test.test.paths_on_pythonpath([str(target)]): subprocess.check_call(pkg_resources_imp) - @pytest.mark.xfail(reason="#2612") + @staticmethod + def install_workaround(site_packages): + site_packages.mkdir(parents=True) + sc = site_packages / 'sitecustomize.py' + sc.write_text(textwrap.dedent(""" + import site + import pathlib + here = pathlib.Path(__file__).parent + site.addsitedir(str(here)) + """).lstrip()) + def test_editable_prefix(self, tmp_path, sample_project): """ Editable install to a prefix should be discoverable. @@ -209,23 +220,30 @@ class TestNamespaces: prefix = tmp_path / 'prefix' prefix.mkdir() + # figure out where pip will likely install the package + site_packages = prefix / next( + pathlib.Path(path).relative_to(sys.prefix) + for path in sys.path + if 'site-packages' in path + and path.startswith(sys.prefix) + ) + + # install the workaround + self.install_workaround(site_packages) + + env = dict(PYTHONPATH=site_packages) cmd = [ sys.executable, '-m', 'pip', 'install', - '-e', str(sample_project), + '--editable', + str(sample_project), '--prefix', str(prefix), + '--no-build-isolation', ] - subprocess.check_call(cmd) + subprocess.check_call(cmd, env=env) # now run 'sample' with the prefix on the PYTHONPATH - site_packages = prefix / next( - pathlib.Path(path).relative_to(sys.prefix) - for path in sys.path - if 'site-packages' in path - and path.startswith(sys.prefix) - ) - env = dict(PYTHONPATH=site_packages) bin = 'Scripts' if platform.system() == 'Windows' else 'bin' - sample = prefix / bin / 'sample' - subprocess.check_call([sample], env=env) + exe = prefix / bin / 'sample' + subprocess.check_call([exe], env=env) |