Skip to content

Commit 3492617

Browse files
authored
Merge pull request #6199 from saadmk11/raw_config_private
Make raw_config private
2 parents eb97d57 + 936f1c2 commit 3492617

File tree

2 files changed

+31
-31
lines changed

2 files changed

+31
-31
lines changed

readthedocs/config/config.py

+25-25
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ class BuildConfigBase:
157157

158158
def __init__(self, env_config, raw_config, source_file):
159159
self.env_config = env_config
160-
self.raw_config = copy.deepcopy(raw_config)
160+
self._raw_config = copy.deepcopy(raw_config)
161161
self.source_file = source_file
162162
if os.path.isdir(self.source_file):
163163
self.base_path = self.source_file
@@ -224,13 +224,13 @@ def pop(self, name, container, default, raise_ex):
224224

225225
def pop_config(self, key, default=None, raise_ex=False):
226226
"""
227-
Search and pop a key (recursively) from `self.raw_config`.
227+
Search and pop a key (recursively) from `self._raw_config`.
228228
229229
:param key: the key name in a dotted form (``key.innerkey``)
230230
:param default: Optionally, it can receive a default value
231231
:param raise_ex: If True, raises an exception when the key is not found
232232
"""
233-
return self.pop(key.split('.'), self.raw_config, default, raise_ex)
233+
return self.pop(key.split('.'), self._raw_config, default, raise_ex)
234234

235235
def validate(self):
236236
raise NotImplementedError()
@@ -382,8 +382,8 @@ def validate_build(self):
382382
build = {'image': settings.DOCKER_IMAGE}
383383

384384
# User specified
385-
if 'build' in self.raw_config:
386-
_build = self.raw_config['build']
385+
if 'build' in self._raw_config:
386+
_build = self._raw_config['build']
387387
if 'image' in _build:
388388
with self.catch_validation_error('build'):
389389
build['image'] = validate_choice(
@@ -419,8 +419,8 @@ def validate_python(self):
419419
'version': version,
420420
}
421421

422-
if 'python' in self.raw_config:
423-
raw_python = self.raw_config['python']
422+
if 'python' in self._raw_config:
423+
raw_python = self._raw_config['python']
424424
if not isinstance(raw_python, dict):
425425
self.error(
426426
'python',
@@ -491,8 +491,8 @@ def validate_conda(self):
491491
"""Validates the ``conda`` key."""
492492
conda = {}
493493

494-
if 'conda' in self.raw_config:
495-
raw_conda = self.raw_config['conda']
494+
if 'conda' in self._raw_config:
495+
raw_conda = self._raw_config['conda']
496496
with self.catch_validation_error('conda'):
497497
validate_dict(raw_conda)
498498
with self.catch_validation_error('conda.file'):
@@ -508,10 +508,10 @@ def validate_conda(self):
508508

509509
def validate_requirements_file(self):
510510
"""Validates that the requirements file exists."""
511-
if 'requirements_file' not in self.raw_config:
511+
if 'requirements_file' not in self._raw_config:
512512
requirements_file = self.defaults.get('requirements_file')
513513
else:
514-
requirements_file = self.raw_config['requirements_file']
514+
requirements_file = self._raw_config['requirements_file']
515515
if not requirements_file:
516516
return None
517517
with self.catch_validation_error('requirements_file'):
@@ -523,7 +523,7 @@ def validate_requirements_file(self):
523523

524524
def validate_formats(self):
525525
"""Validates that formats contains only valid formats."""
526-
formats = self.raw_config.get('formats')
526+
formats = self._raw_config.get('formats')
527527
if formats is None:
528528
return self.defaults.get('formats', [])
529529
if formats == ['none']:
@@ -674,7 +674,7 @@ def validate_formats(self):
674674

675675
def validate_conda(self):
676676
"""Validates the conda key."""
677-
raw_conda = self.raw_config.get('conda')
677+
raw_conda = self._raw_config.get('conda')
678678
if raw_conda is None:
679679
return None
680680

@@ -693,7 +693,7 @@ def validate_build(self):
693693
694694
It prioritizes the value from the default image if exists.
695695
"""
696-
raw_build = self.raw_config.get('build', {})
696+
raw_build = self._raw_config.get('build', {})
697697
with self.catch_validation_error('build'):
698698
validate_dict(raw_build)
699699
build = {}
@@ -729,7 +729,7 @@ def validate_python(self):
729729
- ``version`` can be a string or number type.
730730
- ``extra_requirements`` needs to be used with ``install: 'pip'``.
731731
"""
732-
raw_python = self.raw_config.get('python', {})
732+
raw_python = self._raw_config.get('python', {})
733733
with self.catch_validation_error('python'):
734734
validate_dict(raw_python)
735735

@@ -750,17 +750,17 @@ def validate_python(self):
750750
)
751751

752752
with self.catch_validation_error('python.install'):
753-
raw_install = self.raw_config.get('python', {}).get('install', [])
753+
raw_install = self._raw_config.get('python', {}).get('install', [])
754754
validate_list(raw_install)
755755
if raw_install:
756756
# Transform to a dict, so it's easy to validate extra keys.
757-
self.raw_config.setdefault('python', {})['install'] = (
757+
self._raw_config.setdefault('python', {})['install'] = (
758758
list_to_dict(raw_install)
759759
)
760760
else:
761761
self.pop_config('python.install')
762762

763-
raw_install = self.raw_config.get('python', {}).get('install', [])
763+
raw_install = self._raw_config.get('python', {}).get('install', [])
764764
python['install'] = [
765765
self.validate_python_install(index)
766766
for index in range(len(raw_install))
@@ -783,7 +783,7 @@ def validate_python_install(self, index):
783783
"""Validates the python.install.{index} key."""
784784
python_install = {}
785785
key = 'python.install.{}'.format(index)
786-
raw_install = self.raw_config['python']['install'][str(index)]
786+
raw_install = self._raw_config['python']['install'][str(index)]
787787
with self.catch_validation_error(key):
788788
validate_dict(raw_install)
789789

@@ -850,7 +850,7 @@ def validate_doc_types(self):
850850
avoid innecessary validations.
851851
"""
852852
with self.catch_validation_error('.'):
853-
if 'sphinx' in self.raw_config and 'mkdocs' in self.raw_config:
853+
if 'sphinx' in self._raw_config and 'mkdocs' in self._raw_config:
854854
self.error(
855855
'.',
856856
'You can not have the ``sphinx`` and ``mkdocs`` '
@@ -864,7 +864,7 @@ def validate_mkdocs(self):
864864
865865
It makes sure we are using an existing configuration file.
866866
"""
867-
raw_mkdocs = self.raw_config.get('mkdocs')
867+
raw_mkdocs = self._raw_config.get('mkdocs')
868868
if raw_mkdocs is None:
869869
return None
870870

@@ -894,7 +894,7 @@ def validate_sphinx(self):
894894
It should be called after ``validate_mkdocs``. That way
895895
we can default to sphinx if ``mkdocs`` is not given.
896896
"""
897-
raw_sphinx = self.raw_config.get('sphinx')
897+
raw_sphinx = self._raw_config.get('sphinx')
898898
if raw_sphinx is None:
899899
if self.mkdocs is None:
900900
raw_sphinx = {}
@@ -961,7 +961,7 @@ def validate_submodules(self):
961961
- We can use the ``ALL`` keyword in include or exlude.
962962
- We can't exlude and include submodules at the same time.
963963
"""
964-
raw_submodules = self.raw_config.get('submodules', {})
964+
raw_submodules = self._raw_config.get('submodules', {})
965965
with self.catch_validation_error('submodules'):
966966
validate_dict(raw_submodules)
967967

@@ -1009,7 +1009,7 @@ def validate_keys(self):
10091009
Checks that we don't have extra keys (invalid ones).
10101010
10111011
This should be called after all the validations are done and all keys
1012-
are popped from `self.raw_config`.
1012+
are popped from `self._raw_config`.
10131013
"""
10141014
msg = (
10151015
'Invalid configuration option: {}. '
@@ -1018,7 +1018,7 @@ def validate_keys(self):
10181018
# The version key isn't popped, but it's
10191019
# validated in `load`.
10201020
self.pop_config('version', None)
1021-
wrong_key = '.'.join(self._get_extra_key(self.raw_config))
1021+
wrong_key = '.'.join(self._get_extra_key(self._raw_config))
10221022
if wrong_key:
10231023
self.error(
10241024
wrong_key,

readthedocs/config/tests/test_config.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -1870,7 +1870,7 @@ def test_strict_validation_pops_all_keys(self):
18701870
},
18711871
})
18721872
build.validate()
1873-
assert build.raw_config == {}
1873+
assert build._raw_config == {}
18741874

18751875
@pytest.mark.parametrize(
18761876
'value,expected', [
@@ -1888,27 +1888,27 @@ def test_get_extra_key(self, value, expected):
18881888
def test_pop_config_single(self):
18891889
build = self.get_build_config({'one': 1})
18901890
build.pop_config('one')
1891-
assert build.raw_config == {}
1891+
assert build._raw_config == {}
18921892

18931893
def test_pop_config_nested(self):
18941894
build = self.get_build_config({'one': {'two': 2}})
18951895
build.pop_config('one.two')
1896-
assert build.raw_config == {}
1896+
assert build._raw_config == {}
18971897

18981898
def test_pop_config_nested_with_residue(self):
18991899
build = self.get_build_config({'one': {'two': 2, 'three': 3}})
19001900
build.pop_config('one.two')
1901-
assert build.raw_config == {'one': {'three': 3}}
1901+
assert build._raw_config == {'one': {'three': 3}}
19021902

19031903
def test_pop_config_default_none(self):
19041904
build = self.get_build_config({'one': {'two': 2, 'three': 3}})
19051905
assert build.pop_config('one.four') is None
1906-
assert build.raw_config == {'one': {'two': 2, 'three': 3}}
1906+
assert build._raw_config == {'one': {'two': 2, 'three': 3}}
19071907

19081908
def test_pop_config_default(self):
19091909
build = self.get_build_config({'one': {'two': 2, 'three': 3}})
19101910
assert build.pop_config('one.four', 4) == 4
1911-
assert build.raw_config == {'one': {'two': 2, 'three': 3}}
1911+
assert build._raw_config == {'one': {'two': 2, 'three': 3}}
19121912

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

0 commit comments

Comments
 (0)