Skip to content
This repository was archived by the owner on Mar 18, 2022. It is now read-only.

Commit ef2d919

Browse files
authored
Merge pull request #16 from kdeldycke/add-pip-extra-dependencies-yaml-support
Add support for Pip's extra dependencies in YAML config.
2 parents 8f4c031 + b94ec44 commit ef2d919

File tree

3 files changed

+52
-0
lines changed

3 files changed

+52
-0
lines changed

readthedocs_build/config/config.py

+18
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from .validation import validate_choice
1010
from .validation import validate_directory
1111
from .validation import validate_file
12+
from .validation import validate_string
1213
from .validation import ValidationError
1314

1415

@@ -74,6 +75,8 @@ class BuildConfig(dict):
7475
TYPE_REQUIRED_MESSAGE = 'Missing key "type"'
7576
CONF_FILE_REQUIRED_MESSAGE = 'Missing key "conf_file"'
7677
PYTHON_INVALID_MESSAGE = '"python" section must be a mapping.'
78+
PYTHON_EXTRA_REQUIREMENTS_INVALID_MESSAGE = (
79+
'"python.extra_requirements" section must be a list.')
7780

7881
def __init__(self, env_config, raw_config, source_file, source_position):
7982
self.env_config = env_config
@@ -205,6 +208,7 @@ def validate_python(self):
205208
python = {
206209
'use_system_site_packages': False,
207210
'pip_install': False,
211+
'extra_requirements': [],
208212
'setup_py_install': False,
209213
'setup_py_path': os.path.join(
210214
os.path.dirname(self.source_file),
@@ -233,6 +237,20 @@ def validate_python(self):
233237
python['pip_install'] = validate_bool(
234238
raw_python['pip_install'])
235239

240+
# Validate extra_requirements.
241+
if 'extra_requirements' in raw_python:
242+
raw_extra_requirements = raw_python['extra_requirements']
243+
if not isinstance(raw_extra_requirements, list):
244+
self.error(
245+
'python.extra_requirements',
246+
self.PYTHON_EXTRA_REQUIREMENTS_INVALID_MESSAGE,
247+
code=PYTHON_INVALID)
248+
for extra_name in raw_extra_requirements:
249+
with self.catch_validation_error(
250+
'python.extra_requirements'):
251+
python['extra_requirements'].append(
252+
validate_string(extra_name))
253+
236254
# Validate setup_py_install.
237255
if 'setup_py_install' in raw_python:
238256
with self.catch_validation_error('python.setup_py_install'):

readthedocs_build/config/test_config.py

+25
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,31 @@ def test_python_pip_install_default():
179179
assert build['python']['pip_install'] is False
180180

181181

182+
def describe_validate_python_extra_requirements():
183+
184+
def it_defaults_to_list():
185+
build = get_build_config({'python': {}})
186+
build.validate_python()
187+
# Default is an empty list.
188+
assert build['python']['extra_requirements'] == []
189+
190+
def it_validates_is_a_list():
191+
build = get_build_config(
192+
{'python': {'extra_requirements': 'invalid'}})
193+
with raises(InvalidConfig) as excinfo:
194+
build.validate_python()
195+
assert excinfo.value.key == 'python.extra_requirements'
196+
assert excinfo.value.code == PYTHON_INVALID
197+
198+
@patch('readthedocs_build.config.config.validate_string')
199+
def it_uses_validate_string(validate_string):
200+
validate_string.return_value = True
201+
build = get_build_config(
202+
{'python': {'extra_requirements': ['tests']}})
203+
build.validate_python()
204+
validate_string.assert_any_call('tests')
205+
206+
182207
def describe_validate_use_system_site_packages():
183208
def it_defaults_to_false():
184209
build = get_build_config({'python': {}})

spec.rst

+9
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,11 @@ Following mapping keys are supported (all but the marked once are optional):
136136
path/to/requirements.txt``. Accepts version modifiers like
137137
``setuptools>=18.0``.
138138

139+
``extra_requirements``
140+
A list of `extra requirements`_ sections to install, additionnaly to
141+
the `package default dependencies`_. Ignored if the ``setup_install``
142+
option below is ``true``.
143+
139144
``setup_install``
140145
If ``true``, then ``python setup.py install`` will be executed before
141146
building the docs.
@@ -146,3 +151,7 @@ Following mapping keys are supported (all but the marked once are optional):
146151

147152
``language``
148153
The language the doc is written in. Defaults to empty string.
154+
155+
156+
.. _extra requirements: http://setuptools.readthedocs.io/en/latest/setuptools.html#declaring-extras-optional-features-with-their-own-dependencies
157+
.. _package default dependencies: http://setuptools.readthedocs.io/en/latest/setuptools.html#declaring-dependencies

0 commit comments

Comments
 (0)