From 96217f84805bbe02e94dc0de7b94b7c2c7d3ad20 Mon Sep 17 00:00:00 2001 From: JinWang An Date: Mon, 27 Mar 2023 17:02:47 +0900 Subject: [PATCH] Imported Upstream version 61.1.1 --- .bumpversion.cfg | 2 +- CHANGES.rst | 14 +++++++ setup.cfg | 2 +- setuptools/command/easy_install.py | 4 +- setuptools/command/install.py | 23 +++++++---- setuptools/tests/test_easy_install.py | 59 ++++++++++++++++++++++++++- 6 files changed, 92 insertions(+), 12 deletions(-) diff --git a/.bumpversion.cfg b/.bumpversion.cfg index 30fa709..70ba4d7 100644 --- a/.bumpversion.cfg +++ b/.bumpversion.cfg @@ -1,5 +1,5 @@ [bumpversion] -current_version = 61.1.0 +current_version = 61.1.1 commit = True tag = True diff --git a/CHANGES.rst b/CHANGES.rst index 2c76dad..676cd15 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -1,3 +1,15 @@ +v61.1.1 +------- + + +Misc +^^^^ +* #3212: Fixed missing dependencies when running ``setup.py install``. + Note that calling ``setup.py install`` directly is still deprecated and + will be removed in future versions of ``setuptools``. + Please check the release notes for :ref:`setup_install_deprecation_note`. + + v61.1.0 ------- @@ -704,6 +716,8 @@ Documentation changes :user:`abravalheri` +.. _setup_install_deprecation_note: + v58.3.0 ------- diff --git a/setup.cfg b/setup.cfg index e5c484b..fa376ef 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,6 +1,6 @@ [metadata] name = setuptools -version = 61.1.0 +version = 61.1.1 author = Python Packaging Authority author_email = distutils-sig@python.org description = Easily download, build, install, upgrade, and uninstall Python packages diff --git a/setuptools/command/easy_install.py b/setuptools/command/easy_install.py index 107850a..77dcd25 100644 --- a/setuptools/command/easy_install.py +++ b/setuptools/command/easy_install.py @@ -298,7 +298,9 @@ class easy_install(Command): if not self.editable: self.check_site_dir() - self.index_url = self.index_url or "https://pypi.org/simple/" + default_index = os.getenv("__EASYINSTALL_INDEX", "https://pypi.org/simple/") + # ^ Private API for testing purposes only + self.index_url = self.index_url or default_index self.shadow_path = self.all_site_dirs[:] for path_item in self.install_dir, normalize_path(self.script_dir): if path_item not in self.shadow_path: diff --git a/setuptools/command/install.py b/setuptools/command/install.py index 35e54d2..55fdb12 100644 --- a/setuptools/command/install.py +++ b/setuptools/command/install.py @@ -91,14 +91,21 @@ class install(orig.install): msg = "For best results, pass -X:Frames to enable call stack." warnings.warn(msg) return True - res = inspect.getouterframes(run_frame)[2] - caller, = res[:1] - info = inspect.getframeinfo(caller) - caller_module = caller.f_globals.get('__name__', '') - return ( - caller_module == 'distutils.dist' - and info.function == 'run_commands' - ) + + frames = inspect.getouterframes(run_frame) + for frame in frames[2:4]: + caller, = frame[:1] + info = inspect.getframeinfo(caller) + caller_module = caller.f_globals.get('__name__', '') + + if caller_module == "setuptools.dist" and info.function == "run_command": + # Starting from v61.0.0 setuptools overwrites dist.run_command + continue + + return ( + caller_module == 'distutils.dist' + and info.function == 'run_commands' + ) def do_egg_install(self): diff --git a/setuptools/tests/test_easy_install.py b/setuptools/tests/test_easy_install.py index 5831b26..0d26dc7 100644 --- a/setuptools/tests/test_easy_install.py +++ b/setuptools/tests/test_easy_install.py @@ -448,6 +448,63 @@ class TestDistutilsPackage: run_setup('setup.py', ['bdist_egg']) +class TestInstallRequires: + def test_setup_install_includes_dependencies(self, tmp_path, mock_index): + """ + When ``python setup.py install`` is called directly, it will use easy_install + to fetch dependencies. + """ + # TODO: Remove these tests once `setup.py install` is completely removed + project_root = tmp_path / "project" + project_root.mkdir(exist_ok=True) + install_root = tmp_path / "install" + install_root.mkdir(exist_ok=True) + + self.create_project(project_root) + cmd = [ + sys.executable, + '-c', '__import__("setuptools").setup()', + 'install', + '--install-base', str(install_root), + '--install-lib', str(install_root), + '--install-headers', str(install_root), + '--install-scripts', str(install_root), + '--install-data', str(install_root), + '--install-purelib', str(install_root), + '--install-platlib', str(install_root), + ] + env = {"PYTHONPATH": str(install_root), "__EASYINSTALL_INDEX": mock_index.url} + with pytest.raises(subprocess.CalledProcessError) as exc_info: + subprocess.check_output( + cmd, cwd=str(project_root), env=env, stderr=subprocess.STDOUT, text=True + ) + try: + assert '/does-not-exist/' in {r.path for r in mock_index.requests} + assert next( + line + for line in exc_info.value.output.splitlines() + if "not find suitable distribution for" in line + and "does-not-exist" in line + ) + except Exception: + if "failed to get random numbers" in exc_info.value.output: + pytest.xfail(f"{sys.platform} failure - {exc_info.value.output}") + raise + + def create_project(self, root): + config = """ + [metadata] + name = project + version = 42 + + [options] + install_requires = does-not-exist + py_modules = mod + """ + (root / 'setup.cfg').write_text(DALS(config), encoding="utf-8") + (root / 'mod.py').touch() + + class TestSetupRequires: def test_setup_requires_honors_fetch_params(self, mock_index, monkeypatch): @@ -466,7 +523,7 @@ class TestSetupRequires: with contexts.environment(PYTHONPATH=temp_install_dir): cmd = [ sys.executable, - '-m', 'setup', + '-c', '__import__("setuptools").setup()', 'easy_install', '--index-url', mock_index.url, '--exclude-scripts', -- 2.34.1