11"""Module for building and build-time QA of the python tutorial website"""
2+ import argparse
23from os import makedirs
34from pathlib import Path
45import sys
1213from app .templates import TEMPLATES , BASE_HTML
1314from app .templates .codeblocks import codeblocks
1415from app .templates .links import links
15- from app .qa import LinkTester , CodeblocksTester , UnresolvedTemplateVariablesTester , BuildTestFailure
16+ from app .qa import (
17+ LinkTester , CodeblocksTester , UnresolvedTemplateVariablesTester , BuildTestFailure
18+ )
1619
20+ parser = argparse .ArgumentParser ()
21+ parser .add_argument ('--new-internal-links' )
22+ parser .add_argument (
23+ '--dry-run' ,
24+ help = """
25+ Do not write any files or directories.
26+ Still perform network requests for link checks
27+ """
28+ )
1729
18- def run_build_checks (env , ctx ):
30+ def run_build_checks (env , ctx , args ):
1931 """QA for build process"""
20- args = sys .argv [1 :]
21- ignore_internal = '--new-internal-links' in args
2232 testers = (
23- LinkTester (ignore_internal_links = ignore_internal ),
33+ LinkTester (ignore_internal_links = args . new_internal_links ),
2434 CodeblocksTester (),
2535 UnresolvedTemplateVariablesTester (env , ctx ),
2636 )
@@ -60,13 +70,11 @@ def render_templates(env, ctx):
6070
6171def write_render (render , path ):
6272 """Write final render to appropriate path"""
63- args = sys .argv [1 :]
64- if '--dry-run' not in args :
65- with open (path , 'w' , encoding = 'utf-8' ) as f :
66- f .write (render )
73+ with open (path , 'w' , encoding = 'utf-8' ) as f :
74+ f .write (render )
6775
6876
69- def build ( ):
77+ def main ( args ):
7078 """
7179 Perform all of the actions necessary to output the python tutorial webpages
7280 """
@@ -76,11 +84,13 @@ def build():
7684 undefined = DebugUndefined ,
7785 )
7886 ctx = {** codeblocks , ** links }
79- run_build_checks (env , ctx )
80- makedirs ('dist' , exist_ok = True )
81- for render , path in render_templates (env , ctx ):
82- write_render (render , path )
87+ run_build_checks (env , ctx , args )
88+ if not args .dry_run :
89+ makedirs ('dist' , exist_ok = True )
90+ for render , path in render_templates (env , ctx ):
91+ write_render (render , path )
8392
8493
8594if __name__ == '__main__' :
86- build ()
95+ args_ = parser .parse_args ()
96+ main (args_ )
0 commit comments