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

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

Merged
merged 1 commit into from
Aug 19, 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
18 changes: 18 additions & 0 deletions readthedocs_build/config/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from .validation import validate_choice
from .validation import validate_directory
from .validation import validate_file
from .validation import validate_string
from .validation import ValidationError


Expand Down Expand Up @@ -74,6 +75,8 @@ class BuildConfig(dict):
TYPE_REQUIRED_MESSAGE = 'Missing key "type"'
CONF_FILE_REQUIRED_MESSAGE = 'Missing key "conf_file"'
PYTHON_INVALID_MESSAGE = '"python" section must be a mapping.'
PYTHON_EXTRA_REQUIREMENTS_INVALID_MESSAGE = (
'"python.extra_requirements" section must be a list.')

def __init__(self, env_config, raw_config, source_file, source_position):
self.env_config = env_config
Expand Down Expand Up @@ -205,6 +208,7 @@ def validate_python(self):
python = {
'use_system_site_packages': False,
'pip_install': False,
'extra_requirements': [],
'setup_py_install': False,
'setup_py_path': os.path.join(
os.path.dirname(self.source_file),
Expand Down Expand Up @@ -233,6 +237,20 @@ def validate_python(self):
python['pip_install'] = validate_bool(
raw_python['pip_install'])

# Validate extra_requirements.
if 'extra_requirements' in raw_python:
raw_extra_requirements = raw_python['extra_requirements']
if not isinstance(raw_extra_requirements, list):
self.error(
'python.extra_requirements',
self.PYTHON_EXTRA_REQUIREMENTS_INVALID_MESSAGE,
code=PYTHON_INVALID)
for extra_name in raw_extra_requirements:
with self.catch_validation_error(
'python.extra_requirements'):
python['extra_requirements'].append(
validate_string(extra_name))

# Validate setup_py_install.
if 'setup_py_install' in raw_python:
with self.catch_validation_error('python.setup_py_install'):
Expand Down
25 changes: 25 additions & 0 deletions readthedocs_build/config/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,31 @@ def test_python_pip_install_default():
assert build['python']['pip_install'] is False


def describe_validate_python_extra_requirements():

def it_defaults_to_list():
build = get_build_config({'python': {}})
build.validate_python()
# Default is an empty list.
assert build['python']['extra_requirements'] == []

def it_validates_is_a_list():
build = get_build_config(
{'python': {'extra_requirements': 'invalid'}})
with raises(InvalidConfig) as excinfo:
build.validate_python()
assert excinfo.value.key == 'python.extra_requirements'
assert excinfo.value.code == PYTHON_INVALID

@patch('readthedocs_build.config.config.validate_string')
def it_uses_validate_string(validate_string):
validate_string.return_value = True
build = get_build_config(
{'python': {'extra_requirements': ['tests']}})
build.validate_python()
validate_string.assert_any_call('tests')


def describe_validate_use_system_site_packages():
def it_defaults_to_false():
build = get_build_config({'python': {}})
Expand Down
9 changes: 9 additions & 0 deletions spec.rst
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,11 @@ Following mapping keys are supported (all but the marked once are optional):
path/to/requirements.txt``. Accepts version modifiers like
``setuptools>=18.0``.

``extra_requirements``
A list of `extra requirements`_ sections to install, additionnaly to
the `package default dependencies`_. Ignored if the ``setup_install``
option below is ``true``.

``setup_install``
If ``true``, then ``python setup.py install`` will be executed before
building the docs.
Expand All @@ -146,3 +151,7 @@ Following mapping keys are supported (all but the marked once are optional):

``language``
The language the doc is written in. Defaults to empty string.


.. _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