This repository has been archived by the owner on Jun 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add script to transform documentation
- Loading branch information
1 parent
bb28ae6
commit 81c2236
Showing
4 changed files
with
168 additions
and
4 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
# Documentation transformation | ||
transdoc_build/ | ||
|
||
# Byte-compiled / optimized / DLL files | ||
__pycache__/ | ||
*.py[cod] | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
""" | ||
# Scripts / transform docstrings | ||
Transform docstrings to make them render more nicely inline, and online. | ||
""" | ||
from transdoc import transform | ||
from pathlib import Path | ||
from shutil import rmtree, copyfile | ||
import os | ||
|
||
|
||
INPUT_DIR = Path("src") | ||
OUTPUT_DIR = Path("transdoc_build") | ||
|
||
|
||
# Rule definitions | ||
############################################################################### | ||
|
||
|
||
BASE_URL = "https://miguelguthridge.github.io/FL-Studio-API-Stubs" | ||
|
||
NOTE_MAPPINGS = { | ||
"colors": """Note that colors can be split into or built from components using the | ||
functions provided in the [utils](https://miguelguthridge.github.io/FL-Studio-API-Stubs/utils/) module. | ||
* [ColorToRGB()](https://miguelguthridge.github.io/FL-Studio-API-Stubs/utils/#utils.ColorToRGB) | ||
* [RGBToColor()](https://miguelguthridge.github.io/FL-Studio-API-Stubs/utils/#utils.RGBToColor)""", | ||
|
||
"playlist_indexes": "Note that playlist track indexes start at 1.", | ||
} | ||
|
||
|
||
def url_for(function: str) -> str: | ||
""" | ||
Return a markdown URL for a function within the API, given its name. | ||
""" | ||
module, fn = function.rsplit(".", 1) | ||
return f"[{fn}()]({BASE_URL}/{module}/#{module}.{fn})" | ||
|
||
|
||
def note(name: str) -> str: | ||
""" | ||
Insert a note given its name. | ||
""" | ||
return NOTE_MAPPINGS[name] | ||
|
||
|
||
# The actual script | ||
############################################################################### | ||
|
||
|
||
def transform_modules(): | ||
""" | ||
Go through all code in the src/ directory and transform it | ||
""" | ||
|
||
try: | ||
rmtree(OUTPUT_DIR) | ||
except Exception as e: | ||
print(e) | ||
|
||
for dirpath, _, filenames in os.walk(INPUT_DIR): | ||
# Create directory | ||
out_dir = OUTPUT_DIR.joinpath(Path(dirpath).relative_to(INPUT_DIR)) | ||
out_dir.mkdir() | ||
for file in filenames: | ||
# If it's not a Python file, just copy it | ||
out_file = out_dir.joinpath(file) | ||
in_file = Path(dirpath).joinpath(file) | ||
|
||
if not in_file.suffix == ".py": | ||
copyfile(in_file, out_file) | ||
else: | ||
txt = in_file.read_text() | ||
out_file.write_text(transform(txt, [url_for, note])) | ||
|
||
|
||
if __name__ == '__main__': | ||
transform_modules() |