|
7 | 7 | import io
|
8 | 8 | import subprocess
|
9 | 9 | import platform
|
| 10 | +import pathlib |
| 11 | +import textwrap |
10 | 12 |
|
11 | 13 | from setuptools.command import test
|
12 | 14 |
|
@@ -199,3 +201,55 @@ def test_namespace_package_importable(self, tmpdir):
|
199 | 201 | ]
|
200 | 202 | with test.test.paths_on_pythonpath([str(target)]):
|
201 | 203 | subprocess.check_call(pkg_resources_imp)
|
| 204 | + |
| 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 | + |
| 216 | + @pytest.mark.xfail( |
| 217 | + platform.python_implementation() == 'PyPy', |
| 218 | + reason="Workaround fails on PyPy (why?)", |
| 219 | + ) |
| 220 | + def test_editable_prefix(self, tmp_path, sample_project): |
| 221 | + """ |
| 222 | + Editable install to a prefix should be discoverable. |
| 223 | + """ |
| 224 | + prefix = tmp_path / 'prefix' |
| 225 | + prefix.mkdir() |
| 226 | + |
| 227 | + # figure out where pip will likely install the package |
| 228 | + site_packages = prefix / next( |
| 229 | + pathlib.Path(path).relative_to(sys.prefix) |
| 230 | + for path in sys.path |
| 231 | + if 'site-packages' in path |
| 232 | + and path.startswith(sys.prefix) |
| 233 | + ) |
| 234 | + |
| 235 | + # install the workaround |
| 236 | + self.install_workaround(site_packages) |
| 237 | + |
| 238 | + env = dict(os.environ, PYTHONPATH=str(site_packages)) |
| 239 | + cmd = [ |
| 240 | + sys.executable, |
| 241 | + '-m', 'pip', |
| 242 | + 'install', |
| 243 | + '--editable', |
| 244 | + str(sample_project), |
| 245 | + '--prefix', str(prefix), |
| 246 | + '--no-build-isolation', |
| 247 | + ] |
| 248 | + subprocess.check_call(cmd, env=env) |
| 249 | + |
| 250 | + # now run 'sample' with the prefix on the PYTHONPATH |
| 251 | + bin = 'Scripts' if platform.system() == 'Windows' else 'bin' |
| 252 | + exe = prefix / bin / 'sample' |
| 253 | + if sys.version_info < (3, 7) and platform.system() == 'Windows': |
| 254 | + exe = str(exe) |
| 255 | + subprocess.check_call([exe], env=env) |
0 commit comments