Skip to content

Make raw_config private #6199

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

Merged
merged 1 commit into from
Oct 7, 2019
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
50 changes: 25 additions & 25 deletions readthedocs/config/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ class BuildConfigBase:

def __init__(self, env_config, raw_config, source_file):
self.env_config = env_config
self.raw_config = copy.deepcopy(raw_config)
self._raw_config = copy.deepcopy(raw_config)
self.source_file = source_file
if os.path.isdir(self.source_file):
self.base_path = self.source_file
Expand Down Expand Up @@ -224,13 +224,13 @@ def pop(self, name, container, default, raise_ex):

def pop_config(self, key, default=None, raise_ex=False):
"""
Search and pop a key (recursively) from `self.raw_config`.
Search and pop a key (recursively) from `self._raw_config`.

:param key: the key name in a dotted form (``key.innerkey``)
:param default: Optionally, it can receive a default value
:param raise_ex: If True, raises an exception when the key is not found
"""
return self.pop(key.split('.'), self.raw_config, default, raise_ex)
return self.pop(key.split('.'), self._raw_config, default, raise_ex)

def validate(self):
raise NotImplementedError()
Expand Down Expand Up @@ -382,8 +382,8 @@ def validate_build(self):
build = {'image': settings.DOCKER_IMAGE}

# User specified
if 'build' in self.raw_config:
_build = self.raw_config['build']
if 'build' in self._raw_config:
_build = self._raw_config['build']
if 'image' in _build:
with self.catch_validation_error('build'):
build['image'] = validate_choice(
Expand Down Expand Up @@ -419,8 +419,8 @@ def validate_python(self):
'version': version,
}

if 'python' in self.raw_config:
raw_python = self.raw_config['python']
if 'python' in self._raw_config:
raw_python = self._raw_config['python']
if not isinstance(raw_python, dict):
self.error(
'python',
Expand Down Expand Up @@ -491,8 +491,8 @@ def validate_conda(self):
"""Validates the ``conda`` key."""
conda = {}

if 'conda' in self.raw_config:
raw_conda = self.raw_config['conda']
if 'conda' in self._raw_config:
raw_conda = self._raw_config['conda']
with self.catch_validation_error('conda'):
validate_dict(raw_conda)
with self.catch_validation_error('conda.file'):
Expand All @@ -508,10 +508,10 @@ def validate_conda(self):

def validate_requirements_file(self):
"""Validates that the requirements file exists."""
if 'requirements_file' not in self.raw_config:
if 'requirements_file' not in self._raw_config:
requirements_file = self.defaults.get('requirements_file')
else:
requirements_file = self.raw_config['requirements_file']
requirements_file = self._raw_config['requirements_file']
if not requirements_file:
return None
with self.catch_validation_error('requirements_file'):
Expand All @@ -523,7 +523,7 @@ def validate_requirements_file(self):

def validate_formats(self):
"""Validates that formats contains only valid formats."""
formats = self.raw_config.get('formats')
formats = self._raw_config.get('formats')
if formats is None:
return self.defaults.get('formats', [])
if formats == ['none']:
Expand Down Expand Up @@ -674,7 +674,7 @@ def validate_formats(self):

def validate_conda(self):
"""Validates the conda key."""
raw_conda = self.raw_config.get('conda')
raw_conda = self._raw_config.get('conda')
if raw_conda is None:
return None

Expand All @@ -693,7 +693,7 @@ def validate_build(self):

It prioritizes the value from the default image if exists.
"""
raw_build = self.raw_config.get('build', {})
raw_build = self._raw_config.get('build', {})
with self.catch_validation_error('build'):
validate_dict(raw_build)
build = {}
Expand Down Expand Up @@ -729,7 +729,7 @@ def validate_python(self):
- ``version`` can be a string or number type.
- ``extra_requirements`` needs to be used with ``install: 'pip'``.
"""
raw_python = self.raw_config.get('python', {})
raw_python = self._raw_config.get('python', {})
with self.catch_validation_error('python'):
validate_dict(raw_python)

Expand All @@ -750,17 +750,17 @@ def validate_python(self):
)

with self.catch_validation_error('python.install'):
raw_install = self.raw_config.get('python', {}).get('install', [])
raw_install = self._raw_config.get('python', {}).get('install', [])
validate_list(raw_install)
if raw_install:
# Transform to a dict, so it's easy to validate extra keys.
self.raw_config.setdefault('python', {})['install'] = (
self._raw_config.setdefault('python', {})['install'] = (
list_to_dict(raw_install)
)
else:
self.pop_config('python.install')

raw_install = self.raw_config.get('python', {}).get('install', [])
raw_install = self._raw_config.get('python', {}).get('install', [])
python['install'] = [
self.validate_python_install(index)
for index in range(len(raw_install))
Expand All @@ -783,7 +783,7 @@ def validate_python_install(self, index):
"""Validates the python.install.{index} key."""
python_install = {}
key = 'python.install.{}'.format(index)
raw_install = self.raw_config['python']['install'][str(index)]
raw_install = self._raw_config['python']['install'][str(index)]
with self.catch_validation_error(key):
validate_dict(raw_install)

Expand Down Expand Up @@ -850,7 +850,7 @@ def validate_doc_types(self):
avoid innecessary validations.
"""
with self.catch_validation_error('.'):
if 'sphinx' in self.raw_config and 'mkdocs' in self.raw_config:
if 'sphinx' in self._raw_config and 'mkdocs' in self._raw_config:
self.error(
'.',
'You can not have the ``sphinx`` and ``mkdocs`` '
Expand All @@ -864,7 +864,7 @@ def validate_mkdocs(self):

It makes sure we are using an existing configuration file.
"""
raw_mkdocs = self.raw_config.get('mkdocs')
raw_mkdocs = self._raw_config.get('mkdocs')
if raw_mkdocs is None:
return None

Expand Down Expand Up @@ -894,7 +894,7 @@ def validate_sphinx(self):
It should be called after ``validate_mkdocs``. That way
we can default to sphinx if ``mkdocs`` is not given.
"""
raw_sphinx = self.raw_config.get('sphinx')
raw_sphinx = self._raw_config.get('sphinx')
if raw_sphinx is None:
if self.mkdocs is None:
raw_sphinx = {}
Expand Down Expand Up @@ -961,7 +961,7 @@ def validate_submodules(self):
- We can use the ``ALL`` keyword in include or exlude.
- We can't exlude and include submodules at the same time.
"""
raw_submodules = self.raw_config.get('submodules', {})
raw_submodules = self._raw_config.get('submodules', {})
with self.catch_validation_error('submodules'):
validate_dict(raw_submodules)

Expand Down Expand Up @@ -1009,7 +1009,7 @@ def validate_keys(self):
Checks that we don't have extra keys (invalid ones).

This should be called after all the validations are done and all keys
are popped from `self.raw_config`.
are popped from `self._raw_config`.
"""
msg = (
'Invalid configuration option: {}. '
Expand All @@ -1018,7 +1018,7 @@ def validate_keys(self):
# The version key isn't popped, but it's
# validated in `load`.
self.pop_config('version', None)
wrong_key = '.'.join(self._get_extra_key(self.raw_config))
wrong_key = '.'.join(self._get_extra_key(self._raw_config))
if wrong_key:
self.error(
wrong_key,
Expand Down
12 changes: 6 additions & 6 deletions readthedocs/config/tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -1870,7 +1870,7 @@ def test_strict_validation_pops_all_keys(self):
},
})
build.validate()
assert build.raw_config == {}
assert build._raw_config == {}

@pytest.mark.parametrize(
'value,expected', [
Expand All @@ -1888,27 +1888,27 @@ def test_get_extra_key(self, value, expected):
def test_pop_config_single(self):
build = self.get_build_config({'one': 1})
build.pop_config('one')
assert build.raw_config == {}
assert build._raw_config == {}

def test_pop_config_nested(self):
build = self.get_build_config({'one': {'two': 2}})
build.pop_config('one.two')
assert build.raw_config == {}
assert build._raw_config == {}

def test_pop_config_nested_with_residue(self):
build = self.get_build_config({'one': {'two': 2, 'three': 3}})
build.pop_config('one.two')
assert build.raw_config == {'one': {'three': 3}}
assert build._raw_config == {'one': {'three': 3}}

def test_pop_config_default_none(self):
build = self.get_build_config({'one': {'two': 2, 'three': 3}})
assert build.pop_config('one.four') is None
assert build.raw_config == {'one': {'two': 2, 'three': 3}}
assert build._raw_config == {'one': {'two': 2, 'three': 3}}

def test_pop_config_default(self):
build = self.get_build_config({'one': {'two': 2, 'three': 3}})
assert build.pop_config('one.four', 4) == 4
assert build.raw_config == {'one': {'two': 2, 'three': 3}}
assert build._raw_config == {'one': {'two': 2, 'three': 3}}

def test_pop_config_raise_exception(self):
build = self.get_build_config({'one': {'two': 2, 'three': 3}})
Expand Down