From 1224875104a27355713b41008eb92097b12cbe5d Mon Sep 17 00:00:00 2001 From: Santos Gallegos Date: Mon, 24 Apr 2023 20:29:36 -0500 Subject: [PATCH] Build: Pin setuptools only when required Ref https://github.com/readthedocs/readthedocs.org/issues/8659 Closes https://github.com/readthedocs/readthedocs.org/issues/10263 --- readthedocs/config/config.py | 8 ++++++++ readthedocs/doc_builder/director.py | 13 +++++++++---- readthedocs/doc_builder/python_environments.py | 12 ++++++++++-- readthedocs/projects/tests/test_build_tasks.py | 6 +++--- readthedocs/rtd_tests/tests/test_doc_building.py | 6 +++--- 5 files changed, 33 insertions(+), 12 deletions(-) diff --git a/readthedocs/config/config.py b/readthedocs/config/config.py index c59196bfd4d..03941e9d7cc 100644 --- a/readthedocs/config/config.py +++ b/readthedocs/config/config.py @@ -282,6 +282,14 @@ def is_using_conda(self): return self.python_interpreter in ("conda", "mamba") return self.conda is not None + @property + def is_using_setup_py_install(self): + """Check if this project is using `setup.py install` as installation method.""" + for install in self.python.install: + if isinstance(install, PythonInstall) and install.method == SETUPTOOLS: + return True + return False + @property def python_interpreter(self): if self.using_build_tools: diff --git a/readthedocs/doc_builder/director.py b/readthedocs/doc_builder/director.py index 662ff2b1c4d..d49dd666464 100644 --- a/readthedocs/doc_builder/director.py +++ b/readthedocs/doc_builder/director.py @@ -542,6 +542,14 @@ def install_build_tools(self): self.data.config.python_interpreter not in ("conda", "mamba"), ] ): + # We cap setuptools to avoid breakage of projects + # relying on setup.py invokations, + # see https://github.com/readthedocs/readthedocs.org/issues/8659 + setuptools_version = ( + "setuptools<58.3.0" + if self.data.config.is_using_setup_py_install + else "setuptools" + ) # Install our own requirements if the version is compiled cmd = [ "python", @@ -549,10 +557,7 @@ def install_build_tools(self): "install", "-U", "virtualenv", - # We cap setuptools to avoid breakage of projects - # relying on setup.py invokations, - # see https://github.com/readthedocs/readthedocs.org/issues/8659 - "setuptools<58.3.0", + setuptools_version, ] self.build_environment.run( *cmd, diff --git a/readthedocs/doc_builder/python_environments.py b/readthedocs/doc_builder/python_environments.py index 15713ae4b94..1d4f3b51dac 100644 --- a/readthedocs/doc_builder/python_environments.py +++ b/readthedocs/doc_builder/python_environments.py @@ -171,7 +171,15 @@ def install_core_requirements(self): positive='pip<20.3', negative='pip', ) - cmd = pip_install_cmd + [pip_version, 'setuptools<58.3.0'] + # Installing a project with setup.py install is deprecated + # in new versions of setuptools, so we need to pin setuptools + # to a supported version if the project is using setup.py install. + setuptools_version = ( + "setuptools<58.3.0" + if self.config.is_using_setup_py_install + else "setuptools" + ) + cmd = pip_install_cmd + [pip_version, setuptools_version] self.build_env.run( *cmd, bin_path=self.venv_bin(), @@ -248,7 +256,7 @@ def install_core_requirements(self): self.build_env.run( *cmd, bin_path=self.venv_bin(), - cwd=self.checkout_path # noqa - no comma here in py27 :/ + cwd=self.checkout_path, ) def install_requirements_file(self, install): diff --git a/readthedocs/projects/tests/test_build_tasks.py b/readthedocs/projects/tests/test_build_tasks.py index f64e5acfba1..670071c5111 100644 --- a/readthedocs/projects/tests/test_build_tasks.py +++ b/readthedocs/projects/tests/test_build_tasks.py @@ -708,7 +708,7 @@ def test_build_commands_executed( "--upgrade", "--no-cache-dir", "pip", - "setuptools<58.3.0", + "setuptools", bin_path=mock.ANY, cwd=mock.ANY, ), @@ -981,7 +981,7 @@ def test_build_tools(self, load_yaml_config): "install", "-U", "virtualenv", - "setuptools<58.3.0", + "setuptools", ), mock.call("asdf", "install", "nodejs", nodejs_version), mock.call("asdf", "global", "nodejs", nodejs_version), @@ -1138,7 +1138,7 @@ def test_build_commands(self, load_yaml_config): "install", "-U", "virtualenv", - "setuptools<58.3.0", + "setuptools", ), # NOTE: when running commands from `build.jobs` or # `build.commands` they are not split to allow multi-line diff --git a/readthedocs/rtd_tests/tests/test_doc_building.py b/readthedocs/rtd_tests/tests/test_doc_building.py index 6d1642780e9..94de21ffccc 100644 --- a/readthedocs/rtd_tests/tests/test_doc_building.py +++ b/readthedocs/rtd_tests/tests/test_doc_building.py @@ -418,7 +418,7 @@ def test_install_core_requirements_sphinx(self, checkout_path): self.assertEqual(self.build_env_mock.run.call_count, 2) calls = self.build_env_mock.run.call_args_list - core_args = self.pip_install_args + ['pip', 'setuptools<58.3.0'] + core_args = self.pip_install_args + ["pip", "setuptools"] self.assertArgsStartsWith(core_args, calls[0]) requirements = self.base_requirements + requirements_sphinx @@ -457,7 +457,7 @@ def test_install_core_requirements_sphinx_system_packages_caps_setuptools(self, self.assertEqual(self.build_env_mock.run.call_count, 2) calls = self.build_env_mock.run.call_args_list - core_args = self.pip_install_args + ['pip', 'setuptools<58.3.0'] + core_args = self.pip_install_args + ["pip", "setuptools"] self.assertArgsStartsWith(core_args, calls[0]) requirements = self.base_requirements + requirements_sphinx @@ -482,7 +482,7 @@ def test_install_core_requirements_mkdocs(self, checkout_path): self.assertEqual(self.build_env_mock.run.call_count, 2) calls = self.build_env_mock.run.call_args_list - core_args = self.pip_install_args + ['pip', 'setuptools<58.3.0'] + core_args = self.pip_install_args + ["pip", "setuptools"] self.assertArgsStartsWith(core_args, calls[0]) requirements = self.base_requirements + requirements_mkdocs