Skip to content

Commit d7e86b3

Browse files
authored
Merge pull request #6965 from eric-wieser/patch-1
Ensure invoked Sphinx matches importable one
2 parents ecab363 + c25a21b commit d7e86b3

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

readthedocs/doc_builder/backends/sphinx.py

+14-4
Original file line numberDiff line numberDiff line change
@@ -232,8 +232,7 @@ def build(self):
232232
self.clean()
233233
project = self.project
234234
build_command = [
235-
'python',
236-
self.python_env.venv_bin(filename='sphinx-build'),
235+
*self.get_sphinx_cmd(),
237236
'-T',
238237
]
239238
if self._force:
@@ -259,6 +258,18 @@ def build(self):
259258
)
260259
return cmd_ret.successful
261260

261+
def get_sphinx_cmd(self):
262+
if self.project.has_feature(Feature.FORCE_SPHINX_FROM_VENV):
263+
return (
264+
self.python_env.venv_bin(filename='python'),
265+
'-m',
266+
'sphinx',
267+
)
268+
return (
269+
'python',
270+
self.python_env.venv_bin(filename='sphinx-build'),
271+
)
272+
262273
def venv_sphinx_supports_latexmk(self):
263274
"""
264275
Check if ``sphinx`` from the user's venv supports ``latexmk``.
@@ -434,8 +445,7 @@ def build(self):
434445

435446
# Default to this so we can return it always.
436447
self.run(
437-
'python',
438-
self.python_env.venv_bin(filename='sphinx-build'),
448+
*self.get_sphinx_cmd(),
439449
'-b',
440450
'latex',
441451
'-D',

readthedocs/projects/models.py

+5
Original file line numberDiff line numberDiff line change
@@ -1584,6 +1584,7 @@ def add_features(sender, **kwargs):
15841584
CACHED_ENVIRONMENT = 'cached_environment'
15851585
CELERY_ROUTER = 'celery_router'
15861586
LIMIT_CONCURRENT_BUILDS = 'limit_concurrent_builds'
1587+
FORCE_SPHINX_FROM_VENV = 'force_sphinx_from_venv'
15871588
LIST_PACKAGES_INSTALLED_ENV = 'list_packages_installed_env'
15881589
VCS_REMOTE_LISTING = 'vcs_remote_listing'
15891590

@@ -1664,6 +1665,10 @@ def add_features(sender, **kwargs):
16641665
LIMIT_CONCURRENT_BUILDS,
16651666
_('Limit the amount of concurrent builds'),
16661667
),
1668+
(
1669+
FORCE_SPHINX_FROM_VENV,
1670+
_('Force to use Sphinx from the current virtual environment'),
1671+
),
16671672
(
16681673
LIST_PACKAGES_INSTALLED_ENV,
16691674
_(

0 commit comments

Comments
 (0)