shk-readme-generator/extract.py

21 lines
575 B
Python

import re
from pathlib import Path
def extract_source(name):
model = Path(name) / Path(f"{name}.py")
text = model.read_text()
match = re.search(r"^#\s*sources?\s*:\s*(?:\n#\s*-\s*)?(.+?)\s*$", text, re.MULTILINE | re.IGNORECASE)
if not match:
print(text)
raise Exception(f"No match found in {name}!")
source = match.group(1)
return source.strip('#- ')
def main():
path = Path('.')
for model in (i for i in path.iterdir() if i.is_dir()):
print(model, '|', extract_source(model))
if __name__ == '__main__':
main()