9
9
import sys
10
10
from argparse import ArgumentParser
11
11
12
- # This uses the `__all__` list in `util.py` to determine what objects to import
12
+ # This uses the `__all__` list in `util.py` to determine what objects to import
13
13
# see https://docs.python.org/3/tutorial/modules.html#importing-from-a-package
14
14
from util import *
15
15
from reporter import Reporter
119
119
# Please keep this in sync with .editorconfig!
120
120
MAX_LINE_LEN = 100
121
121
122
+ # Contents of _config.yml
123
+ CONFIG = {}
122
124
123
125
def main ():
124
126
"""Main driver."""
125
127
126
128
args = parse_args ()
127
129
args .reporter = Reporter ()
128
- life_cycle = check_config (args .reporter , args .source_dir )
130
+
131
+ global CONFIG
132
+ config_file = os .path .join (args .source_dir , '_config.yml' )
133
+ CONFIG = load_yaml (config_file )
134
+ CONFIG ["config_file" ] = config_file
135
+
136
+ life_cycle = CONFIG .get ('life_cycle' , None )
129
137
# pre-alpha lessons should report without error
130
138
if life_cycle == "pre-alpha" :
131
139
args .permissive = True
140
+
141
+ check_config (args .reporter )
132
142
check_source_rmd (args .reporter , args .source_dir , args .parser )
133
143
134
- args .references = {}
135
- if not using_remote_theme (args .source_dir ):
136
- args .references = read_references (args .reporter , args .reference_path )
144
+ args .references = read_references (args .reporter , args .reference_path )
137
145
138
146
docs = read_all_markdown (args .source_dir , args .parser )
139
147
check_fileset (args .source_dir , args .reporter , list (docs .keys ()))
@@ -196,22 +204,15 @@ def parse_args():
196
204
197
205
return args
198
206
199
- def using_remote_theme (source_dir ):
200
- config_file = os .path .join (source_dir , '_config.yml' )
201
- config = load_yaml (config_file )
202
- return 'remote_theme' in config
203
-
204
- def check_config (reporter , source_dir ):
207
+ def check_config (reporter ):
205
208
"""Check configuration file."""
206
209
207
- config_file = os .path .join (source_dir , '_config.yml' )
208
- config = load_yaml (config_file )
209
- reporter .check_field (config_file , 'configuration' ,
210
- config , 'kind' , 'lesson' )
211
- reporter .check_field (config_file , 'configuration' ,
212
- config , 'carpentry' , ('swc' , 'dc' , 'lc' , 'cp' , 'incubator' ))
213
- reporter .check_field (config_file , 'configuration' , config , 'title' )
214
- reporter .check_field (config_file , 'configuration' , config , 'email' )
210
+ reporter .check_field (CONFIG ["config_file" ], 'configuration' ,
211
+ CONFIG , 'kind' , 'lesson' )
212
+ reporter .check_field (CONFIG ["config_file" ], 'configuration' ,
213
+ CONFIG , 'carpentry' , ('swc' , 'dc' , 'lc' , 'cp' , 'incubator' ))
214
+ reporter .check_field (CONFIG ["config_file" ], 'configuration' , CONFIG , 'title' )
215
+ reporter .check_field (CONFIG ["config_file" ], 'configuration' , CONFIG , 'email' )
215
216
216
217
for defaults in [
217
218
{'values' : {'root' : '.' , 'layout' : 'page' }},
@@ -223,13 +224,9 @@ def check_config(reporter, source_dir):
223
224
layout = defaults ["values" ]["layout" ]
224
225
error_message = error_text .format (root , layout )
225
226
226
- defaults_test = defaults in config .get ('defaults' , [])
227
+ defaults_test = defaults in CONFIG .get ('defaults' , [])
227
228
reporter .check (defaults_test , 'configuration' , error_message )
228
229
229
- if 'life_cycle' not in config :
230
- config ['life_cycle' ] = None
231
- return config ['life_cycle' ]
232
-
233
230
def check_source_rmd (reporter , source_dir , parser ):
234
231
"""Check that Rmd episode files include `source: Rmd`"""
235
232
@@ -249,6 +246,9 @@ def read_references(reporter, ref_path):
249
246
{symbolic_name : URL}
250
247
"""
251
248
249
+ if 'remote_theme' in CONFIG :
250
+ return {}
251
+
252
252
if not ref_path :
253
253
raise Warning ("No filename has been provided." )
254
254
@@ -548,8 +548,7 @@ def check(self):
548
548
"""Run extra tests."""
549
549
550
550
super ().check ()
551
- if not using_remote_theme (self .args .source_dir ):
552
- self .check_reference_inclusion ()
551
+ self .check_reference_inclusion ()
553
552
554
553
def check_metadata (self ):
555
554
super ().check_metadata ()
@@ -579,6 +578,9 @@ def check_metadata_fields(self, expected):
579
578
def check_reference_inclusion (self ):
580
579
"""Check that links file has been included."""
581
580
581
+ if 'remote_theme' in CONFIG :
582
+ return
583
+
582
584
if not self .args .reference_path :
583
585
return
584
586
0 commit comments