Skip to content

Commit 475cf0b

Browse files
committed
Properly install pip & conda deps
1 parent d76a50e commit 475cf0b

File tree

1 file changed

+47
-19
lines changed

1 file changed

+47
-19
lines changed

readthedocs/doc_builder/python_environments.py

Lines changed: 47 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def venv_bin(self, version=LATEST, filename=None):
7777
class Virtualenv(PythonEnvironment):
7878

7979
def venv_path(self, version=LATEST):
80-
return os.path.join(self.doc_path, 'envs', version)
80+
return os.path.join(self.project.doc_path, 'envs', version)
8181

8282
def setup_base(self, config):
8383
site_packages = '--no-site-packages'
@@ -131,7 +131,7 @@ def install_user_requirements(self, config):
131131
requirements_file_path = self.project.requirements_file
132132
if not requirements_file_path:
133133
builder_class = get_builder_class(self.project.documentation_type)
134-
docs_dir = (builder_class(self.build_env)
134+
docs_dir = (builder_class(build_env=self.build_env, python_env=self)
135135
.docs_dir())
136136
for path in [docs_dir, '']:
137137
for req_file in ['pip_requirements.txt', 'requirements.txt']:
@@ -157,25 +157,31 @@ def install_user_requirements(self, config):
157157
class Conda(PythonEnvironment):
158158

159159
def venv_path(self, version=LATEST):
160-
return os.path.join(self.doc_path, 'conda', version)
160+
return os.path.join(self.project.doc_path, 'conda', version)
161161

162162
def setup_base(self, config):
163-
env_path = self.venv_path(version=self.version.slug)
164-
if 'python' in config:
165-
python_version = config['python'].get('version', 2)
166-
else:
167-
python_version = 2
168-
if not os.path.exists(env_path):
169-
self.build_env.run(
170-
'conda',
171-
'create',
172-
'--yes',
173-
'--prefix',
174-
env_path,
175-
'python={python_version}'.format(python_version=python_version),
176-
)
163+
conda_env_path = os.path.join(self.project.doc_path, 'conda')
164+
version_path = os.path.join(conda_env_path, self.version.slug)
165+
166+
python_version = config['python'].get('version', 2)
167+
if os.path.exists(version_path):
168+
# Re-create conda directory each time to keep fresh state
169+
self._log('Removing existing conda directory')
170+
shutil.rmtree(version_path)
171+
self.build_env.run(
172+
'conda',
173+
'create',
174+
'--yes',
175+
'--name',
176+
self.version.slug,
177+
'python={python_version}'.format(python_version=python_version),
178+
environment={'CONDA_ENVS_PATH': conda_env_path}
179+
)
177180

178181
def install_core_requirements(self, config):
182+
conda_env_path = os.path.join(self.project.doc_path, 'conda')
183+
184+
# Use conda for requirements it packages
179185
requirements = [
180186
'sphinx==1.3.1',
181187
'Pygments==2.0.2',
@@ -192,11 +198,34 @@ def install_core_requirements(self, config):
192198
cmd = [
193199
'conda',
194200
'install',
195-
'-y',
201+
'--yes',
202+
'--name',
203+
self.version.slug,
196204
]
197205
cmd.extend(requirements)
198206
self.build_env.run(
199207
*cmd,
208+
environment={'CONDA_ENVS_PATH': conda_env_path}
209+
)
210+
211+
# Install pip-only things.
212+
pip_requirements = [
213+
'mkdocs==0.14.0',
214+
'readthedocs-sphinx-ext==0.5.4',
215+
'recommonmark==0.1.1',
216+
]
217+
218+
pip_cmd = [
219+
'python',
220+
self.venv_bin(version=self.version.slug, filename='pip'),
221+
'install',
222+
'-U',
223+
'--cache-dir',
224+
self.project.pip_cache_path,
225+
]
226+
pip_cmd.extend(pip_requirements)
227+
self.build_env.run(
228+
*pip_cmd,
200229
bin_path=self.venv_bin(version=self.version.slug)
201230
)
202231

@@ -210,6 +239,5 @@ def install_user_requirements(self, config):
210239
self.version.slug,
211240
'--file',
212241
config['conda']['file'],
213-
cwd=self.checkout_path,
214242
environment={'CONDA_ENVS_PATH': conda_env_path}
215243
)

0 commit comments

Comments
 (0)