10
10
import shutil
11
11
import yaml
12
12
13
+ from django .conf import settings
14
+
13
15
from readthedocs .config import PIP , SETUPTOOLS , ParseError , parse as parse_yaml
14
16
from readthedocs .config .models import PythonInstall , PythonInstallRequirements
15
17
from readthedocs .doc_builder .config import load_yaml_config
@@ -102,8 +104,7 @@ def install_package(self, install):
102
104
'--upgrade' ,
103
105
'--upgrade-strategy' ,
104
106
'eager' ,
105
- '--cache-dir' ,
106
- self .project .pip_cache_path ,
107
+ * self ._pip_cache_cmd_argument (),
107
108
'{path}{extra_requirements}' .format (
108
109
path = local_path ,
109
110
extra_requirements = extra_req_param ,
@@ -121,6 +122,27 @@ def install_package(self, install):
121
122
bin_path = self .venv_bin (),
122
123
)
123
124
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
+
124
146
def venv_bin (self , filename = None ):
125
147
"""
126
148
Return path to the virtualenv bin path, or a specific binary.
@@ -287,8 +309,7 @@ def install_core_requirements(self):
287
309
'pip' ,
288
310
'install' ,
289
311
'--upgrade' ,
290
- '--cache-dir' ,
291
- self .project .pip_cache_path ,
312
+ * self ._pip_cache_cmd_argument (),
292
313
]
293
314
294
315
# Install latest pip first,
@@ -384,8 +405,7 @@ def install_requirements_file(self, install):
384
405
args += ['--upgrade' ]
385
406
args += [
386
407
'--exists-action=w' ,
387
- '--cache-dir' ,
388
- self .project .pip_cache_path ,
408
+ * self ._pip_cache_cmd_argument (),
389
409
'-r' ,
390
410
requirements_file_path ,
391
411
]
@@ -581,8 +601,7 @@ def install_core_requirements(self):
581
601
'pip' ,
582
602
'install' ,
583
603
'-U' ,
584
- '--cache-dir' ,
585
- self .project .pip_cache_path ,
604
+ * self ._pip_cache_cmd_argument (),
586
605
]
587
606
pip_cmd .extend (pip_requirements )
588
607
self .build_env .run (
0 commit comments