From 6376ad10547315c15dfec719ff3f384e7a94dfc2 Mon Sep 17 00:00:00 2001 From: Andrey Bienkowski Date: Sun, 6 Mar 2022 00:43:07 +0300 Subject: XXX: Debugging --- setuptools/command/easy_install.py | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'setuptools') diff --git a/setuptools/command/easy_install.py b/setuptools/command/easy_install.py index 107850a9..318eac31 100644 --- a/setuptools/command/easy_install.py +++ b/setuptools/command/easy_install.py @@ -221,6 +221,42 @@ class easy_install(Command): raise SystemExit() def finalize_options(self): # noqa: C901 # is too complex (25) # FIXME + print(sysconfig._INSTALL_SCHEMES) + print(f'{os.name}_user') + + def global_trace(frame, event, arg): + pass + + import sys + + sys.settrace(global_trace) + + XXX = [set()] + + def trace(frame, event, arg): + config_vars = getattr(self, 'config_vars', {}) + o = { + ('USER_BASE', site.USER_BASE), + ('USER_SITE', site.USER_SITE), + ('install_dir', self.install_dir), + ('install_userbase', self.install_userbase), + ('install_usersite', self.install_usersite), + ('install_purelib', self.install_purelib), + ('install_scripts', self.install_scripts), + ('userbase', config_vars.get('userbase')), + ('usersite', config_vars.get('usersite')), + } + if XXX[0] - o: + print('-', XXX[0] - o) + if o - XXX[0]: + print('+', o - XXX[0]) + XXX[0] = o + lines, start = inspect.getsourcelines(frame) + print(frame.f_lineno, lines[frame.f_lineno - start]) + + import inspect + inspect.currentframe().f_trace = trace + self.version and self._render_version() py_version = sys.version.split()[0] @@ -459,6 +495,7 @@ class easy_install(Command): instdir = normalize_path(self.install_dir) pth_file = os.path.join(instdir, 'easy-install.pth') + print('XXX', instdir, os.path.exists(instdir)) if not os.path.exists(instdir): try: os.makedirs(instdir) -- cgit v1.2.1 From 2e7ba454d431945237125b951c5482a452b67e4e Mon Sep 17 00:00:00 2001 From: Andrey Bienkowski Date: Sat, 5 Mar 2022 18:22:01 +0300 Subject: Test: editable install \w --user&build isolation Add a new test and confirm that it fails in the expected manner --- setuptools/tests/test_easy_install.py | 42 +++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) (limited to 'setuptools') diff --git a/setuptools/tests/test_easy_install.py b/setuptools/tests/test_easy_install.py index 5831b267..09c4e075 100644 --- a/setuptools/tests/test_easy_install.py +++ b/setuptools/tests/test_easy_install.py @@ -40,6 +40,8 @@ import pkg_resources from . import contexts from .textwrap import DALS +import py + @pytest.fixture(autouse=True) def pip_disable_index(monkeypatch): @@ -1109,3 +1111,43 @@ 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, tmpdir): + ''' `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(tmpdir / 'home')) + monkeypatch.setattr('site.USER_BASE', None) + monkeypatch.setattr('site.USER_SITE', None) + user_site = py.path.local(site.getusersitepackages()) + user_site.ensure_dir() + + sys_prefix = (tmpdir / 'sys_prefix').ensure_dir() + monkeypatch.setattr('sys.prefix', str(sys_prefix)) + + # == Sanity check == + assert sys_prefix.listdir() == [] + assert user_site.listdir() == [] + + # == Act == + run_setup('setup.py', ['develop', '--user']) + + # == Assert == + # Should not install to sys.prefix + with pytest.raises(AssertionError): + assert sys_prefix.listdir() == [] + # Should install to user site + with pytest.raises(AssertionError): + assert {f.basename for f in user_site.listdir()} == {'UNKNOWN.egg-link'} -- cgit v1.2.1 From 45340d00688ba29fc3492c52c88c47d14ce918e6 Mon Sep 17 00:00:00 2001 From: Andrey Bienkowski Date: Sun, 6 Mar 2022 07:58:24 +0300 Subject: Revert "XXX: Debugging" This reverts commit 6376ad10547315c15dfec719ff3f384e7a94dfc2. --- setuptools/command/easy_install.py | 37 ------------------------------------- 1 file changed, 37 deletions(-) (limited to 'setuptools') diff --git a/setuptools/command/easy_install.py b/setuptools/command/easy_install.py index 318eac31..107850a9 100644 --- a/setuptools/command/easy_install.py +++ b/setuptools/command/easy_install.py @@ -221,42 +221,6 @@ class easy_install(Command): raise SystemExit() def finalize_options(self): # noqa: C901 # is too complex (25) # FIXME - print(sysconfig._INSTALL_SCHEMES) - print(f'{os.name}_user') - - def global_trace(frame, event, arg): - pass - - import sys - - sys.settrace(global_trace) - - XXX = [set()] - - def trace(frame, event, arg): - config_vars = getattr(self, 'config_vars', {}) - o = { - ('USER_BASE', site.USER_BASE), - ('USER_SITE', site.USER_SITE), - ('install_dir', self.install_dir), - ('install_userbase', self.install_userbase), - ('install_usersite', self.install_usersite), - ('install_purelib', self.install_purelib), - ('install_scripts', self.install_scripts), - ('userbase', config_vars.get('userbase')), - ('usersite', config_vars.get('usersite')), - } - if XXX[0] - o: - print('-', XXX[0] - o) - if o - XXX[0]: - print('+', o - XXX[0]) - XXX[0] = o - lines, start = inspect.getsourcelines(frame) - print(frame.f_lineno, lines[frame.f_lineno - start]) - - import inspect - inspect.currentframe().f_trace = trace - self.version and self._render_version() py_version = sys.version.split()[0] @@ -495,7 +459,6 @@ class easy_install(Command): instdir = normalize_path(self.install_dir) pth_file = os.path.join(instdir, 'easy-install.pth') - print('XXX', instdir, os.path.exists(instdir)) if not os.path.exists(instdir): try: os.makedirs(instdir) -- cgit v1.2.1 From b828c32cd49f2281156644fce55d3c40663081dd Mon Sep 17 00:00:00 2001 From: Andrey Bienkowski Date: Sat, 5 Mar 2022 15:20:42 +0300 Subject: Fix editable --user installs with build isolation https://github.com/pypa/setuptools/issues/3019 --- setuptools/command/easy_install.py | 18 ++++++------------ setuptools/tests/test_easy_install.py | 6 ++---- 2 files changed, 8 insertions(+), 16 deletions(-) (limited to 'setuptools') diff --git a/setuptools/command/easy_install.py b/setuptools/command/easy_install.py index 107850a9..940c916f 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() @@ -373,7 +367,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 09c4e075..7a8b64a6 100644 --- a/setuptools/tests/test_easy_install.py +++ b/setuptools/tests/test_easy_install.py @@ -1146,8 +1146,6 @@ def test_editable_user_and_build_isolation(setup_context, monkeypatch, tmpdir): # == Assert == # Should not install to sys.prefix - with pytest.raises(AssertionError): - assert sys_prefix.listdir() == [] + assert sys_prefix.listdir() == [] # Should install to user site - with pytest.raises(AssertionError): - assert {f.basename for f in user_site.listdir()} == {'UNKNOWN.egg-link'} + assert {f.basename for f in user_site.listdir()} == {'UNKNOWN.egg-link'} -- cgit v1.2.1 From a28da5fad3dd78e9234e16f07601c8979f9e116b Mon Sep 17 00:00:00 2001 From: Andrey Bienkowski Date: Sun, 6 Mar 2022 09:10:48 +0300 Subject: Fix test_editable_user_and_build_isolation This test broke on my machine for some reason --- setuptools/tests/test_easy_install.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'setuptools') diff --git a/setuptools/tests/test_easy_install.py b/setuptools/tests/test_easy_install.py index 7a8b64a6..fd4a83ee 100644 --- a/setuptools/tests/test_easy_install.py +++ b/setuptools/tests/test_easy_install.py @@ -1148,4 +1148,7 @@ def test_editable_user_and_build_isolation(setup_context, monkeypatch, tmpdir): # Should not install to sys.prefix assert sys_prefix.listdir() == [] # Should install to user site - assert {f.basename for f in user_site.listdir()} == {'UNKNOWN.egg-link'} + installed = {f.basename for f in user_site.listdir()} + # sometimes easy-install.pth is created and sometimes not + installed = installed - {"easy-install.pth"} + assert installed == {'UNKNOWN.egg-link'} -- cgit v1.2.1 From c2f4907fcdec3b8a68e595ee9b9fc57103992ce2 Mon Sep 17 00:00:00 2001 From: Anderson Bravalheri Date: Tue, 8 Mar 2022 11:22:55 +0000 Subject: Replace direct usage of the `py` library According to https://pypi.org/project/py/, this library is in maintenance mode and should not be used in new code. --- setuptools/tests/test_easy_install.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'setuptools') diff --git a/setuptools/tests/test_easy_install.py b/setuptools/tests/test_easy_install.py index fd4a83ee..878eb7c3 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 @@ -40,8 +41,6 @@ import pkg_resources from . import contexts from .textwrap import DALS -import py - @pytest.fixture(autouse=True) def pip_disable_index(monkeypatch): @@ -1113,7 +1112,7 @@ def test_use_correct_python_version_string(tmpdir, tmpdir_cwd, monkeypatch): assert cmd.config_vars['py_version_nodot'] == '310' -def test_editable_user_and_build_isolation(setup_context, monkeypatch, tmpdir): +def test_editable_user_and_build_isolation(setup_context, monkeypatch, tmp_path): ''' `setup.py develop` should honor `--user` even under build isolation''' # == Arrange == @@ -1128,27 +1127,28 @@ def test_editable_user_and_build_isolation(setup_context, monkeypatch, tmpdir): # 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(tmpdir / 'home')) + monkeypatch.setenv('HOME', str(tmp_path / 'home')) monkeypatch.setattr('site.USER_BASE', None) monkeypatch.setattr('site.USER_SITE', None) - user_site = py.path.local(site.getusersitepackages()) - user_site.ensure_dir() + user_site = Path(site.getusersitepackages()) + user_site.mkdir(parents=True, exist_ok=True) - sys_prefix = (tmpdir / 'sys_prefix').ensure_dir() + sys_prefix = (tmp_path / 'sys_prefix') + sys_prefix.mkdir(parents=True, exist_ok=True) monkeypatch.setattr('sys.prefix', str(sys_prefix)) # == Sanity check == - assert sys_prefix.listdir() == [] - assert user_site.listdir() == [] + 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 sys_prefix.listdir() == [] + assert list(sys_prefix.glob("*")) == [] # Should install to user site - installed = {f.basename for f in user_site.listdir()} + 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'} -- cgit v1.2.1