Skip to content

Commit 7bfdacf

Browse files
committed
Write the modified conda env to a temporary file
1 parent c669154 commit 7bfdacf

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

readthedocs/doc_builder/python_environments.py

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
import os
1010
import shutil
1111
import tarfile
12+
import tempfile
13+
from pathlib import Path
1214

1315
import yaml
1416
from django.conf import settings
@@ -689,9 +691,12 @@ def setup_base(self):
689691
if self.project.has_feature(Feature.UPDATE_CONDA_STARTUP):
690692
self._update_conda_startup()
691693

694+
conda_env_file = self.config.conda.environment
692695
if self.project.has_feature(Feature.CONDA_APPEND_CORE_REQUIREMENTS):
693-
self._append_core_requirements()
694-
self._show_environment_yaml()
696+
conda_env_file = self._append_core_requirements()
697+
log.warning("Exists: %s", Path(conda_env_file).exists())
698+
self._show_environment_yaml(conda_env_file)
699+
log.warning(self.config)
695700

696701
if all([
697702
# The project has CONDA_USES_MAMBA feature enabled and,
@@ -710,16 +715,17 @@ def setup_base(self):
710715
'--name',
711716
self.version.slug,
712717
'--file',
713-
self.config.conda.environment,
718+
conda_env_file,
714719
bin_path=None, # Don't use conda bin that doesn't exist yet
715720
cwd=self.checkout_path,
716721
)
717722

718-
def _show_environment_yaml(self):
723+
def _show_environment_yaml(self, conda_env_file=None):
719724
"""Show ``environment.yml`` file in the Build output."""
725+
conda_env_file = conda_env_file or self.config.conda.environment
720726
self.build_env.run(
721727
'cat',
722-
self.config.conda.environment,
728+
conda_env_file,
723729
cwd=self.checkout_path,
724730
)
725731

@@ -767,16 +773,16 @@ def _append_core_requirements(self):
767773
dependencies.append(pip_dependencies)
768774
dependencies.extend(conda_requirements)
769775
environment.update({'dependencies': dependencies})
776+
_, output_filename = tempfile.mkstemp(dir=Path(self.checkout_path) / ".." / "..", suffix=".yml")
770777
try:
771778
outputfile = codecs.open(
772-
os.path.join(
773-
self.checkout_path,
774-
self.config.conda.environment,
775-
),
779+
output_filename,
776780
encoding='utf-8',
777781
mode='w',
778782
)
779783
yaml.safe_dump(environment, outputfile)
784+
785+
return output_filename
780786
except IOError:
781787
log.warning(
782788
'There was an error while writing the new Conda '

0 commit comments

Comments
 (0)