|
19 | 19 | import pathlib
|
20 | 20 | import warnings
|
21 | 21 | from collections import namedtuple
|
| 22 | +from pathlib import Path |
22 | 23 |
|
23 | 24 | import pytest
|
24 | 25 | from jaraco import path
|
@@ -1166,3 +1167,45 @@ def test_use_correct_python_version_string(tmpdir, tmpdir_cwd, monkeypatch):
|
1166 | 1167 | assert cmd.config_vars['py_version'] == '3.10.1'
|
1167 | 1168 | assert cmd.config_vars['py_version_short'] == '3.10'
|
1168 | 1169 | assert cmd.config_vars['py_version_nodot'] == '310'
|
| 1170 | + |
| 1171 | + |
| 1172 | +def test_editable_user_and_build_isolation(setup_context, monkeypatch, tmp_path): |
| 1173 | + ''' `setup.py develop` should honor `--user` even under build isolation''' |
| 1174 | + |
| 1175 | + # == Arrange == |
| 1176 | + # Pretend that build isolation was enabled |
| 1177 | + # e.g pip sets the environment varible PYTHONNOUSERSITE=1 |
| 1178 | + monkeypatch.setattr('site.ENABLE_USER_SITE', False) |
| 1179 | + |
| 1180 | + # Patching $HOME for 2 reasons: |
| 1181 | + # 1. setuptools/command/easy_install.py:create_home_path |
| 1182 | + # tries creating directories in $HOME |
| 1183 | + # given `self.config_vars['DESTDIRS'] = "/home/user/.pyenv/versions/3.9.10 /home/user/.pyenv/versions/3.9.10/lib /home/user/.pyenv/versions/3.9.10/lib/python3.9 /home/user/.pyenv/versions/3.9.10/lib/python3.9/lib-dynload"`` # noqa: E501 |
| 1184 | + # it will `makedirs("/home/user/.pyenv/versions/3.9.10 /home/user/.pyenv/versions/3.9.10/lib /home/user/.pyenv/versions/3.9.10/lib/python3.9 /home/user/.pyenv/versions/3.9.10/lib/python3.9/lib-dynload")`` # noqa: E501 |
| 1185 | + # 2. We are going to force `site` to update site.USER_BASE and site.USER_SITE |
| 1186 | + # To point inside our new home |
| 1187 | + monkeypatch.setenv('HOME', str(tmp_path / 'home')) |
| 1188 | + monkeypatch.setattr('site.USER_BASE', None) |
| 1189 | + monkeypatch.setattr('site.USER_SITE', None) |
| 1190 | + user_site = Path(site.getusersitepackages()) |
| 1191 | + user_site.mkdir(parents=True, exist_ok=True) |
| 1192 | + |
| 1193 | + sys_prefix = (tmp_path / 'sys_prefix') |
| 1194 | + sys_prefix.mkdir(parents=True, exist_ok=True) |
| 1195 | + monkeypatch.setattr('sys.prefix', str(sys_prefix)) |
| 1196 | + |
| 1197 | + # == Sanity check == |
| 1198 | + assert list(sys_prefix.glob("*")) == [] |
| 1199 | + assert list(user_site.glob("*")) == [] |
| 1200 | + |
| 1201 | + # == Act == |
| 1202 | + run_setup('setup.py', ['develop', '--user']) |
| 1203 | + |
| 1204 | + # == Assert == |
| 1205 | + # Should not install to sys.prefix |
| 1206 | + assert list(sys_prefix.glob("*")) == [] |
| 1207 | + # Should install to user site |
| 1208 | + installed = {f.name for f in user_site.glob("*")} |
| 1209 | + # sometimes easy-install.pth is created and sometimes not |
| 1210 | + installed = installed - {"easy-install.pth"} |
| 1211 | + assert installed == {'UNKNOWN.egg-link'} |
0 commit comments