Skip to content

Commit

Permalink
Properly install pip & conda deps
Browse files Browse the repository at this point in the history
  • Loading branch information
ericholscher committed Dec 21, 2015
1 parent d76a50e commit 475cf0b
Showing 1 changed file with 47 additions and 19 deletions.
66 changes: 47 additions & 19 deletions readthedocs/doc_builder/python_environments.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def venv_bin(self, version=LATEST, filename=None):
class Virtualenv(PythonEnvironment):

def venv_path(self, version=LATEST):
return os.path.join(self.doc_path, 'envs', version)
return os.path.join(self.project.doc_path, 'envs', version)

def setup_base(self, config):
site_packages = '--no-site-packages'
Expand Down Expand Up @@ -131,7 +131,7 @@ def install_user_requirements(self, config):
requirements_file_path = self.project.requirements_file
if not requirements_file_path:
builder_class = get_builder_class(self.project.documentation_type)
docs_dir = (builder_class(self.build_env)
docs_dir = (builder_class(build_env=self.build_env, python_env=self)
.docs_dir())
for path in [docs_dir, '']:
for req_file in ['pip_requirements.txt', 'requirements.txt']:
Expand All @@ -157,25 +157,31 @@ def install_user_requirements(self, config):
class Conda(PythonEnvironment):

def venv_path(self, version=LATEST):
return os.path.join(self.doc_path, 'conda', version)
return os.path.join(self.project.doc_path, 'conda', version)

def setup_base(self, config):
env_path = self.venv_path(version=self.version.slug)
if 'python' in config:
python_version = config['python'].get('version', 2)
else:
python_version = 2
if not os.path.exists(env_path):
self.build_env.run(
'conda',
'create',
'--yes',
'--prefix',
env_path,
'python={python_version}'.format(python_version=python_version),
)
conda_env_path = os.path.join(self.project.doc_path, 'conda')
version_path = os.path.join(conda_env_path, self.version.slug)

python_version = config['python'].get('version', 2)
if os.path.exists(version_path):
# Re-create conda directory each time to keep fresh state
self._log('Removing existing conda directory')
shutil.rmtree(version_path)
self.build_env.run(
'conda',
'create',
'--yes',
'--name',
self.version.slug,
'python={python_version}'.format(python_version=python_version),
environment={'CONDA_ENVS_PATH': conda_env_path}
)

def install_core_requirements(self, config):
conda_env_path = os.path.join(self.project.doc_path, 'conda')

# Use conda for requirements it packages
requirements = [
'sphinx==1.3.1',
'Pygments==2.0.2',
Expand All @@ -192,11 +198,34 @@ def install_core_requirements(self, config):
cmd = [
'conda',
'install',
'-y',
'--yes',
'--name',
self.version.slug,
]
cmd.extend(requirements)
self.build_env.run(
*cmd,
environment={'CONDA_ENVS_PATH': conda_env_path}
)

# Install pip-only things.
pip_requirements = [
'mkdocs==0.14.0',
'readthedocs-sphinx-ext==0.5.4',
'recommonmark==0.1.1',
]

pip_cmd = [
'python',
self.venv_bin(version=self.version.slug, filename='pip'),
'install',
'-U',
'--cache-dir',
self.project.pip_cache_path,
]
pip_cmd.extend(pip_requirements)
self.build_env.run(
*pip_cmd,
bin_path=self.venv_bin(version=self.version.slug)
)

Expand All @@ -210,6 +239,5 @@ def install_user_requirements(self, config):
self.version.slug,
'--file',
config['conda']['file'],
cwd=self.checkout_path,
environment={'CONDA_ENVS_PATH': conda_env_path}
)

0 comments on commit 475cf0b

Please sign in to comment.