Created
September 4, 2023 12:15
-
-
Save nekufa/f3046ff01a0eb7974af8f2e210a353b6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
from inspect import getmembers, isclass | |
from os import path | |
from posixpath import abspath | |
from schemas import settings | |
base = settings.BaseSettings.schema() | |
info = '' | |
toc = '' | |
members = getmembers(settings, isclass) | |
for (name, member) in members: | |
if member == settings.BaseSettings: | |
continue | |
if not hasattr(member, 'schema'): | |
continue | |
schema = member.schema() | |
if schema['description'] == base['description']: | |
continue | |
title = name.replace("Settings", "") | |
title = re.sub(r'((?<=[a-z])[A-Z]|(?<!\A)[A-Z](?=[a-z]))', r' \1', title) | |
comment = schema['description'].replace("\n", " ") | |
anchor = title.lower().replace(" ", "-") | |
toc += "\n- [" + title + '](#-' + anchor + ') - ' + comment | |
info += "\n## " + '[^](#environment) ' + title + "\n" + comment | |
rows = [] | |
for property in schema['properties'].values(): | |
if 'allOf' in property or property['type'] == 'array': | |
continue | |
env = list(property['env_names'])[0].upper() | |
row = "\n- `" + env | |
if 'default' in property and len(str(property['default'])) > 0: | |
row += ' = ' + str(property['default']) | |
row += '`<br/>' | |
row += ' ' + property['title'] | |
rows.append(row) | |
rows.sort() | |
info += "".join(rows) | |
info += "" + "\n" | |
readme = abspath(__file__ + '/../../README.md') | |
if path.isfile(readme): | |
with open(readme, mode='r') as f: | |
splitter = '<!--GENERATED_PART-->' | |
contents = f.read() | |
header = contents.split(splitter)[0] | |
with open(readme, mode='w') as f: | |
f.write(header + splitter + toc + info) | |
print('readme actualized') | |
else: | |
print(info) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment