Skip to content

Commit 37a8227

Browse files
authored
Build: Pin setuptools only when required (#10268)
Ref #8659 Closes #10263
1 parent fdff2a6 commit 37a8227

File tree

5 files changed

+33
-12
lines changed

5 files changed

+33
-12
lines changed

readthedocs/config/config.py

+8
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,14 @@ def is_using_conda(self):
282282
return self.python_interpreter in ("conda", "mamba")
283283
return self.conda is not None
284284

285+
@property
286+
def is_using_setup_py_install(self):
287+
"""Check if this project is using `setup.py install` as installation method."""
288+
for install in self.python.install:
289+
if isinstance(install, PythonInstall) and install.method == SETUPTOOLS:
290+
return True
291+
return False
292+
285293
@property
286294
def python_interpreter(self):
287295
if self.using_build_tools:

readthedocs/doc_builder/director.py

+9-4
Original file line numberDiff line numberDiff line change
@@ -542,17 +542,22 @@ def install_build_tools(self):
542542
self.data.config.python_interpreter not in ("conda", "mamba"),
543543
]
544544
):
545+
# We cap setuptools to avoid breakage of projects
546+
# relying on setup.py invokations,
547+
# see https://github.com/readthedocs/readthedocs.org/issues/8659
548+
setuptools_version = (
549+
"setuptools<58.3.0"
550+
if self.data.config.is_using_setup_py_install
551+
else "setuptools"
552+
)
545553
# Install our own requirements if the version is compiled
546554
cmd = [
547555
"python",
548556
"-mpip",
549557
"install",
550558
"-U",
551559
"virtualenv",
552-
# We cap setuptools to avoid breakage of projects
553-
# relying on setup.py invokations,
554-
# see https://github.com/readthedocs/readthedocs.org/issues/8659
555-
"setuptools<58.3.0",
560+
setuptools_version,
556561
]
557562
self.build_environment.run(
558563
*cmd,

readthedocs/doc_builder/python_environments.py

+10-2
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,15 @@ def install_core_requirements(self):
171171
positive='pip<20.3',
172172
negative='pip',
173173
)
174-
cmd = pip_install_cmd + [pip_version, 'setuptools<58.3.0']
174+
# Installing a project with setup.py install is deprecated
175+
# in new versions of setuptools, so we need to pin setuptools
176+
# to a supported version if the project is using setup.py install.
177+
setuptools_version = (
178+
"setuptools<58.3.0"
179+
if self.config.is_using_setup_py_install
180+
else "setuptools"
181+
)
182+
cmd = pip_install_cmd + [pip_version, setuptools_version]
175183
self.build_env.run(
176184
*cmd,
177185
bin_path=self.venv_bin(),
@@ -248,7 +256,7 @@ def install_core_requirements(self):
248256
self.build_env.run(
249257
*cmd,
250258
bin_path=self.venv_bin(),
251-
cwd=self.checkout_path # noqa - no comma here in py27 :/
259+
cwd=self.checkout_path,
252260
)
253261

254262
def install_requirements_file(self, install):

readthedocs/projects/tests/test_build_tasks.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -708,7 +708,7 @@ def test_build_commands_executed(
708708
"--upgrade",
709709
"--no-cache-dir",
710710
"pip",
711-
"setuptools<58.3.0",
711+
"setuptools",
712712
bin_path=mock.ANY,
713713
cwd=mock.ANY,
714714
),
@@ -981,7 +981,7 @@ def test_build_tools(self, load_yaml_config):
981981
"install",
982982
"-U",
983983
"virtualenv",
984-
"setuptools<58.3.0",
984+
"setuptools",
985985
),
986986
mock.call("asdf", "install", "nodejs", nodejs_version),
987987
mock.call("asdf", "global", "nodejs", nodejs_version),
@@ -1138,7 +1138,7 @@ def test_build_commands(self, load_yaml_config):
11381138
"install",
11391139
"-U",
11401140
"virtualenv",
1141-
"setuptools<58.3.0",
1141+
"setuptools",
11421142
),
11431143
# NOTE: when running commands from `build.jobs` or
11441144
# `build.commands` they are not split to allow multi-line

readthedocs/rtd_tests/tests/test_doc_building.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ def test_install_core_requirements_sphinx(self, checkout_path):
418418
self.assertEqual(self.build_env_mock.run.call_count, 2)
419419
calls = self.build_env_mock.run.call_args_list
420420

421-
core_args = self.pip_install_args + ['pip', 'setuptools<58.3.0']
421+
core_args = self.pip_install_args + ["pip", "setuptools"]
422422
self.assertArgsStartsWith(core_args, calls[0])
423423

424424
requirements = self.base_requirements + requirements_sphinx
@@ -457,7 +457,7 @@ def test_install_core_requirements_sphinx_system_packages_caps_setuptools(self,
457457
self.assertEqual(self.build_env_mock.run.call_count, 2)
458458
calls = self.build_env_mock.run.call_args_list
459459

460-
core_args = self.pip_install_args + ['pip', 'setuptools<58.3.0']
460+
core_args = self.pip_install_args + ["pip", "setuptools"]
461461
self.assertArgsStartsWith(core_args, calls[0])
462462

463463
requirements = self.base_requirements + requirements_sphinx
@@ -482,7 +482,7 @@ def test_install_core_requirements_mkdocs(self, checkout_path):
482482
self.assertEqual(self.build_env_mock.run.call_count, 2)
483483
calls = self.build_env_mock.run.call_args_list
484484

485-
core_args = self.pip_install_args + ['pip', 'setuptools<58.3.0']
485+
core_args = self.pip_install_args + ["pip", "setuptools"]
486486
self.assertArgsStartsWith(core_args, calls[0])
487487

488488
requirements = self.base_requirements + requirements_mkdocs

0 commit comments

Comments
 (0)