Skip to content

Commit 59d9b3c

Browse files
kdeldyckeKevin Deldycke
authored and
Kevin Deldycke
committed
Add support for Pip's extra dependencies in YAML config.
Closes #173.
1 parent ef40e22 commit 59d9b3c

File tree

5 files changed

+86
-2
lines changed

5 files changed

+86
-2
lines changed

docs/yaml-config.rst

+50
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,56 @@ documentation.
144144
145145
conf_file: project2/docs/conf.py
146146
147+
python.extra_requirements
148+
`````````````````````````
149+
150+
* Default: ``[]``
151+
* Type: List
152+
153+
List of `extra requirements`_ sections to install, additionnaly to the
154+
`package default dependencies`_. Only works if ``python.pip_install`` option
155+
above is set to ``True``.
156+
157+
Let's say your Python package has a ``setup.py`` which looks like this:
158+
159+
.. code-block:: python
160+
161+
from setuptools import setup
162+
163+
setup(
164+
name="my_package",
165+
# (...)
166+
install_requires=[
167+
'requests',
168+
'simplejson'],
169+
extras_require={
170+
'tests': [
171+
'nose',
172+
'pycodestyle >= 2.1.0'],
173+
'docs': [
174+
'sphinx >= 1.4',
175+
'sphinx_rtd_theme']}
176+
)
177+
178+
Then to have all dependencies from the ``tests`` and ``docs`` sections
179+
installed in addition to the default ``requests`` and ``simplejson``, use the
180+
``extra_requirements`` as such:
181+
182+
.. code-block:: yaml
183+
184+
python:
185+
extra_requirements:
186+
- tests
187+
- docs
188+
189+
Behind the scene the following Pip command will be run:
190+
191+
.. code-block:: shell
192+
193+
$ pip install -e .[tests,docs]
194+
147195
148196
.. _issue: https://github.com/rtfd/readthedocs.org/issues
149197
.. _environment file: http://conda.pydata.org/docs/using/envs.html#share-an-environment
198+
.. _extra requirements: http://setuptools.readthedocs.io/en/latest/setuptools.html#declaring-extras-optional-features-with-their-own-dependencies
199+
.. _package default dependencies: http://setuptools.readthedocs.io/en/latest/setuptools.html#declaring-dependencies

readthedocs/doc_builder/config.py

+8
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,14 @@ def install_project(self):
3939
else:
4040
return self._project.install_project
4141

42+
@property
43+
def extra_requirements(self):
44+
if self.pip_install and 'extra_requirements' in self._yaml_config.get(
45+
'python', {}):
46+
return self._yaml_config['python']['extra_requirements']
47+
else:
48+
return []
49+
4250
@property
4351
def python_interpreter(self):
4452
if 'version' in self._yaml_config.get('python', {}):

readthedocs/doc_builder/python_environments.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,18 @@ def install_package(self):
4444
setup_path = os.path.join(self.checkout_path, 'setup.py')
4545
if os.path.isfile(setup_path) and self.config.install_project:
4646
if self.config.pip_install or getattr(settings, 'USE_PIP_INSTALL', False):
47+
extra_req_param = ''
48+
if self.config.extra_requirements:
49+
extra_req_param = '[{0}]'.format(
50+
','.join(self.config.extra_requirements))
4751
self.build_env.run(
4852
'python',
4953
self.venv_bin(filename='pip'),
5054
'install',
5155
'--ignore-installed',
5256
'--cache-dir',
5357
self.project.pip_cache_path,
54-
'.',
58+
'.{0}'.format(extra_req_param),
5559
cwd=self.checkout_path,
5660
bin_path=self.venv_bin()
5761
)

readthedocs/rtd_tests/tests/test_config_wrapper.py

+22
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,28 @@ def test_install_project(self):
5555
config = ConfigWrapper(version=self.version, yaml_config=yaml_config)
5656
self.assertEqual(config.install_project, False)
5757

58+
def test_extra_requirements(self):
59+
yaml_config = get_build_config({'python': {
60+
'pip_install': True,
61+
'extra_requirements': ['tests', 'docs']}})
62+
config = ConfigWrapper(version=self.version, yaml_config=yaml_config)
63+
self.assertEqual(config.extra_requirements, ['tests', 'docs'])
64+
65+
yaml_config = get_build_config({'python': {
66+
'extra_requirements': ['tests', 'docs']}})
67+
config = ConfigWrapper(version=self.version, yaml_config=yaml_config)
68+
self.assertEqual(config.extra_requirements, [])
69+
70+
yaml_config = get_build_config({})
71+
config = ConfigWrapper(version=self.version, yaml_config=yaml_config)
72+
self.assertEqual(config.extra_requirements, [])
73+
74+
yaml_config = get_build_config({'python': {
75+
'setup_py_install': True,
76+
'extra_requirements': ['tests', 'docs']}})
77+
config = ConfigWrapper(version=self.version, yaml_config=yaml_config)
78+
self.assertEqual(config.extra_requirements, [])
79+
5880
def test_conda(self):
5981
to_find = 'urls.py'
6082
yaml_config = get_build_config({'conda': {'file': to_find}})

requirements/pip.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ docutils==0.11
55
Sphinx==1.3.5
66
Pygments==2.0.2
77
mkdocs==0.14.0
8-
readthedocs-build==2.0.5
8+
git+https://github.com/rtfd/readthedocs-build.git@ef2d91962aeb5391f21245d1e3c311e33785649d#egg=readthedocs-build-2.0.6.dev
99
django==1.8.3
1010

1111
django-tastypie==0.12.2

0 commit comments

Comments
 (0)