Skip to content

Build: Pin setuptools only when required #10268

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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