@@ -33,15 +33,14 @@ def write_module_doc_metafile(dump_location: pathlib.Path, module_name: str) ->
3333 """Create a markdown file which allows mkdocstrings to index an individual module."""
3434 write_file = dump_location / (module_name .replace ('.' , '/' ) + '.md' )
3535 write_file .parent .mkdir (parents = True , exist_ok = True )
36- fh = write_file .open ('w' , encoding = 'utf8' )
37- # yaml header
38- fh .write ('---\n ' )
39- fh .write (f'title: { module_name } \n ' )
40- fh .write (f'description: Documentation for { module_name } module\n ' )
41- fh .write ('---\n \n ' )
42- fh .write (f'::: { module_name } \n ' ) # noqa: E231
43- fh .write ('handler: python\n ' )
44- fh .close ()
36+ with write_file .open ('w' , encoding = 'utf8' ) as fh :
37+ # yaml header
38+ fh .write ('---\n ' )
39+ fh .write (f'title: { module_name } \n ' )
40+ fh .write (f'description: Documentation for { module_name } module\n ' )
41+ fh .write ('---\n \n ' )
42+ fh .write (f'::: { module_name } \n ' ) # noqa: E231
43+ fh .write ('handler: python\n ' )
4544
4645
4746def get_key (var : Dict [str , Any ]) -> str :
@@ -72,11 +71,12 @@ def create_module_markdowns(base_path: pathlib.Path, base_module: str, dump_loca
7271def md_txt (original : pathlib .Path , md_ed_license : pathlib .Path ):
7372 """Convert the apache license into a markdown file by wrapping the content in a text escape block."""
7473 assert original .exists ()
75- orig_data = original .open ('r' , encoding = 'utf8' ).read ()
76- md_fh = md_ed_license .open ('w' , encoding = 'utf8' )
77- md_fh .write ('```text\n ' )
78- md_fh .write (orig_data )
79- md_fh .write ('\n ```\n ' )
74+ with original .open ('r' , encoding = 'utf8' ) as orig_fh :
75+ orig_data = orig_fh .read ()
76+ with md_ed_license .open ('w' , encoding = 'utf8' ) as md_fh :
77+ md_fh .write ('```text\n ' )
78+ md_fh .write (orig_data )
79+ md_fh .write ('\n ```\n ' )
8080
8181
8282def cleanup_directory (dump_location : pathlib .Path ):
0 commit comments