Skip to content

Commit 8de5432

Browse files
committed
Remove support for multiple configurations in one file
1 parent 7fb4b18 commit 8de5432

File tree

3 files changed

+24
-50
lines changed

3 files changed

+24
-50
lines changed

readthedocs/config/config.py

Lines changed: 16 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
'ConfigError',
3737
'ConfigOptionNotSupportedError',
3838
'InvalidConfig',
39-
'ProjectConfig',
4039
)
4140

4241
ALL = 'all'
@@ -110,12 +109,10 @@ class InvalidConfig(ConfigError):
110109

111110
message_template = 'Invalid "{key}": {error}'
112111

113-
def __init__(self, key, code, error_message, source_file=None,
114-
source_position=None):
112+
def __init__(self, key, code, error_message, source_file=None):
115113
self.key = key
116114
self.code = code
117115
self.source_file = source_file
118-
self.source_position = source_position
119116
message = self.message_template.format(
120117
key=key,
121118
code=code,
@@ -144,11 +141,10 @@ class BuildConfigBase(object):
144141

145142
version = None
146143

147-
def __init__(self, env_config, raw_config, source_file, source_position):
144+
def __init__(self, env_config, raw_config, source_file):
148145
self.env_config = env_config
149146
self.raw_config = raw_config
150147
self.source_file = source_file
151-
self.source_position = source_position
152148
if os.path.isdir(self.source_file):
153149
self.base_path = self.source_file
154150
else:
@@ -160,10 +156,7 @@ def __init__(self, env_config, raw_config, source_file, source_position):
160156
def error(self, key, message, code):
161157
"""Raise an error related to ``key``."""
162158
if not os.path.isdir(self.source_file):
163-
source = '{file} [{pos}]'.format(
164-
file=os.path.relpath(self.source_file, self.base_path),
165-
pos=self.source_position,
166-
)
159+
source = os.path.relpath(self.source_file, self.base_path)
167160
error_message = '{source}: {message}'.format(
168161
source=source,
169162
message=message,
@@ -175,7 +168,6 @@ def error(self, key, message, code):
175168
code=code,
176169
error_message=error_message,
177170
source_file=self.source_file,
178-
source_position=self.source_position,
179171
)
180172

181173
@contextmanager
@@ -189,7 +181,6 @@ def catch_validation_error(self, key):
189181
code=error.code,
190182
error_message=str(error),
191183
source_file=self.source_file,
192-
source_position=self.source_position,
193184
)
194185

195186
def pop(self, name, container, default, raise_ex):
@@ -1043,16 +1034,6 @@ def submodules(self):
10431034
return Submodules(**self._config['submodules'])
10441035

10451036

1046-
class ProjectConfig(list):
1047-
1048-
"""Wrapper for multiple build configs."""
1049-
1050-
def validate(self):
1051-
"""Validates each configuration build."""
1052-
for build in self:
1053-
build.validate()
1054-
1055-
10561037
def load(path, env_config):
10571038
"""
10581039
Load a project configuration and the top-most build config for a given path.
@@ -1068,10 +1049,9 @@ def load(path, env_config):
10681049
'No configuration file found',
10691050
code=CONFIG_REQUIRED
10701051
)
1071-
build_configs = []
10721052
with open(filename, 'r') as configuration_file:
10731053
try:
1074-
configs = parse(configuration_file.read())
1054+
config = parse(configuration_file.read())
10751055
except ParseError as error:
10761056
raise ConfigError(
10771057
'Parse error in {filename}: {message}'.format(
@@ -1080,23 +1060,19 @@ def load(path, env_config):
10801060
),
10811061
code=CONFIG_SYNTAX_INVALID,
10821062
)
1083-
for i, config in enumerate(configs):
1084-
allow_v2 = env_config.get('allow_v2')
1085-
if allow_v2:
1086-
version = config.get('version', 1)
1087-
else:
1088-
version = 1
1089-
build_config = get_configuration_class(version)(
1090-
env_config,
1091-
config,
1092-
source_file=filename,
1093-
source_position=i,
1094-
)
1095-
build_configs.append(build_config)
1063+
allow_v2 = env_config.get('allow_v2')
1064+
if allow_v2:
1065+
version = config.get('version', 1)
1066+
else:
1067+
version = 1
1068+
build_config = get_configuration_class(version)(
1069+
env_config,
1070+
config,
1071+
source_file=filename,
1072+
)
10961073

1097-
project_config = ProjectConfig(build_configs)
1098-
project_config.validate()
1099-
return project_config
1074+
build_config.validate()
1075+
return build_config
11001076

11011077

11021078
def get_configuration_class(version):

readthedocs/config/parser.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,17 @@ class ParseError(Exception):
1717

1818
def parse(stream):
1919
"""
20-
Take file-like object and return a list of project configurations.
20+
Take file-like object and return a project configuration.
2121
22-
The files need be valid YAML and only contain mappings as documents.
22+
The file need be valid YAML and only contain mappings as document.
2323
Everything else raises a ``ParseError``.
2424
"""
2525
try:
26-
configs = list(yaml.safe_load_all(stream))
26+
config = yaml.safe_load(stream)
2727
except yaml.YAMLError as error:
2828
raise ParseError('YAML: {message}'.format(message=error))
29-
if not configs:
29+
if not isinstance(config, dict):
30+
raise ParseError('Expected mapping')
31+
if not config:
3032
raise ParseError('Empty config')
31-
for config in configs:
32-
if not isinstance(config, dict):
33-
raise ParseError('Expected mapping')
34-
return configs
33+
return config

readthedocs/doc_builder/config.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def load_yaml_config(version):
6565
config = load_config(
6666
path=checkout_path,
6767
env_config=env_config,
68-
)[0]
68+
)
6969
except InvalidConfig:
7070
# This is a subclass of ConfigError, so has to come first
7171
raise
@@ -74,7 +74,6 @@ def load_yaml_config(version):
7474
env_config=env_config,
7575
raw_config={},
7676
source_file=checkout_path,
77-
source_position=0,
7877
)
7978
config.validate()
8079
return config

0 commit comments

Comments
 (0)