From 1da5bd91ee74d64e14509e47dbb29df733e06704 Mon Sep 17 00:00:00 2001 From: Tobotimus Date: Sat, 16 Jun 2018 23:25:15 +1000 Subject: [PATCH 1/3] Add pipenv install stage and configuration --- readthedocs/doc_builder/config.py | 12 ++++++++++++ .../doc_builder/python_environments.py | 19 +++++++++++++++++++ readthedocs/projects/tasks.py | 1 + 3 files changed, 32 insertions(+) diff --git a/readthedocs/doc_builder/config.py b/readthedocs/doc_builder/config.py index 05cc58397fc..eb59aaac3f1 100644 --- a/readthedocs/doc_builder/config.py +++ b/readthedocs/doc_builder/config.py @@ -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: diff --git a/readthedocs/doc_builder/python_environments.py b/readthedocs/doc_builder/python_environments.py index 96190a47919..565c2cdffbb 100644 --- a/readthedocs/doc_builder/python_environments.py +++ b/readthedocs/doc_builder/python_environments.py @@ -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: @@ -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): diff --git a/readthedocs/projects/tasks.py b/readthedocs/projects/tasks.py index 9a7bd48484c..6ad4a1f8952 100644 --- a/readthedocs/projects/tasks.py +++ b/readthedocs/projects/tasks.py @@ -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): From 4fcdc57b83a9bb1e936b09eef2e9986df6e36f73 Mon Sep 17 00:00:00 2001 From: Tobotimus Date: Sat, 16 Jun 2018 23:25:43 +1000 Subject: [PATCH 2/3] Add tests for pipenv install --- .../rtd_tests/tests/test_doc_building.py | 61 +++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/readthedocs/rtd_tests/tests/test_doc_building.py b/readthedocs/rtd_tests/tests/test_doc_building.py index 27664688262..71c795d5be8 100644 --- a/readthedocs/rtd_tests/tests/test_doc_building.py +++ b/readthedocs/rtd_tests/tests/test_doc_building.py @@ -1343,6 +1343,67 @@ def test_install_user_requirements_conda(self): python_env.install_user_requirements() self.build_env_mock.run.assert_not_called() + def test_pipenv_install(self): + config_data = { + 'pipenv': { + 'enabled': True, + 'options': [], + }, + } + yaml_config = create_load(config_data)()[0] + config = ConfigWrapper( + version=self.version_sphinx, yaml_config=yaml_config) + python_env = Virtualenv( + version=self.version_sphinx, + build_env=self.build_env_mock, + config=config, + ) + + 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 + ) + + def test_pipenv_install_with_options(self): + options = [ + '--dev', + '--skip-lock' + ] + config_data = { + 'pipenv': { + 'enabled': True, + 'options': options, + }, + } + yaml_config = create_load(config_data)()[0] + config = ConfigWrapper( + version=self.version_sphinx, yaml_config=yaml_config) + python_env = Virtualenv( + version=self.version_sphinx, + build_env=self.build_env_mock, + config=config, + ) + + 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'] From 7bd484413c299455197605210d3e26ad46d2724d Mon Sep 17 00:00:00 2001 From: Tobotimus Date: Sun, 17 Jun 2018 14:11:26 +1000 Subject: [PATCH 3/3] Add test for installing pipenv Also refactored other tests for pipenv. --- .../rtd_tests/tests/test_doc_building.py | 55 +++++++++++-------- 1 file changed, 32 insertions(+), 23 deletions(-) diff --git a/readthedocs/rtd_tests/tests/test_doc_building.py b/readthedocs/rtd_tests/tests/test_doc_building.py index 71c795d5be8..d4dd5dc337d 100644 --- a/readthedocs/rtd_tests/tests/test_doc_building.py +++ b/readthedocs/rtd_tests/tests/test_doc_building.py @@ -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, @@ -1343,20 +1366,12 @@ def test_install_user_requirements_conda(self): python_env.install_user_requirements() self.build_env_mock.run.assert_not_called() - def test_pipenv_install(self): - config_data = { - 'pipenv': { - 'enabled': True, - 'options': [], - }, - } - yaml_config = create_load(config_data)()[0] - config = ConfigWrapper( - version=self.version_sphinx, yaml_config=yaml_config) + @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, - config=config, ) args = [ @@ -1371,24 +1386,18 @@ def test_pipenv_install(self): *args, cwd=mock.ANY, bin_path=mock.ANY ) - def test_pipenv_install_with_options(self): + @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' + '--skip-lock', ] - config_data = { - 'pipenv': { - 'enabled': True, - 'options': options, - }, - } - yaml_config = create_load(config_data)()[0] - config = ConfigWrapper( - version=self.version_sphinx, yaml_config=yaml_config) + pipenv_enabled.return_value = True + pipenv_options.return_value = options python_env = Virtualenv( version=self.version_sphinx, build_env=self.build_env_mock, - config=config, ) args = [