Skip to content
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

Update conda at startup #5897

Merged
merged 1 commit into from
Jul 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
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
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):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should also check if the project is using conda, so we don't run it if the user isn't using conda.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code is under the Conda class, not need to add a check here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Santos is right.

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 = 'update_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