Skip to content

Commit

Permalink
Update conda at startup
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
humitos committed Jul 9, 2019
1 parent 801f63b commit 7d5962b
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 2 deletions.
8 changes: 7 additions & 1 deletion docs/guides/feature-flags.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand All @@ -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`
``USE_TESTING_BUILD_IMAGE``: :featureflags:`USE_TESTING_BUILD_IMAGE`
23 changes: 22 additions & 1 deletion readthedocs/doc_builder/python_environments.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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',
Expand Down
5 changes: 5 additions & 0 deletions readthedocs/projects/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')),
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 7d5962b

Please sign in to comment.