From 30ede06ea1b9bb85ab618bc0e656be2cf7e6f237 Mon Sep 17 00:00:00 2001 From: Manuel Kaufmann Date: Wed, 2 Oct 2019 19:44:47 +0200 Subject: [PATCH 1/2] Do not use --cache-dir for pip if CLEAN_AFTER_BUILD is enabled --- .../doc_builder/python_environments.py | 37 +++++++++++++++---- 1 file changed, 29 insertions(+), 8 deletions(-) diff --git a/readthedocs/doc_builder/python_environments.py b/readthedocs/doc_builder/python_environments.py index 381a8f46f9f..8bcc3d71c35 100644 --- a/readthedocs/doc_builder/python_environments.py +++ b/readthedocs/doc_builder/python_environments.py @@ -10,6 +10,8 @@ import shutil import yaml +from django.conf import settings + from readthedocs.config import PIP, SETUPTOOLS, ParseError, parse as parse_yaml from readthedocs.config.models import PythonInstall, PythonInstallRequirements from readthedocs.doc_builder.config import load_yaml_config @@ -102,8 +104,7 @@ def install_package(self, install): '--upgrade', '--upgrade-strategy', 'eager', - '--cache-dir', - self.project.pip_cache_path, + *self._pip_cache_cmd_argument(), '{path}{extra_requirements}'.format( path=local_path, extra_requirements=extra_req_param, @@ -121,6 +122,29 @@ def install_package(self, install): bin_path=self.venv_bin(), ) + def _pip_cache_cmd_argument(self): + """ + Return the pip command ``--cache-dir`` or ``--no-cache-dir`` argument. + + The decision is made considering if the directories are going to be + cleaned after the build (``RTD_CLEAN_AFTER_BUILD=True`` or project has + the ``CLEAN_AFTER_BUILD`` feature enabled). In this case, there is no + need to cache anything. + """ + if ( + not settings.RTD_CLEAN_AFTER_BUILD and + not self.project.has_feature(Feature.CLEAN_AFTER_BUILD) + ): + return [ + '--cache-dir', + self.project.pip_cache_path, + ] + + return [ + '--no-cache-dir', + ] + + def venv_bin(self, filename=None): """ Return path to the virtualenv bin path, or a specific binary. @@ -287,8 +311,7 @@ def install_core_requirements(self): 'pip', 'install', '--upgrade', - '--cache-dir', - self.project.pip_cache_path, + *self._pip_cache_cmd_argument(), ] # Install latest pip first, @@ -384,8 +407,7 @@ def install_requirements_file(self, install): args += ['--upgrade'] args += [ '--exists-action=w', - '--cache-dir', - self.project.pip_cache_path, + *self._pip_cache_cmd_argument(), '-r', requirements_file_path, ] @@ -581,8 +603,7 @@ def install_core_requirements(self): 'pip', 'install', '-U', - '--cache-dir', - self.project.pip_cache_path, + *self._pip_cache_cmd_argument(), ] pip_cmd.extend(pip_requirements) self.build_env.run( From 8364954b968bbf4e896ac10cd3f6976fcb06e18c Mon Sep 17 00:00:00 2001 From: Santos Gallegos Date: Thu, 3 Oct 2019 16:04:06 -0500 Subject: [PATCH 2/2] Invert conditional --- readthedocs/doc_builder/python_environments.py | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/readthedocs/doc_builder/python_environments.py b/readthedocs/doc_builder/python_environments.py index 8bcc3d71c35..51749da1adb 100644 --- a/readthedocs/doc_builder/python_environments.py +++ b/readthedocs/doc_builder/python_environments.py @@ -132,19 +132,17 @@ def _pip_cache_cmd_argument(self): need to cache anything. """ if ( - not settings.RTD_CLEAN_AFTER_BUILD and - not self.project.has_feature(Feature.CLEAN_AFTER_BUILD) + settings.RTD_CLEAN_AFTER_BUILD or + self.project.has_feature(Feature.CLEAN_AFTER_BUILD) ): return [ - '--cache-dir', - self.project.pip_cache_path, + '--no-cache-dir', ] - return [ - '--no-cache-dir', + '--cache-dir', + self.project.pip_cache_path, ] - def venv_bin(self, filename=None): """ Return path to the virtualenv bin path, or a specific binary.