-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
Add schema for configuration file with yamale #4084
Changes from 4 commits
c5aa08a
f38259d
4c02207
a63d39e
7fc52b9
ab7d8fa
602fcd4
b6dd2a2
584ce5e
e4f5a3a
cd5b5dc
07350b9
00e69d9
f4ddb42
89badbf
7b30c8c
e038046
b2e5dbc
40c35a2
ace5f8e
25e962d
1c3a2fa
b63b016
18a6485
dc60f11
79ebf87
6286a34
31fc800
84d1326
9ccd94b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,6 +28,7 @@ submodules: include('submodules', required=False) | |
# Redirects for the current version to be built | ||
# Key/value list, represent redirects of type `type` | ||
# from url -> to url | ||
# Default: null | ||
redirects: map(enum('page'), map(str(), str()), required=False) | ||
|
||
--- | ||
|
@@ -47,9 +48,11 @@ python: | |
version: enum('2', '2.7', '3', '3.5', '3.6', required=False) | ||
|
||
# The path to the requirements file from the root of the project | ||
# Default: null | ||
requirements: path(required=False) | ||
|
||
# Install the project using python setup.py install or pip | ||
# Default: null | ||
install: enum('pip', 'setup.py', required=False) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the first breaking change :), I think is more simple to do this, instead of having a boolean field for each There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, the |
||
|
||
# Extra requirements sections to install in addition to the package dependencies | ||
|
@@ -60,13 +63,24 @@ python: | |
# Default: false | ||
system_packages: bool(required=False) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wasn't 100% sure if this should belong in the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I mostly want this option to go away, but I don't know if we can do it quite yet. I think it can go in |
||
|
||
sphinx: | ||
sphinx: | ||
# The path to the conf.py file | ||
# Default: rtd will try to find it | ||
configuration: path(required=False) | ||
|
||
# Add the -W option to sphinx-build | ||
# Default: false | ||
fail_on_warning: bool(required=False) | ||
|
||
mkdocs: | ||
# Something | ||
# The path to the mkdocs.yml file | ||
# Default: rtd will try to find it | ||
configuration: path(required=False) | ||
|
||
# Add the --strict optio to mkdocs build | ||
# Default: false | ||
fail_on_warning: bool(required=False) | ||
|
||
|
||
submodules: | ||
# List of submodules to be included | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,19 +2,20 @@ | |
|
||
import pytest | ||
from readthedocs.rtdyml import BuildConfig | ||
from readthedocs.rtd_tests.utils import apply_fs | ||
from readthedocs_build.testing import utils | ||
|
||
|
||
def create_yaml(tmpdir, content): | ||
fs = { | ||
'environment.yml': '', | ||
'mkdocs.yml': '', | ||
'rtd.yml': content, | ||
'docs': { | ||
'conf.py': '', | ||
'requirements.txt': '', | ||
}, | ||
} | ||
apply_fs(tmpdir, fs) | ||
utils.apply_fs(tmpdir, fs) | ||
return path.join(tmpdir.strpath, 'rtd.yml') | ||
|
||
|
||
|
@@ -192,7 +193,7 @@ def test_python_version_invalid(tmpdir): | |
) | ||
|
||
|
||
def test_no_python_version(tmpdir): | ||
def test_python_version_no_key(tmpdir): | ||
content = ''' | ||
version: "2" | ||
python: | ||
|
@@ -201,7 +202,7 @@ def test_no_python_version(tmpdir): | |
assertValidConfig(tmpdir, content) | ||
|
||
|
||
def test_valid_requirements(tmpdir): | ||
def test_python_requirements(tmpdir): | ||
content = ''' | ||
version: "2" | ||
python: | ||
|
@@ -210,7 +211,7 @@ def test_valid_requirements(tmpdir): | |
assertValidConfig(tmpdir, content) | ||
|
||
|
||
def test_invalid_requirements_file(tmpdir): | ||
def test_python_requirements_invalid(tmpdir): | ||
content = ''' | ||
version: "2" | ||
python: | ||
|
@@ -223,6 +224,15 @@ def test_invalid_requirements_file(tmpdir): | |
) | ||
|
||
|
||
def test_python_requirements_null(tmpdir): | ||
content = ''' | ||
version: "2" | ||
python: | ||
requirements: null | ||
''' | ||
assertValidConfig(tmpdir, content) | ||
|
||
|
||
@pytest.mark.parametrize('value', ['pip', 'setup.py']) | ||
def test_python_install(tmpdir, value): | ||
content = ''' | ||
|
@@ -247,6 +257,15 @@ def test_python_install_invalid(tmpdir): | |
) | ||
|
||
|
||
def test_python_install_null(tmpdir): | ||
content = ''' | ||
version: "2" | ||
python: | ||
install: null | ||
''' | ||
assertValidConfig(tmpdir, content) | ||
|
||
|
||
def test_python_extra_requirements(tmpdir): | ||
content = ''' | ||
version: "2" | ||
|
@@ -273,6 +292,16 @@ def test_python_extra_requirements_invalid(tmpdir): | |
) | ||
|
||
|
||
@pytest.mark.parametrize('value', ['', 'null', '[]']) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, yes! |
||
def test_python_extra_requirements_empty(tmpdir, value): | ||
content = ''' | ||
version: "2" | ||
python: | ||
extra_requirements: {value} | ||
''' | ||
assertValidConfig(tmpdir, content.format(value=value)) | ||
|
||
|
||
@pytest.mark.parametrize('value', ['true', 'false']) | ||
def test_python_system_packages(tmpdir, value): | ||
content = ''' | ||
|
@@ -300,6 +329,15 @@ def test_python_system_packages_invalid(tmpdir, value): | |
def test_sphinx(tmpdir): | ||
content = ''' | ||
version: "2" | ||
sphinx: | ||
configuration: docs/conf.py | ||
''' | ||
assertValidConfig(tmpdir, content) | ||
|
||
|
||
def test_sphinx_default_value(tmpdir): | ||
content = ''' | ||
version: "2" | ||
sphinx: | ||
file: docs/conf.py # Default value for configuration key | ||
''' | ||
|
@@ -320,6 +358,84 @@ def test_sphinx_invalid(tmpdir, value): | |
) | ||
|
||
|
||
def test_sphinx_fail_on_warning(tmpdir): | ||
content = ''' | ||
version: "2" | ||
sphinx: | ||
fail_on_warning: true | ||
''' | ||
assertValidConfig(tmpdir, content) | ||
|
||
|
||
@pytest.mark.parametrize('value', ['not true', "''", '[]']) | ||
def test_sphinx_fail_on_warning_invalid(tmpdir, value): | ||
content = ''' | ||
version: "2" | ||
sphinx: | ||
fail_on_warning: {value} | ||
''' | ||
assertInvalidConfig( | ||
tmpdir, | ||
content.format(value=value), | ||
['is not a bool'] | ||
) | ||
|
||
|
||
def test_mkdocs(tmpdir): | ||
content = ''' | ||
version: "2" | ||
mkdocs: | ||
configuration: mkdocs.yml | ||
''' | ||
assertValidConfig(tmpdir, content) | ||
|
||
|
||
def test_mkdocs_default_value(tmpdir): | ||
content = ''' | ||
version: "2" | ||
mkdocs: | ||
file: mkdocs.yml # Default value for configuration key | ||
''' | ||
assertValidConfig(tmpdir, content) | ||
|
||
|
||
@pytest.mark.parametrize('value', ['2', 'environment.py']) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why it does fail with (there are other places where I have the same question --for example, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It fails because it doesn't exist in the current file system (there is only an There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Got it. Two things here:
(note that in 2 I used what I proposed in 1 and it's very clear) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I go a little crazy with the names on tests p: I'm not sure how to validate a valid path without doing it in a hacky way or a complicated regex, not sure if it's worth it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We probably don't want to validate that the file exists on the schema, since any path is valid for schema but we want to validate that the file exists when using the YAML file to build the docs. As @ericholscher said in another comment, we may want to have these validations at different places/steps. (although, my suggestion about the names of the invalid options/files/etc is still valid and I think you should follow it :) ) |
||
def test_mkdocs_invalid(tmpdir, value): | ||
content = ''' | ||
version: "2" | ||
mkdocs: | ||
configuration: {value} | ||
''' | ||
assertInvalidConfig( | ||
tmpdir, | ||
content, | ||
['is not a path'] | ||
) | ||
|
||
|
||
def test_mkdocs_fail_on_warning(tmpdir): | ||
content = ''' | ||
version: "2" | ||
mkdocs: | ||
fail_on_warning: true | ||
''' | ||
assertValidConfig(tmpdir, content) | ||
|
||
|
||
@pytest.mark.parametrize('value', ['not true', "''", '[]']) | ||
def test_mkdocs_fail_on_warning_invalid(tmpdir, value): | ||
content = ''' | ||
version: "2" | ||
mkdocs: | ||
fail_on_warning: {value} | ||
''' | ||
assertInvalidConfig( | ||
tmpdir, | ||
content.format(value=value), | ||
['is not a bool'] | ||
) | ||
|
||
|
||
def test_submodules_include(tmpdir): | ||
content = ''' | ||
version: "2" | ||
|
@@ -374,7 +490,7 @@ def test_redirects(tmpdir): | |
assertValidConfig(tmpdir, content) | ||
|
||
|
||
def test_invalid_redirects(tmpdir): | ||
def test_redirects_invalid(tmpdir): | ||
content = ''' | ||
version: "2" | ||
redirects: | ||
|
@@ -386,3 +502,12 @@ def test_invalid_redirects(tmpdir): | |
content, | ||
['is not a str'] | ||
) | ||
|
||
|
||
@pytest.mark.parametrize('value', ['', 'null', '{}']) | ||
def test_redirects_empty(tmpdir, value): | ||
content = ''' | ||
version: "2" | ||
redirects: {value} | ||
''' | ||
assertValidConfig(tmpdir, content.format(value=value)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure what to do here. This is dependent on the docker image. Our current
latest
image (our default image will soon belatest
) has2.7
,3.3
,3.4
,3.5
, and3.6
. The4.0
image has2.7
,3.5
,3.6
, and should probably have3.7
soon.I think verifying the python version list is a config parsing level validation, we don't necessarily need to worry about validating across fields as part of this exercise. Perhaps here, for our spec discussion, we just put all possible python versions?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd say yes