Skip to content

Commit 6593201

Browse files
Merge pull request #53 from ynput/feature/mkdocs-setup
Automated mkdocs setup
2 parents 13d8b4d + 725c78c commit 6593201

File tree

10 files changed

+1010
-0
lines changed

10 files changed

+1010
-0
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,3 +160,6 @@ Icon
160160
Network Trash Folder
161161
Temporary Items
162162
.apdisk
163+
164+
# ignore mkdocs build
165+
site/

docs/css/custom.css

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[data-md-color-scheme="slate"] {
2+
/* simple slate overrides */
3+
--md-primary-fg-color: hsl(155, 49%, 50%);
4+
--md-accent-fg-color: rgb(93, 200, 156);
5+
--md-typeset-a-color: hsl(155, 49%, 45%) !important;
6+
}
7+
[data-md-color-scheme="default"] {
8+
/* simple default overrides */
9+
--md-primary-fg-color: hsl(155, 49%, 50%);
10+
--md-accent-fg-color: rgb(93, 200, 156);
11+
--md-typeset-a-color: hsl(155, 49%, 45%) !important;
12+
}

docs/img/ay-symbol-blackw-full.png

1.59 KB
Loading

docs/img/favicon.ico

490 Bytes
Binary file not shown.

docs/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
--8<-- "README.md"

docs/license.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
--8<-- "LICENSE"

mkdocs.yml

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
site_name: ayon-resolve
2+
repo_url: https://github.com/ynput/ayon-resolve
3+
4+
nav:
5+
- Home: index.md
6+
- License: license.md
7+
8+
theme:
9+
name: material
10+
palette:
11+
- media: "(prefers-color-scheme: dark)"
12+
scheme: slate
13+
toggle:
14+
icon: material/toggle-switch-off-outline
15+
name: Switch to light mode
16+
- media: "(prefers-color-scheme: light)"
17+
scheme: default
18+
toggle:
19+
icon: material/toggle-switch
20+
name: Switch to dark mode
21+
logo: img/ay-symbol-blackw-full.png
22+
favicon: img/favicon.ico
23+
features:
24+
- navigation.sections
25+
- navigation.path
26+
- navigation.prune
27+
28+
extra:
29+
version:
30+
provider: mike
31+
32+
extra_css: [css/custom.css]
33+
34+
markdown_extensions:
35+
- mdx_gh_links
36+
- pymdownx.snippets
37+
38+
plugins:
39+
- search
40+
- offline
41+
- mkdocs-autoapi:
42+
autoapi_dir: ./
43+
autoapi_add_nav_entry: Reference
44+
autoapi_ignore:
45+
- .*
46+
- docs/**/*
47+
- tests/**/*
48+
- tools/**/*
49+
- stubs/**/* # mocha fix
50+
- ./**/pythonrc.py # houdini fix
51+
- .*/**/*
52+
- ./*.py
53+
- mkdocstrings:
54+
handlers:
55+
python:
56+
paths:
57+
- ./
58+
- client/*
59+
- server/*
60+
- services/*
61+
- minify:
62+
minify_html: true
63+
minify_js: true
64+
minify_css: true
65+
htmlmin_opts:
66+
remove_comments: true
67+
cache_safe: true
68+
- mike
69+
70+
hooks:
71+
- mkdocs_hooks.py

mkdocs_hooks.py

Lines changed: 194 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,194 @@
1+
import os
2+
from pathlib import Path
3+
from shutil import rmtree
4+
import json
5+
import glob
6+
import logging
7+
8+
TMP_FILE = "./missing_init_files.json"
9+
NFILES = []
10+
11+
# -----------------------------------------------------------------------------
12+
13+
14+
class ColorFormatter(logging.Formatter):
15+
grey = "\x1b[38;20m"
16+
green = "\x1b[32;20m"
17+
yellow = "\x1b[33;20m"
18+
red = "\x1b[31;20m"
19+
bold_red = "\x1b[31;1m"
20+
reset = "\x1b[0m"
21+
fmt = (
22+
"%(asctime)s - %(name)s - %(levelname)s - %(message)s " # noqa
23+
"(%(filename)s:%(lineno)d)"
24+
)
25+
26+
FORMATS = {
27+
logging.DEBUG: grey + fmt + reset,
28+
logging.INFO: green + fmt + reset,
29+
logging.WARNING: yellow + fmt + reset,
30+
logging.ERROR: red + fmt + reset,
31+
logging.CRITICAL: bold_red + fmt + reset,
32+
}
33+
34+
def format(self, record):
35+
log_fmt = self.FORMATS.get(record.levelno)
36+
formatter = logging.Formatter(log_fmt)
37+
return formatter.format(record)
38+
39+
40+
ch = logging.StreamHandler()
41+
ch.setFormatter(ColorFormatter())
42+
43+
logging.basicConfig(
44+
level=logging.INFO,
45+
handlers=[ch],
46+
)
47+
48+
49+
# -----------------------------------------------------------------------------
50+
51+
52+
def create_init_file(dirpath, msg):
53+
global NFILES
54+
ini_file = f"{dirpath}/__init__.py"
55+
Path(ini_file).touch()
56+
NFILES.append(ini_file)
57+
logging.info(f"{msg}: created '{ini_file}'")
58+
59+
60+
def create_parent_init_files(dirpath: str, rootpath: str, msg: str):
61+
parent_path = dirpath
62+
while parent_path != rootpath:
63+
parent_path = os.path.dirname(parent_path)
64+
parent_init = os.path.join(parent_path, "__init__.py")
65+
if not os.path.exists(parent_init):
66+
create_init_file(parent_path, msg)
67+
else:
68+
break
69+
70+
71+
def add_missing_init_files(*roots, msg=""):
72+
"""
73+
This function takes in one or more root directories as arguments and scans
74+
them for Python files without an `__init__.py` file. It generates a JSON
75+
file named `missing_init_files.json` containing the paths of these files.
76+
77+
Args:
78+
*roots: Variable number of root directories to scan.
79+
80+
Returns:
81+
None
82+
"""
83+
84+
for root in roots:
85+
if not os.path.exists(root):
86+
continue
87+
rootpath = os.path.abspath(root)
88+
for dirpath, dirs, files in os.walk(rootpath):
89+
if "__init__.py" in files:
90+
continue
91+
92+
if "." in dirpath:
93+
continue
94+
95+
if (
96+
not glob.glob(os.path.join(dirpath, "*.py"))
97+
and "vendor" not in dirpath
98+
):
99+
continue
100+
101+
create_init_file(dirpath, msg)
102+
create_parent_init_files(dirpath, rootpath, msg)
103+
104+
with open(TMP_FILE, "w") as f:
105+
json.dump(NFILES, f)
106+
107+
108+
def remove_missing_init_files(msg=""):
109+
"""
110+
This function removes temporary `__init__.py` files created in the
111+
`add_missing_init_files()` function. It reads the paths of these files from
112+
a JSON file named `missing_init_files.json`.
113+
114+
Args:
115+
None
116+
117+
Returns:
118+
None
119+
"""
120+
global NFILES
121+
nfiles = []
122+
if os.path.exists(TMP_FILE):
123+
with open(TMP_FILE, "r") as f:
124+
nfiles = json.load(f)
125+
else:
126+
nfiles = NFILES
127+
128+
for file in nfiles:
129+
Path(file).unlink()
130+
logging.info(f"{msg}: removed {file}")
131+
132+
os.remove(TMP_FILE)
133+
NFILES = []
134+
135+
136+
def remove_pychache_dirs(msg=""):
137+
"""
138+
This function walks the current directory and removes all existing
139+
'__pycache__' directories.
140+
141+
Args:
142+
msg: An optional message to display during the removal process.
143+
144+
Returns:
145+
None
146+
"""
147+
nremoved = 0
148+
149+
for dirpath, dirs, files in os.walk("."):
150+
if "__pycache__" in dirs:
151+
pydir = Path(f"{dirpath}/__pycache__")
152+
rmtree(pydir)
153+
nremoved += 1
154+
logging.info(f"{msg}: removed '{pydir}'")
155+
156+
if not nremoved:
157+
logging.info(f"{msg}: no __pycache__ dirs found")
158+
159+
160+
# mkdocs hooks ----------------------------------------------------------------
161+
162+
163+
def on_startup(command, dirty):
164+
remove_pychache_dirs(msg="HOOK - on_startup")
165+
166+
167+
def on_pre_build(config):
168+
"""
169+
This function is called before the MkDocs build process begins. It adds
170+
temporary `__init__.py` files to directories that do not contain one, to
171+
make sure mkdocs doesn't ignore them.
172+
"""
173+
try:
174+
add_missing_init_files(
175+
"client",
176+
"server",
177+
"services",
178+
msg="HOOK - on_pre_build",
179+
)
180+
except BaseException as e:
181+
logging.error(e)
182+
remove_missing_init_files(
183+
msg="HOOK - on_post_build: cleaning up on error !"
184+
)
185+
raise
186+
187+
188+
def on_post_build(config):
189+
"""
190+
This function is called after the MkDocs build process ends. It removes
191+
temporary `__init__.py` files that were added in the `on_pre_build()`
192+
function.
193+
"""
194+
remove_missing_init_files(msg="HOOK - on_post_build")

pyproject.toml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# This file was generated by generate_docs.py.
2+
3+
[project]
4+
name = "ayon-resolve"
5+
version = "0.4.0"
6+
description = "Resolve addon for Ayon.\n"
7+
readme = "README.md"
8+
requires-python = ">=3.11"
9+
dependencies = [
10+
"tomlkit>=0.13.2",
11+
"requests>=2.32.3",
12+
"mkdocs-material>=9.6.7",
13+
"mkdocs-autoapi>=0.4.0",
14+
"mkdocstrings-python>=1.16.2",
15+
"mkdocstrings-shell>=1.0.2",
16+
"mkdocs-minify-plugin>=0.8.0",
17+
"markdown-checklist>=0.4.4",
18+
"mdx-gh-links>=0.4",
19+
"pymdown-extensions>=10.14.3",
20+
"mike>=2.1.3",
21+
]

0 commit comments

Comments
 (0)