99import sys
1010from argparse import ArgumentParser
1111
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
1313# see https://docs.python.org/3/tutorial/modules.html#importing-from-a-package
1414from util import *
1515from reporter import Reporter
119119# Please keep this in sync with .editorconfig!
120120MAX_LINE_LEN = 100
121121
122+ # Contents of _config.yml
123+ CONFIG = {}
122124
123125def main ():
124126 """Main driver."""
125127
126128 args = parse_args ()
127129 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 )
129137 # pre-alpha lessons should report without error
130138 if life_cycle == "pre-alpha" :
131139 args .permissive = True
140+
141+ check_config (args .reporter )
132142 check_source_rmd (args .reporter , args .source_dir , args .parser )
133143
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 )
137145
138146 docs = read_all_markdown (args .source_dir , args .parser )
139147 check_fileset (args .source_dir , args .reporter , list (docs .keys ()))
@@ -196,22 +204,15 @@ def parse_args():
196204
197205 return args
198206
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 ):
205208 """Check configuration file."""
206209
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' )
215216
216217 for defaults in [
217218 {'values' : {'root' : '.' , 'layout' : 'page' }},
@@ -223,13 +224,9 @@ def check_config(reporter, source_dir):
223224 layout = defaults ["values" ]["layout" ]
224225 error_message = error_text .format (root , layout )
225226
226- defaults_test = defaults in config .get ('defaults' , [])
227+ defaults_test = defaults in CONFIG .get ('defaults' , [])
227228 reporter .check (defaults_test , 'configuration' , error_message )
228229
229- if 'life_cycle' not in config :
230- config ['life_cycle' ] = None
231- return config ['life_cycle' ]
232-
233230def check_source_rmd (reporter , source_dir , parser ):
234231 """Check that Rmd episode files include `source: Rmd`"""
235232
@@ -249,6 +246,9 @@ def read_references(reporter, ref_path):
249246 {symbolic_name : URL}
250247 """
251248
249+ if 'remote_theme' in CONFIG :
250+ return {}
251+
252252 if not ref_path :
253253 raise Warning ("No filename has been provided." )
254254
@@ -548,8 +548,7 @@ def check(self):
548548 """Run extra tests."""
549549
550550 super ().check ()
551- if not using_remote_theme (self .args .source_dir ):
552- self .check_reference_inclusion ()
551+ self .check_reference_inclusion ()
553552
554553 def check_metadata (self ):
555554 super ().check_metadata ()
@@ -579,6 +578,9 @@ def check_metadata_fields(self, expected):
579578 def check_reference_inclusion (self ):
580579 """Check that links file has been included."""
581580
581+ if 'remote_theme' in CONFIG :
582+ return
583+
582584 if not self .args .reference_path :
583585 return
584586
0 commit comments