Skip to content

Commit

Permalink
Build: Pin setuptools only when required
Browse files Browse the repository at this point in the history
Ref #8659
Closes #10263
  • Loading branch information
stsewd committed Apr 25, 2023
1 parent fdff2a6 commit 1224875
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 12 deletions.
8 changes: 8 additions & 0 deletions readthedocs/config/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
13 changes: 9 additions & 4 deletions readthedocs/doc_builder/director.py
Original file line number Diff line number Diff line change
Expand Up @@ -542,17 +542,22 @@ 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",
"-mpip",
"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,
Expand Down
12 changes: 10 additions & 2 deletions readthedocs/doc_builder/python_environments.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down Expand Up @@ -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):
Expand Down
6 changes: 3 additions & 3 deletions readthedocs/projects/tests/test_build_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
),
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions readthedocs/rtd_tests/tests/test_doc_building.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 1224875

Please sign in to comment.