Skip to content

Commit 58f833d

Browse files
humitosagjohnson
authored andcommitted
Do not use --cache-dir for pip if CLEAN_AFTER_BUILD is enabled (#6239)
* Do not use --cache-dir for pip if CLEAN_AFTER_BUILD is enabled * Invert conditional
1 parent 2e76781 commit 58f833d

File tree

1 file changed

+27
-8
lines changed

1 file changed

+27
-8
lines changed

readthedocs/doc_builder/python_environments.py

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
import shutil
1111
import yaml
1212

13+
from django.conf import settings
14+
1315
from readthedocs.config import PIP, SETUPTOOLS, ParseError, parse as parse_yaml
1416
from readthedocs.config.models import PythonInstall, PythonInstallRequirements
1517
from readthedocs.doc_builder.config import load_yaml_config
@@ -102,8 +104,7 @@ def install_package(self, install):
102104
'--upgrade',
103105
'--upgrade-strategy',
104106
'eager',
105-
'--cache-dir',
106-
self.project.pip_cache_path,
107+
*self._pip_cache_cmd_argument(),
107108
'{path}{extra_requirements}'.format(
108109
path=local_path,
109110
extra_requirements=extra_req_param,
@@ -121,6 +122,27 @@ def install_package(self, install):
121122
bin_path=self.venv_bin(),
122123
)
123124

125+
def _pip_cache_cmd_argument(self):
126+
"""
127+
Return the pip command ``--cache-dir`` or ``--no-cache-dir`` argument.
128+
129+
The decision is made considering if the directories are going to be
130+
cleaned after the build (``RTD_CLEAN_AFTER_BUILD=True`` or project has
131+
the ``CLEAN_AFTER_BUILD`` feature enabled). In this case, there is no
132+
need to cache anything.
133+
"""
134+
if (
135+
settings.RTD_CLEAN_AFTER_BUILD or
136+
self.project.has_feature(Feature.CLEAN_AFTER_BUILD)
137+
):
138+
return [
139+
'--no-cache-dir',
140+
]
141+
return [
142+
'--cache-dir',
143+
self.project.pip_cache_path,
144+
]
145+
124146
def venv_bin(self, filename=None):
125147
"""
126148
Return path to the virtualenv bin path, or a specific binary.
@@ -287,8 +309,7 @@ def install_core_requirements(self):
287309
'pip',
288310
'install',
289311
'--upgrade',
290-
'--cache-dir',
291-
self.project.pip_cache_path,
312+
*self._pip_cache_cmd_argument(),
292313
]
293314

294315
# Install latest pip first,
@@ -384,8 +405,7 @@ def install_requirements_file(self, install):
384405
args += ['--upgrade']
385406
args += [
386407
'--exists-action=w',
387-
'--cache-dir',
388-
self.project.pip_cache_path,
408+
*self._pip_cache_cmd_argument(),
389409
'-r',
390410
requirements_file_path,
391411
]
@@ -581,8 +601,7 @@ def install_core_requirements(self):
581601
'pip',
582602
'install',
583603
'-U',
584-
'--cache-dir',
585-
self.project.pip_cache_path,
604+
*self._pip_cache_cmd_argument(),
586605
]
587606
pip_cmd.extend(pip_requirements)
588607
self.build_env.run(

0 commit comments

Comments
 (0)