Skip to content

Commit b242e9d

Browse files
stsewdagjohnson
authored andcommitted
Match v1 config interface to new one (#4456)
* Add integratio tests for config file v2 * Complete tests for python * Change external keys to python scope v1 * Fix tests * Adapt tests from v1 * Skip new tests * Refactor code to use new python options * Refactor conda option from v1 * Use new conda option in tests * Linter * Use new configurations * Add doctype to v1 & move models * Use build model in v1 * Use new key for build.image * Stop skipping tests * Test empty requirements * Linter * Use new settings * Add tests for sphinx * Add tests for mkdocs * Pass config object to builders * Revert "Pass config object to builders" This reverts commit 5b37760. * Skip new tests * Style * Fix test * One more test for v2 * Test conf.py default value * Better check for conda
1 parent 6b8ecd8 commit b242e9d

File tree

8 files changed

+760
-226
lines changed

8 files changed

+760
-226
lines changed

readthedocs/config/config.py

+31-94
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77

88
import os
99
import re
10-
from collections import namedtuple
1110
from contextlib import contextmanager
1211

1312
import six
1413

1514
from .find import find_one
15+
from .models import Build, Conda, Mkdocs, Python, Sphinx, Submodules
1616
from .parser import ParseError, parse
1717
from .validation import (
1818
ValidationError, validate_bool, validate_choice, validate_dict,
@@ -177,7 +177,7 @@ def python_interpreter(self):
177177

178178
@property
179179
def python_full_version(self):
180-
ver = self.python_version
180+
ver = self.python.version
181181
if ver in [2, 3]:
182182
# Get the highest version of the major series version if user only
183183
# gave us a version of '2', or '3'
@@ -361,12 +361,9 @@ def validate_python(self):
361361
version = self.defaults.get('python_version', 2)
362362
python = {
363363
'use_system_site_packages': use_system_packages,
364-
'pip_install': False,
364+
'install_with_pip': False,
365365
'extra_requirements': [],
366-
'setup_py_install': install_project,
367-
'setup_py_path': os.path.join(
368-
os.path.dirname(self.source_file),
369-
'setup.py'),
366+
'install_with_setup': install_project,
370367
'version': version,
371368
}
372369

@@ -388,7 +385,7 @@ def validate_python(self):
388385
# Validate pip_install.
389386
if 'pip_install' in raw_python:
390387
with self.catch_validation_error('python.pip_install'):
391-
python['pip_install'] = validate_bool(
388+
python['install_with_pip'] = validate_bool(
392389
raw_python['pip_install'])
393390

394391
# Validate extra_requirements.
@@ -399,26 +396,22 @@ def validate_python(self):
399396
'python.extra_requirements',
400397
self.PYTHON_EXTRA_REQUIREMENTS_INVALID_MESSAGE,
401398
code=PYTHON_INVALID)
402-
for extra_name in raw_extra_requirements:
403-
with self.catch_validation_error(
404-
'python.extra_requirements'):
405-
python['extra_requirements'].append(
406-
validate_string(extra_name)
407-
)
399+
if not python['install_with_pip']:
400+
python['extra_requirements'] = []
401+
else:
402+
for extra_name in raw_extra_requirements:
403+
with self.catch_validation_error(
404+
'python.extra_requirements'):
405+
python['extra_requirements'].append(
406+
validate_string(extra_name)
407+
)
408408

409409
# Validate setup_py_install.
410410
if 'setup_py_install' in raw_python:
411411
with self.catch_validation_error('python.setup_py_install'):
412-
python['setup_py_install'] = validate_bool(
412+
python['install_with_setup'] = validate_bool(
413413
raw_python['setup_py_install'])
414414

415-
# Validate setup_py_path.
416-
if 'setup_py_path' in raw_python:
417-
with self.catch_validation_error('python.setup_py_path'):
418-
base_path = os.path.dirname(self.source_file)
419-
python['setup_py_path'] = validate_file(
420-
raw_python['setup_py_path'], base_path)
421-
422415
if 'version' in raw_python:
423416
with self.catch_validation_error('python.version'):
424417
# Try to convert strings to an int first, to catch '2', then
@@ -451,11 +444,14 @@ def validate_conda(self):
451444
self.PYTHON_INVALID_MESSAGE,
452445
code=PYTHON_INVALID)
453446

447+
conda_environment = None
454448
if 'file' in raw_conda:
455449
with self.catch_validation_error('conda.file'):
456450
base_path = os.path.dirname(self.source_file)
457-
conda['file'] = validate_file(
458-
raw_conda['file'], base_path)
451+
conda_environment = validate_file(
452+
raw_conda['file'], base_path
453+
)
454+
conda['environment'] = conda_environment
459455

460456
return conda
461457
return None
@@ -511,58 +507,24 @@ def formats(self):
511507
@property
512508
def python(self):
513509
"""Python related configuration."""
514-
return self._config.get('python', {})
515-
516-
@property
517-
def python_version(self):
518-
"""Python version."""
519-
return self._config['python']['version']
520-
521-
@property
522-
def pip_install(self):
523-
"""True if the project should be installed using pip."""
524-
return self._config['python']['pip_install']
525-
526-
@property
527-
def install_project(self):
528-
"""True if the project should be installed."""
529-
if self.pip_install:
530-
return True
531-
return self._config['python']['setup_py_install']
532-
533-
@property
534-
def extra_requirements(self):
535-
"""Extra requirements to be installed with pip."""
536-
if self.pip_install:
537-
return self._config['python']['extra_requirements']
538-
return []
539-
540-
@property
541-
def use_system_site_packages(self):
542-
"""True if the project should have access to the system packages."""
543-
return self._config['python']['use_system_site_packages']
544-
545-
@property
546-
def use_conda(self):
547-
"""True if the project use Conda."""
548-
return self._config.get('conda') is not None
510+
requirements = self._config['requirements_file']
511+
self._config['python']['requirements'] = requirements
512+
return Python(**self._config['python'])
549513

550514
@property
551-
def conda_file(self):
552-
"""The Conda environment file."""
553-
if self.use_conda:
554-
return self._config['conda'].get('file')
515+
def conda(self):
516+
if self._config['conda'] is not None:
517+
return Conda(**self._config['conda'])
555518
return None
556519

557520
@property
558-
def requirements_file(self):
559-
"""The project requirements file."""
560-
return self._config['requirements_file']
521+
def build(self):
522+
"""The docker image used by the builders."""
523+
return Build(**self._config['build'])
561524

562525
@property
563-
def build_image(self):
564-
"""The docker image used by the builders."""
565-
return self._config['build']['image']
526+
def doctype(self):
527+
return self.defaults['doctype']
566528

567529

568530
class BuildConfigV2(BuildConfigBase):
@@ -888,47 +850,26 @@ def formats(self):
888850

889851
@property
890852
def conda(self):
891-
Conda = namedtuple('Conda', ['environment']) # noqa
892853
if self._config['conda']:
893854
return Conda(**self._config['conda'])
894855
return None
895856

896857
@property
897858
def build(self):
898-
Build = namedtuple('Build', ['image']) # noqa
899859
return Build(**self._config['build'])
900860

901861
@property
902862
def python(self):
903-
Python = namedtuple( # noqa
904-
'Python',
905-
[
906-
'version',
907-
'requirements',
908-
'install_with_pip',
909-
'install_with_setup',
910-
'extra_requirements',
911-
'use_system_site_packages',
912-
],
913-
)
914863
return Python(**self._config['python'])
915864

916865
@property
917866
def sphinx(self):
918-
Sphinx = namedtuple( # noqa
919-
'Sphinx',
920-
['builder', 'configuration', 'fail_on_warning'],
921-
)
922867
if self._config['sphinx']:
923868
return Sphinx(**self._config['sphinx'])
924869
return None
925870

926871
@property
927872
def mkdocs(self):
928-
Mkdocs = namedtuple( # noqa
929-
'Mkdocs',
930-
['configuration', 'fail_on_warning'],
931-
)
932873
if self._config['mkdocs']:
933874
return Mkdocs(**self._config['mkdocs'])
934875
return None
@@ -941,10 +882,6 @@ def doctype(self):
941882

942883
@property
943884
def submodules(self):
944-
Submodules = namedtuple( # noqa
945-
'Submodules',
946-
['include', 'exclude', 'recursive'],
947-
)
948885
return Submodules(**self._config['submodules'])
949886

950887

readthedocs/config/models.py

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
"""Models for the response of the configuration object."""
2+
3+
from __future__ import division, print_function, unicode_literals
4+
5+
from collections import namedtuple
6+
7+
8+
Build = namedtuple('Build', ['image']) # noqa
9+
10+
Python = namedtuple( # noqa
11+
'Python',
12+
[
13+
'version',
14+
'requirements',
15+
'install_with_pip',
16+
'install_with_setup',
17+
'extra_requirements',
18+
'use_system_site_packages',
19+
],
20+
)
21+
22+
Conda = namedtuple('Conda', ['environment']) # noqa
23+
24+
Sphinx = namedtuple( # noqa
25+
'Sphinx',
26+
['builder', 'configuration', 'fail_on_warning'],
27+
)
28+
29+
Mkdocs = namedtuple( # noqa
30+
'Mkdocs',
31+
['configuration', 'fail_on_warning'],
32+
)
33+
34+
Submodules = namedtuple( # noqa
35+
'Submodules',
36+
['include', 'exclude', 'recursive'],
37+
)

0 commit comments

Comments
 (0)