Skip to content

Do not use --cache-dir for pip if CLEAN_AFTER_BUILD is enabled #6239

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 3 commits into from
Oct 3, 2019
Merged
Changes from 1 commit
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
37 changes: 29 additions & 8 deletions readthedocs/doc_builder/python_environments.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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.
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
]
Expand Down Expand Up @@ -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(
Expand Down