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

Add optional pipenv install stage #4254

Closed
wants to merge 3 commits into from
Closed
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
12 changes: 12 additions & 0 deletions readthedocs/doc_builder/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,18 @@ def requirements_file(self):
return self._yaml_config['requirements_file']
return self._project.requirements_file

@property
def pipenv_enabled(self):
if 'enabled' in self._yaml_config.get('pipenv', {}):
return self._yaml_config['pipenv']['enabled']
return False

@property
def pipenv_options(self):
if 'options' in self._yaml_config.get('pipenv', {}):
return self._yaml_config['pipenv']['options']
return []

@property
def formats(self):
if 'formats' in self._yaml_config:
Expand Down
19 changes: 19 additions & 0 deletions readthedocs/doc_builder/python_environments.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,9 @@ def install_core_requirements(self):
'recommonmark==0.4.0',
]

if self.config.pipenv_enabled:
requirements.append('pipenv==2018.5.18')

if self.project.documentation_type == 'mkdocs':
requirements.append('mkdocs==0.17.3')
else:
Expand Down Expand Up @@ -304,6 +307,22 @@ def install_user_requirements(self):
bin_path=self.venv_bin()
)

def install_from_pipfile(self):
if self.config.pipenv_enabled:
args = [
'python',
self.venv_bin(filename='pipenv'),
'install',
'--system',
]
if self.config.pipenv_options:
args.extend(self.config.pipenv_options)
self.build_env.run(
*args,
cwd=self.checkout_path,
bin_path=self.venv_bin()
)


class Conda(PythonEnvironment):

Expand Down
1 change: 1 addition & 0 deletions readthedocs/projects/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -617,6 +617,7 @@ def setup_python_environment(self):
self.python_env.save_environment_json()
self.python_env.install_core_requirements()
self.python_env.install_user_requirements()
self.python_env.install_from_pipfile()
self.python_env.install_package()

def build_docs(self):
Expand Down
70 changes: 70 additions & 0 deletions readthedocs/rtd_tests/tests/test_doc_building.py
Original file line number Diff line number Diff line change
Expand Up @@ -1179,6 +1179,29 @@ def test_install_core_requirements_mkdocs(self):
*args, bin_path=mock.ANY
)

@patch.object(ConfigWrapper, 'pipenv_enabled', new_callable=PropertyMock)
def test_install_core_requirements_pipenv(self, pipenv_enabled):
pipenv_enabled.return_value = True
python_env = Virtualenv(
version=self.version_sphinx,
build_env=self.build_env_mock,
)
python_env.install_core_requirements()

requirements_pipenv = [
'commonmark==0.5.4',
'recommonmark==0.4.0',
'pipenv==2018.5.18',
'sphinx==1.7.4',
'sphinx-rtd-theme<0.5',
'readthedocs-sphinx-ext<0.6',
]
requirements = self.base_requirements + requirements_pipenv
args = self.pip_install_args + requirements
self.build_env_mock.run.assert_called_once_with(
*args, bin_path=mock.ANY
)

def test_install_user_requirements(self):
"""
If a projects does not specify a requirements file,
Expand Down Expand Up @@ -1343,6 +1366,53 @@ def test_install_user_requirements_conda(self):
python_env.install_user_requirements()
self.build_env_mock.run.assert_not_called()

@patch.object(ConfigWrapper, 'pipenv_enabled', new_callable=PropertyMock)
def test_pipenv_install(self, pipenv_enabled):
pipenv_enabled.return_value = True
python_env = Virtualenv(
version=self.version_sphinx,
build_env=self.build_env_mock,
)

args = [
'python',
mock.ANY, # pipenv path
'install',
'--system',
]

python_env.install_from_pipfile()
self.build_env_mock.run.assert_called_with(
*args, cwd=mock.ANY, bin_path=mock.ANY
)

@patch.object(ConfigWrapper, "pipenv_options", new_callable=PropertyMock)
@patch.object(ConfigWrapper, "pipenv_enabled", new_callable=PropertyMock)
def test_pipenv_install_with_options(self, pipenv_enabled, pipenv_options):
options = [
'--dev',
'--skip-lock',
]
pipenv_enabled.return_value = True
pipenv_options.return_value = options
python_env = Virtualenv(
version=self.version_sphinx,
build_env=self.build_env_mock,
)

args = [
'python',
mock.ANY, # pipenv path
'install',
'--system',
]
args.extend(options)

python_env.install_from_pipfile()
self.build_env_mock.run.assert_called_with(
*args, cwd=mock.ANY, bin_path=mock.ANY
)


class AutoWipeEnvironmentBase(object):
fixtures = ['test_data']
Expand Down