Skip to content

Add support for Pip's extra dependencies in YAML config. #2368

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

Merged
merged 1 commit into from
Aug 24, 2016
Merged
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
50 changes: 50 additions & 0 deletions docs/yaml-config.rst
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,56 @@ documentation.

conf_file: project2/docs/conf.py

python.extra_requirements
`````````````````````````

* Default: ``[]``
* Type: List

List of `extra requirements`_ sections to install, additionnaly to the
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo here: additionnaly

`package default dependencies`_. Only works if ``python.pip_install`` option
above is set to ``True``.

Let's say your Python package has a ``setup.py`` which looks like this:

.. code-block:: python

from setuptools import setup

setup(
name="my_package",
# (...)
install_requires=[
'requests',
'simplejson'],
extras_require={
'tests': [
'nose',
'pycodestyle >= 2.1.0'],
'docs': [
'sphinx >= 1.4',
'sphinx_rtd_theme']}
)

Then to have all dependencies from the ``tests`` and ``docs`` sections
installed in addition to the default ``requests`` and ``simplejson``, use the
``extra_requirements`` as such:

.. code-block:: yaml

python:
extra_requirements:
- tests
- docs

Behind the scene the following Pip command will be run:

.. code-block:: shell

$ pip install -e .[tests,docs]


.. _issue: https://github.com/rtfd/readthedocs.org/issues
.. _environment file: http://conda.pydata.org/docs/using/envs.html#share-an-environment
.. _extra requirements: http://setuptools.readthedocs.io/en/latest/setuptools.html#declaring-extras-optional-features-with-their-own-dependencies
.. _package default dependencies: http://setuptools.readthedocs.io/en/latest/setuptools.html#declaring-dependencies
8 changes: 8 additions & 0 deletions readthedocs/doc_builder/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@ def install_project(self):
else:
return self._project.install_project

@property
def extra_requirements(self):
if self.pip_install and 'extra_requirements' in self._yaml_config.get(
'python', {}):
return self._yaml_config['python']['extra_requirements']
else:
return []

@property
def python_interpreter(self):
if 'version' in self._yaml_config.get('python', {}):
Expand Down
6 changes: 5 additions & 1 deletion readthedocs/doc_builder/python_environments.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,18 @@ def install_package(self):
setup_path = os.path.join(self.checkout_path, 'setup.py')
if os.path.isfile(setup_path) and self.config.install_project:
if self.config.pip_install or getattr(settings, 'USE_PIP_INSTALL', False):
extra_req_param = ''
if self.config.extra_requirements:
extra_req_param = '[{0}]'.format(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

{0} -> {}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

{0} is used everywhere else in the code base. For Python 2.6 compatibility I think.

Even if I can find a couple of {} occurrences for string formatting, the majority is {0}-like.

Should I switch back to {} anyway?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd say go with the current {0} style :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK good.

','.join(self.config.extra_requirements))
self.build_env.run(
'python',
self.venv_bin(filename='pip'),
'install',
'--ignore-installed',
'--cache-dir',
self.project.pip_cache_path,
'.',
'.{0}'.format(extra_req_param),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

{0} -> {}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same question as #2368 (comment).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As decided in #2368 (comment) , we'll keep the {0} format.

cwd=self.checkout_path,
bin_path=self.venv_bin()
)
Expand Down
22 changes: 22 additions & 0 deletions readthedocs/rtd_tests/tests/test_config_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,28 @@ def test_install_project(self):
config = ConfigWrapper(version=self.version, yaml_config=yaml_config)
self.assertEqual(config.install_project, False)

def test_extra_requirements(self):
yaml_config = get_build_config({'python': {
'pip_install': True,
'extra_requirements': ['tests', 'docs']}})
config = ConfigWrapper(version=self.version, yaml_config=yaml_config)
self.assertEqual(config.extra_requirements, ['tests', 'docs'])

yaml_config = get_build_config({'python': {
'extra_requirements': ['tests', 'docs']}})
config = ConfigWrapper(version=self.version, yaml_config=yaml_config)
self.assertEqual(config.extra_requirements, [])

yaml_config = get_build_config({})
config = ConfigWrapper(version=self.version, yaml_config=yaml_config)
self.assertEqual(config.extra_requirements, [])

yaml_config = get_build_config({'python': {
'setup_py_install': True,
'extra_requirements': ['tests', 'docs']}})
config = ConfigWrapper(version=self.version, yaml_config=yaml_config)
self.assertEqual(config.extra_requirements, [])

def test_conda(self):
to_find = 'urls.py'
yaml_config = get_build_config({'conda': {'file': to_find}})
Expand Down
2 changes: 1 addition & 1 deletion requirements/pip.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ docutils==0.11
Sphinx==1.3.5
Pygments==2.0.2
mkdocs==0.14.0
readthedocs-build==2.0.5
git+https://github.com/rtfd/readthedocs-build.git@ef2d91962aeb5391f21245d1e3c311e33785649d#egg=readthedocs-build-2.0.6.dev
django==1.8.3

django-tastypie==0.12.2
Expand Down