X-Git-Url: https://git.arvados.org/rnaseq-cwl-training.git/blobdiff_plain/c9add9b04978e7ba6b617d0572ab09426d6e9796..HEAD:/bin/lesson_check.py diff --git a/bin/lesson_check.py b/bin/lesson_check.py old mode 100755 new mode 100644 index 4a4af32..25388d3 --- a/bin/lesson_check.py +++ b/bin/lesson_check.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - """ Check lesson files and their contents. """ @@ -61,6 +59,7 @@ P_INTERNAL_INCLUDE_LINK = re.compile(r'^{% include ([^ ]*) %}$') # What kinds of blockquotes are allowed? KNOWN_BLOCKQUOTES = { 'callout', + 'caution', 'challenge', 'checklist', 'discussion', @@ -69,22 +68,17 @@ KNOWN_BLOCKQUOTES = { 'prereq', 'quotation', 'solution', - 'testimonial' + 'testimonial', + 'warning' } # What kinds of code fragments are allowed? +# Below we allow all 'language-*' code blocks KNOWN_CODEBLOCKS = { 'error', 'output', 'source', - 'language-bash', - 'html', - 'language-make', - 'language-matlab', - 'language-python', - 'language-r', - 'language-shell', - 'language-sql' + 'warning' } # What fields are required in teaching episode metadata? @@ -114,7 +108,10 @@ def main(): args = parse_args() args.reporter = Reporter() - check_config(args.reporter, args.source_dir) + life_cycle = check_config(args.reporter, args.source_dir) + # pre-alpha lessons should report without error + if life_cycle == "pre-alpha": + args.permissive = True check_source_rmd(args.reporter, args.source_dir, args.parser) args.references = read_references(args.reporter, args.reference_path) @@ -179,7 +176,7 @@ def check_config(reporter, source_dir): reporter.check_field(config_file, 'configuration', config, 'kind', 'lesson') reporter.check_field(config_file, 'configuration', - config, 'carpentry', ('swc', 'dc', 'lc', 'cp')) + config, 'carpentry', ('swc', 'dc', 'lc', 'cp', 'incubator')) reporter.check_field(config_file, 'configuration', config, 'title') reporter.check_field(config_file, 'configuration', config, 'email') @@ -191,6 +188,7 @@ def check_config(reporter, source_dir): reporter.check(defaults in config.get('defaults', []), 'configuration', '"root" not set to "." in configuration') + return config['life_cycle'] def check_source_rmd(reporter, source_dir, parser): """Check that Rmd episode files include `source: Rmd`""" @@ -217,7 +215,7 @@ def read_references(reporter, ref_path): result = {} urls_seen = set() - with open(ref_path, 'r') as reader: + with open(ref_path, 'r', encoding='utf-8') as reader: for (num, line) in enumerate(reader, 1): if P_INTERNAL_INCLUDE_LINK.search(line): continue @@ -257,16 +255,14 @@ def read_all_markdown(source_dir, parser): {path : {'metadata':yaml, 'metadata_len':N, 'text':text, 'lines':[(i, line, len)], 'doc':doc}} """ + all_dirs = [os.path.join(source_dir, d) for d in SOURCE_DIRS] + all_patterns = [os.path.join(d, '*.md') for d in all_dirs] result = {} - for d in SOURCE_DIRS: - dpath = os.path.join(source_dir, d) - - pattern = os.path.join(dpath, '*.md') - for filename in glob.glob(pattern): + for pat in all_patterns: + for filename in glob.glob(pat): data = read_markdown(parser, filename) if data: result[filename] = data - return result @@ -394,7 +390,7 @@ class CheckBase: for node in self.find_all(self.doc, {'type': 'codeblock'}): cls = self.get_val(node, 'attr', 'class') - self.reporter.check(cls in KNOWN_CODEBLOCKS, + self.reporter.check(cls in KNOWN_CODEBLOCKS or cls.startswith('language-'), (self.filename, self.get_loc(node)), 'Unknown or missing code block type {0}', cls) @@ -561,7 +557,7 @@ CHECKERS = [ (re.compile(r'README\.md'), CheckNonJekyll), (re.compile(r'index\.md'), CheckIndex), (re.compile(r'reference\.md'), CheckReference), - (re.compile(r'_episodes/.*\.md'), CheckEpisode), + (re.compile(os.path.join('_episodes', '*\.md')), CheckEpisode), (re.compile(r'.*\.md'), CheckGeneric) ]