From 7d5962bfdab8e926e3ec3efb9fae148b1869a1e6 Mon Sep 17 00:00:00 2001 From: Manuel Kaufmann Date: Tue, 9 Jul 2019 17:16:06 +0200 Subject: [PATCH] Update conda at startup Behind a Feature flag, we can decide if we want to update the version of ``conda`` from the system to its latest version available. This allow us to use a new release of ``conda`` that is not released under Miniconda yet, but also to not upgrade the Docker image just because of a new release of Miniconda. (the overhead added is around 60 seconds in total) --- docs/guides/feature-flags.rst | 8 ++++++- .../doc_builder/python_environments.py | 23 ++++++++++++++++++- readthedocs/projects/models.py | 5 ++++ 3 files changed, 34 insertions(+), 2 deletions(-) diff --git a/docs/guides/feature-flags.rst b/docs/guides/feature-flags.rst index 2a61ff03ac7..fd73f90a178 100644 --- a/docs/guides/feature-flags.rst +++ b/docs/guides/feature-flags.rst @@ -14,6 +14,12 @@ Available Flags ``PIP_ALWAYS_UPGRADE``: :featureflags:`PIP_ALWAYS_UPGRADE` +``UPDATE_CONDA_STARTUP``: :featureflags:`UPDATE_CONDA_STARTUP` + +The version of ``conda`` used in the build process could not be the latest one. +This is because we use Miniconda, which its release process is a little more slow than ``conda`` itself. +In case you prefer to use the latest ``conda`` version available, this is the flag you need. + ``DONT_OVERWRITE_SPHINX_CONTEXT``: :featureflags:`DONT_OVERWRITE_SPHINX_CONTEXT` ``DONT_SHALLOW_CLONE``: :featureflags:`DONT_SHALLOW_CLONE` @@ -22,4 +28,4 @@ The ``DONT_SHALLOW_CLONE`` flag is useful if your code accesses old commits duri e.g. python-reno release notes manager is known to do that (error message line would probably include one of old Git commit id's). -``USE_TESTING_BUILD_IMAGE``: :featureflags:`USE_TESTING_BUILD_IMAGE` \ No newline at end of file +``USE_TESTING_BUILD_IMAGE``: :featureflags:`USE_TESTING_BUILD_IMAGE` diff --git a/readthedocs/doc_builder/python_environments.py b/readthedocs/doc_builder/python_environments.py index 8306a1e57b0..80a725fc2bb 100644 --- a/readthedocs/doc_builder/python_environments.py +++ b/readthedocs/doc_builder/python_environments.py @@ -405,6 +405,23 @@ class Conda(PythonEnvironment): def venv_path(self): return os.path.join(self.project.doc_path, 'conda', self.version.slug) + def _update_conda_startup(self): + """ + Update ``conda`` before use it for the first time. + + This makes the Docker image to use the latest version of ``conda`` + independently the version of Miniconda that it has installed. + """ + self.build_env.run( + 'conda', + 'update', + '--yes', + '--quiet', + '--name=base', + '--channel=defaults', + 'conda', + ) + def setup_base(self): conda_env_path = os.path.join(self.project.doc_path, 'conda') version_path = os.path.join(conda_env_path, self.version.slug) @@ -417,9 +434,13 @@ def setup_base(self): 'project': self.project.slug, 'version': self.version.slug, 'msg': 'Removing existing conda directory', - } + }, ) shutil.rmtree(version_path) + + if self.project.has_feature(Feature.UPDATE_CONDA_STARTUP): + self._update_conda_startup() + self.build_env.run( 'conda', 'env', diff --git a/readthedocs/projects/models.py b/readthedocs/projects/models.py index e60d77440c4..6ed508423ce 100644 --- a/readthedocs/projects/models.py +++ b/readthedocs/projects/models.py @@ -1391,6 +1391,7 @@ def add_features(sender, **kwargs): SHARE_SPHINX_DOCTREE = 'share_sphinx_doctree' DEFAULT_TO_MKDOCS_0_17_3 = 'default_to_mkdocs_0_17_3' CLEAN_AFTER_BUILD = 'clean_after_build' + UPDATE_CONDA_STARTUP = 'upgrade_conda_startup' FEATURES = ( (USE_SPHINX_LATEST, _('Use latest version of Sphinx')), @@ -1431,6 +1432,10 @@ def add_features(sender, **kwargs): CLEAN_AFTER_BUILD, _('Clean all files used in the build process'), ), + ( + UPDATE_CONDA_STARTUP, + _('Upgrade conda before creating the environment'), + ), ) projects = models.ManyToManyField(