diff options
| author | Jason R. Coombs <jaraco@jaraco.com> | 2022-04-03 16:26:57 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-04-03 16:26:57 -0400 |
| commit | fd632dfb65e3e72b91f9e0e6002bc581806b4e59 (patch) | |
| tree | d94c0ec52aa46c2cc804226ab489a47aa0737767 /setuptools | |
| parent | b58bdcad0513a4a2ff2c70b1b152fd565960a34f (diff) | |
| parent | c2f4907fcdec3b8a68e595ee9b9fc57103992ce2 (diff) | |
| download | python-setuptools-git-fd632dfb65e3e72b91f9e0e6002bc581806b4e59.tar.gz | |
Merge pull request #3151 from hexagonrecursion/fix-editable
Fix editable --user installs with build isolation
Diffstat (limited to 'setuptools')
| -rw-r--r-- | setuptools/command/easy_install.py | 18 | ||||
| -rw-r--r-- | setuptools/tests/test_easy_install.py | 43 |
2 files changed, 49 insertions, 12 deletions
diff --git a/setuptools/command/easy_install.py b/setuptools/command/easy_install.py index 77dcd25c..444d3b33 100644 --- a/setuptools/command/easy_install.py +++ b/setuptools/command/easy_install.py @@ -169,12 +169,8 @@ class easy_install(Command): self.install_data = None self.install_base = None self.install_platbase = None - if site.ENABLE_USER_SITE: - self.install_userbase = site.USER_BASE - self.install_usersite = site.USER_SITE - else: - self.install_userbase = None - self.install_usersite = None + self.install_userbase = site.USER_BASE + self.install_usersite = site.USER_SITE self.no_find_links = None # Options not specifiable via command line @@ -253,11 +249,9 @@ class easy_install(Command): getattr(sys, 'windir', '').replace('.', ''), ) - if site.ENABLE_USER_SITE: - self.config_vars['userbase'] = self.install_userbase - self.config_vars['usersite'] = self.install_usersite - - elif self.user: + self.config_vars['userbase'] = self.install_userbase + self.config_vars['usersite'] = self.install_usersite + if self.user and not site.ENABLE_USER_SITE: log.warn("WARNING: The user site-packages directory is disabled.") self._fix_install_dir_for_user_site() @@ -375,7 +369,7 @@ class easy_install(Command): """ Fix the install_dir if "--user" was used. """ - if not self.user or not site.ENABLE_USER_SITE: + if not self.user: return self.create_home_path() diff --git a/setuptools/tests/test_easy_install.py b/setuptools/tests/test_easy_install.py index 0d26dc73..85f528db 100644 --- a/setuptools/tests/test_easy_install.py +++ b/setuptools/tests/test_easy_install.py @@ -19,6 +19,7 @@ import subprocess import pathlib import warnings from collections import namedtuple +from pathlib import Path import pytest from jaraco import path @@ -1166,3 +1167,45 @@ def test_use_correct_python_version_string(tmpdir, tmpdir_cwd, monkeypatch): assert cmd.config_vars['py_version'] == '3.10.1' assert cmd.config_vars['py_version_short'] == '3.10' assert cmd.config_vars['py_version_nodot'] == '310' + + +def test_editable_user_and_build_isolation(setup_context, monkeypatch, tmp_path): + ''' `setup.py develop` should honor `--user` even under build isolation''' + + # == Arrange == + # Pretend that build isolation was enabled + # e.g pip sets the environment varible PYTHONNOUSERSITE=1 + monkeypatch.setattr('site.ENABLE_USER_SITE', False) + + # Patching $HOME for 2 reasons: + # 1. setuptools/command/easy_install.py:create_home_path + # tries creating directories in $HOME + # 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 + # 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 + # 2. We are going to force `site` to update site.USER_BASE and site.USER_SITE + # To point inside our new home + monkeypatch.setenv('HOME', str(tmp_path / 'home')) + monkeypatch.setattr('site.USER_BASE', None) + monkeypatch.setattr('site.USER_SITE', None) + user_site = Path(site.getusersitepackages()) + user_site.mkdir(parents=True, exist_ok=True) + + sys_prefix = (tmp_path / 'sys_prefix') + sys_prefix.mkdir(parents=True, exist_ok=True) + monkeypatch.setattr('sys.prefix', str(sys_prefix)) + + # == Sanity check == + assert list(sys_prefix.glob("*")) == [] + assert list(user_site.glob("*")) == [] + + # == Act == + run_setup('setup.py', ['develop', '--user']) + + # == Assert == + # Should not install to sys.prefix + assert list(sys_prefix.glob("*")) == [] + # Should install to user site + installed = {f.name for f in user_site.glob("*")} + # sometimes easy-install.pth is created and sometimes not + installed = installed - {"easy-install.pth"} + assert installed == {'UNKNOWN.egg-link'} |
