1- """Module for building and build-time QA of the python tutorial website """
1+ """Module for building and build-time QA of the python tutorial codeblocks """
22import inspect
33import json
44from os import makedirs
1313 first_steps ,
1414 first_projects ,
1515 variables ,
16- )
16+ )
17+
18+ OUTPUT_DIR = "dist"
1719
1820
1921def run_build_checks ():
@@ -33,13 +35,20 @@ def main():
3335 """
3436 Perform all of the actions necessary to output the python tutorial codeblocks
3537 """
38+ print ()
3639 run_build_checks ()
37- makedirs ('dist' , exist_ok = True )
38- with open ('dist/codeblocks.json' , 'w' , encoding = 'utf-8' ) as f :
39- json .dump (get_func_body , f )
40+ print ()
41+ makedirs (OUTPUT_DIR , exist_ok = True )
42+ with open (f'{ OUTPUT_DIR } /codeblocks.json' , 'w' , encoding = 'utf-8' ) as f :
43+ codeblock_map = {}
4044 for module in PAGE_MODULES :
41- for fn_name , fn in inspect .getmembers (module ):
42- print (fn_name , fn )
45+ nonlocals = getattr (module , "NONLOCALS" , ())
46+ print (f"extracting from { module .__name__ } :" )
47+ for member_name , member in inspect .getmembers (module , inspect .isfunction ):
48+ if member_name not in nonlocals :
49+ print (" " , member_name )
50+ codeblock_map [member_name ] = get_func_body (member )
51+ json .dump (codeblock_map , f )
4352
4453
4554if __name__ == '__main__' :
0 commit comments