@ -42,6 +42,15 @@ def category_to_folder_name(category) -> str:
assert ( all ( c . isalnum ( ) or c == ' _ ' for c in folder ) )
return folder
def get_files_in_dir ( directory ) - > list [ str ] :
file_paths = [ ]
for root , dirs , files in os . walk ( directory ) :
for file in files :
full_path = os . path . join ( root , file )
relative_path = os . path . relpath ( full_path , directory )
file_paths . append ( relative_path )
return file_paths
def extract_sources ( ) - > ( Dict [ str , argparse . ArgumentParser ] , Dict [ str , list [ str ] ] ) :
"""
Extract the sources .
@ -210,6 +219,26 @@ def generate_index(filename_to_parser: Dict[str, argparse.ArgumentParser], categ
index_autogen_warning = " <!-- THIS FILE IS AUTOGENERATED. DO NOT EDIT IT. See ~/scripts/generate_docs.sh --> \n "
return index_autogen_warning + mdFile . get_md_text ( )
def verify_existence ( filenames : list [ str ] ) - > ( list [ str ] , list [ str ] ) :
current = get_files_in_dir ( base_path )
current = [ base_path + x for x in current ]
missing = [ x for x in filenames if x not in current ]
extra = [ x for x in current if x not in filenames ]
if missing :
print ( " Missing files: " )
for f in missing :
print ( f )
print ( )
if extra :
print ( " These files shouldn ' t exist: " )
for f in extra :
print ( f )
print ( )
return missing , extra
def verify_files ( filename_to_markdown : Dict [ str , str ] ) - > str | None :
"""
@ -306,7 +335,14 @@ markdowned = convert_all_to_markdown(extracted)
markdowned [ base_path + " index.md " ] = generate_index ( extracted , cat_to_names )
if just_verify :
print ( " Verifying... " )
print ( " Checking if all files are in place.. " )
missing , extra = verify_existence ( markdowned . keys ( ) )
if missing or extra :
print ( " To fix this please run ./scripts/generate_docs.sh. " )
exit ( 555 )
print ( " Every file is where it should be! " )
print ( " Verifying contents... " )
err = verify_files ( markdowned )
if err :
print ( " VERIFICATION FAILED. The files differ from what would be auto-generated. " )
@ -314,8 +350,17 @@ if just_verify:
print ( " Please run ./scripts/generate_docs.sh from project root and commit the changes. " )
exit ( 777 )
print ( " Verification Successful. " )
print ( " Verification successful! " )
else :
print ( " Updating files... " )
update_files ( markdowned )
print ( " Update successful. " )
missing , extra = verify_existence ( markdowned . keys ( ) )
assert ( not missing and " Some files are missing, which should be impossible. " )
if extra :
print ( f " Take care! Deleting these extra files ( { len ( extra ) } ): " )
for e in extra :
print ( e )
os . remove ( e )
print ( " Deleted successfully. " )