Debian Codegraph @

scripts/build_profile_docs.py

raw
1 #! /bin/env python
2 import os
3 from typing import Any
4
5 from isort.profiles import profiles
6
7 OUTPUT_FILE = os.path.abspath(
8 os.path.join(os.path.dirname(os.path.abspath(__file__)), "../docs/configuration/profiles.md")
9 )
10
11 HEADER = """Built-in Profile for isort
12 ========
13
14 The following profiles are built into isort to allow easy interoperability with
15 common projects and code styles.
16
17 To use any of the listed profiles, use `isort --profile PROFILE_NAME` from the command line, or `profile=PROFILE_NAME` in your configuration file.
18
19 """
20
21
22 def format_profile(profile_name: str, profile: dict[str, Any]) -> str:
23 options = "\n".join(f" - **{name}**: `{value!r}`" for name, value in profile.items())
24 return f"""
25 #{profile_name}
26
27 {profile.get("description", "")}
28 {options}
29 """
30
31
32 def document_text() -> str:
33 return f"{HEADER}{''.join(format_profile(profile_name, profile) for profile_name, profile in profiles.items())}"
34
35
36 def write_document():
37 with open(OUTPUT_FILE, "w") as output_file:
38 output_file.write(document_text())
39
40
41 if __name__ == "__main__":
42 write_document()