@@ -129,8 +129,17 @@ class BuildConfigBase(object):
129
129
"""
130
130
Config that handles the build of one particular documentation.
131
131
132
- You need to call ``validate`` before the config is ready to use. Also
133
- setting the ``output_base`` is required before using it for a build.
132
+ .. note::
133
+
134
+ You need to call ``validate`` before the config is ready to use.
135
+
136
+ :param env_config: A dict that cointains additional information
137
+ about the environment.
138
+ :param raw_config: A dict with all configuration without validation.
139
+ :param source_file: The file that contains the configuration.
140
+ All paths are relative to this file.
141
+ If a dir is given, the configuration was loaded
142
+ from another source (like the web admin).
134
143
"""
135
144
136
145
version = None
@@ -140,21 +149,27 @@ def __init__(self, env_config, raw_config, source_file, source_position):
140
149
self .raw_config = raw_config
141
150
self .source_file = source_file
142
151
self .source_position = source_position
143
- self .base_path = os .path .dirname (self .source_file )
152
+ if os .path .isdir (self .source_file ):
153
+ self .base_path = self .source_file
154
+ else :
155
+ self .base_path = os .path .dirname (self .source_file )
144
156
self .defaults = self .env_config .get ('defaults' , {})
145
157
146
158
self ._config = {}
147
159
148
160
def error (self , key , message , code ):
149
161
"""Raise an error related to ``key``."""
150
- source = '{file} [{pos}]' .format (
151
- file = os .path .relpath (self .source_file , self .base_path ),
152
- pos = self .source_position ,
153
- )
154
- error_message = '{source}: {message}' .format (
155
- source = source ,
156
- message = message ,
157
- )
162
+ 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
+ )
167
+ error_message = '{source}: {message}' .format (
168
+ source = source ,
169
+ message = message ,
170
+ )
171
+ else :
172
+ error_message = message
158
173
raise InvalidConfig (
159
174
key = key ,
160
175
code = code ,
@@ -307,10 +322,9 @@ def validate_output_base(self):
307
322
"""Validates that ``output_base`` exists and set its absolute path."""
308
323
assert 'output_base' in self .env_config , (
309
324
'"output_base" required in "env_config"' )
310
- base_path = os .path .dirname (self .source_file )
311
325
output_base = os .path .abspath (
312
326
os .path .join (
313
- self .env_config .get ('output_base' , base_path ),
327
+ self .env_config .get ('output_base' , self . base_path ),
314
328
)
315
329
)
316
330
return output_base
@@ -338,10 +352,9 @@ def validate_base(self):
338
352
if 'base' in self .raw_config :
339
353
base = self .raw_config ['base' ]
340
354
else :
341
- base = os . path . dirname ( self .source_file )
355
+ base = self .base_path
342
356
with self .catch_validation_error ('base' ):
343
- base_path = os .path .dirname (self .source_file )
344
- base = validate_directory (base , base_path )
357
+ base = validate_directory (base , self .base_path )
345
358
return base
346
359
347
360
def validate_build (self ):
@@ -488,9 +501,8 @@ def validate_conda(self):
488
501
conda_environment = None
489
502
if 'file' in raw_conda :
490
503
with self .catch_validation_error ('conda.file' ):
491
- base_path = os .path .dirname (self .source_file )
492
504
conda_environment = validate_file (
493
- raw_conda ['file' ], base_path
505
+ raw_conda ['file' ], self . base_path
494
506
)
495
507
conda ['environment' ] = conda_environment
496
508
@@ -505,9 +517,8 @@ def validate_requirements_file(self):
505
517
requirements_file = self .raw_config ['requirements_file' ]
506
518
if not requirements_file :
507
519
return None
508
- base_path = os .path .dirname (self .source_file )
509
520
with self .catch_validation_error ('requirements_file' ):
510
- validate_file (requirements_file , base_path )
521
+ validate_file (requirements_file , self . base_path )
511
522
return requirements_file
512
523
513
524
def validate_formats (self ):
0 commit comments