File: build_profile_docs.py

package info (click to toggle)
isort 7.0.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,548 kB
  • sloc: python: 15,337; javascript: 42; makefile: 28; sh: 22
file content (42 lines) | stat: -rwxr-xr-x 1,092 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#! /bin/env python
import os
from typing import Any

from isort.profiles import profiles

OUTPUT_FILE = os.path.abspath(
    os.path.join(os.path.dirname(os.path.abspath(__file__)), "../docs/configuration/profiles.md")
)

HEADER = """Built-in Profile for isort
========

The following profiles are built into isort to allow easy interoperability with
common projects and code styles.

To use any of the listed profiles, use `isort --profile PROFILE_NAME` from the command line, or `profile=PROFILE_NAME` in your configuration file.

"""


def format_profile(profile_name: str, profile: dict[str, Any]) -> str:
    options = "\n".join(f" - **{name}**: `{value!r}`" for name, value in profile.items())
    return f"""
#{profile_name}

{profile.get("description", "")}
{options}
"""


def document_text() -> str:
    return f"{HEADER}{''.join(format_profile(profile_name, profile) for profile_name, profile in profiles.items())}"


def write_document():
    with open(OUTPUT_FILE, "w") as output_file:
        output_file.write(document_text())


if __name__ == "__main__":
    write_document()