diff --git a/bin/lesson_check.py b/bin/lesson_check.py index f223ccfe..86e42495 100644 --- a/bin/lesson_check.py +++ b/bin/lesson_check.py @@ -9,7 +9,7 @@ import sys from argparse import ArgumentParser -# This uses the `__all__` list in `util.py` to determine what objects to import +# This uses the `__all__` list in `util.py` to determine what objects to import # see https://docs.python.org/3/tutorial/modules.html#importing-from-a-package from util import * from reporter import Reporter @@ -119,21 +119,29 @@ # Please keep this in sync with .editorconfig! MAX_LINE_LEN = 100 +# Contents of _config.yml +CONFIG = {} def main(): """Main driver.""" args = parse_args() args.reporter = Reporter() - life_cycle = check_config(args.reporter, args.source_dir) + + global CONFIG + config_file = os.path.join(args.source_dir, '_config.yml') + CONFIG = load_yaml(config_file) + CONFIG["config_file"] = config_file + + life_cycle = CONFIG.get('life_cycle', None) # pre-alpha lessons should report without error if life_cycle == "pre-alpha": args.permissive = True + + check_config(args.reporter) check_source_rmd(args.reporter, args.source_dir, args.parser) - args.references = {} - if not using_remote_theme(args.source_dir): - args.references = read_references(args.reporter, args.reference_path) + args.references = read_references(args.reporter, args.reference_path) docs = read_all_markdown(args.source_dir, args.parser) check_fileset(args.source_dir, args.reporter, list(docs.keys())) @@ -196,22 +204,15 @@ def parse_args(): return args -def using_remote_theme(source_dir): - config_file = os.path.join(source_dir, '_config.yml') - config = load_yaml(config_file) - return 'remote_theme' in config - -def check_config(reporter, source_dir): +def check_config(reporter): """Check configuration file.""" - config_file = os.path.join(source_dir, '_config.yml') - config = load_yaml(config_file) - reporter.check_field(config_file, 'configuration', - config, 'kind', 'lesson') - reporter.check_field(config_file, 'configuration', - config, 'carpentry', ('swc', 'dc', 'lc', 'cp', 'incubator')) - reporter.check_field(config_file, 'configuration', config, 'title') - reporter.check_field(config_file, 'configuration', config, 'email') + reporter.check_field(CONFIG["config_file"], 'configuration', + CONFIG, 'kind', 'lesson') + reporter.check_field(CONFIG["config_file"], 'configuration', + CONFIG, 'carpentry', ('swc', 'dc', 'lc', 'cp', 'incubator')) + reporter.check_field(CONFIG["config_file"], 'configuration', CONFIG, 'title') + reporter.check_field(CONFIG["config_file"], 'configuration', CONFIG, 'email') for defaults in [ {'values': {'root': '.', 'layout': 'page'}}, @@ -223,13 +224,9 @@ def check_config(reporter, source_dir): layout = defaults["values"]["layout"] error_message = error_text.format(root, layout) - defaults_test = defaults in config.get('defaults', []) + defaults_test = defaults in CONFIG.get('defaults', []) reporter.check(defaults_test, 'configuration', error_message) - if 'life_cycle' not in config: - config['life_cycle'] = None - return config['life_cycle'] - def check_source_rmd(reporter, source_dir, parser): """Check that Rmd episode files include `source: Rmd`""" @@ -249,6 +246,9 @@ def read_references(reporter, ref_path): {symbolic_name : URL} """ + if 'remote_theme' in CONFIG: + return {} + if not ref_path: raise Warning("No filename has been provided.") @@ -548,8 +548,7 @@ def check(self): """Run extra tests.""" super().check() - if not using_remote_theme(self.args.source_dir): - self.check_reference_inclusion() + self.check_reference_inclusion() def check_metadata(self): super().check_metadata() @@ -579,6 +578,9 @@ def check_metadata_fields(self, expected): def check_reference_inclusion(self): """Check that links file has been included.""" + if 'remote_theme' in CONFIG: + return + if not self.args.reference_path: return