Skip to content

Write the modified conda env to a temporary file #8585

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

Closed
wants to merge 3 commits into from
Closed
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
23 changes: 14 additions & 9 deletions readthedocs/doc_builder/python_environments.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import os
import shutil
import tarfile
import tempfile
from pathlib import Path

import yaml
from django.conf import settings
Expand Down Expand Up @@ -689,9 +691,10 @@ def setup_base(self):
if self.project.has_feature(Feature.UPDATE_CONDA_STARTUP):
self._update_conda_startup()

conda_env_file = self.config.conda.environment
if self.project.has_feature(Feature.CONDA_APPEND_CORE_REQUIREMENTS):
self._append_core_requirements()
self._show_environment_yaml()
conda_env_file = self._append_core_requirements()
self._show_environment_yaml(conda_env_file)

if all([
# The project has CONDA_USES_MAMBA feature enabled and,
Expand All @@ -710,16 +713,17 @@ def setup_base(self):
'--name',
self.version.slug,
'--file',
self.config.conda.environment,
conda_env_file,
bin_path=None, # Don't use conda bin that doesn't exist yet
cwd=self.checkout_path,
)

def _show_environment_yaml(self):
def _show_environment_yaml(self, conda_env_file=None):
"""Show ``environment.yml`` file in the Build output."""
conda_env_file = conda_env_file or self.config.conda.environment
self.build_env.run(
'cat',
self.config.conda.environment,
conda_env_file,
cwd=self.checkout_path,
)

Expand Down Expand Up @@ -767,16 +771,17 @@ def _append_core_requirements(self):
dependencies.append(pip_dependencies)
dependencies.extend(conda_requirements)
environment.update({'dependencies': dependencies})
_, output_filename = tempfile.mkstemp(dir=Path(self.checkout_path) / ".." / "..",
suffix=".yml")
try:
outputfile = codecs.open(
os.path.join(
self.checkout_path,
self.config.conda.environment,
),
output_filename,
encoding='utf-8',
mode='w',
)
yaml.safe_dump(environment, outputfile)

return output_filename
except IOError:
log.warning(
'There was an error while writing the new Conda '
Expand Down