|
8 | 8 | import subprocess
|
9 | 9 | import platform
|
10 | 10 | import pathlib
|
| 11 | +import textwrap |
11 | 12 |
|
12 | 13 | from setuptools.command import test
|
13 | 14 |
|
@@ -201,31 +202,48 @@ def test_namespace_package_importable(self, tmpdir):
|
201 | 202 | with test.test.paths_on_pythonpath([str(target)]):
|
202 | 203 | subprocess.check_call(pkg_resources_imp)
|
203 | 204 |
|
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 | + |
205 | 216 | def test_editable_prefix(self, tmp_path, sample_project):
|
206 | 217 | """
|
207 | 218 | Editable install to a prefix should be discoverable.
|
208 | 219 | """
|
209 | 220 | prefix = tmp_path / 'prefix'
|
210 | 221 | prefix.mkdir()
|
211 | 222 |
|
| 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) |
212 | 235 | cmd = [
|
213 | 236 | sys.executable,
|
214 | 237 | '-m', 'pip',
|
215 | 238 | 'install',
|
216 |
| - '-e', str(sample_project), |
| 239 | + '--editable', |
| 240 | + str(sample_project), |
217 | 241 | '--prefix', str(prefix),
|
| 242 | + '--no-build-isolation', |
218 | 243 | ]
|
219 |
| - subprocess.check_call(cmd) |
| 244 | + subprocess.check_call(cmd, env=env) |
220 | 245 |
|
221 | 246 | # 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) |
229 | 247 | 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