Skip to content

Commit 8ff2235

Browse files
committed
chore: enhance development tooling and documentation
- Rewrite gen-init.sh to use tangerine for better template management - Improve TOML linting with tombi support and better formatting - Add numerous Python documentation inventory references - Add tangerine template markers to __init__.py files
1 parent d603f30 commit 8ff2235

5 files changed

Lines changed: 95 additions & 16 deletions

File tree

.cspell.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
"scrapy",
4747
"sdist",
4848
"strftime",
49+
"tombi",
4950
"trimesh",
5051
"unshallow",
5152
"venv",

template/.config/copier/mise/tasks/gen-init.sh

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,36 @@ set -o errexit
55
set -o nounset
66
set -o pipefail
77

8-
CODE="import lazy_loader as lazy
8+
function has() {
9+
type "$@" &> /dev/null
10+
}
911

10-
__getattr__, __dir__, __all__ = lazy.attach_stub(__name__, __file__)"
11-
N_LINES=$(echo "$CODE" | wc --lines)
12+
TEMPLATE="\
13+
# tangerine-start: lazy-loader.py.jinja
14+
import lazy_loader as lazy
15+
16+
__getattr__, __dir__, __all__ = lazy.attach_stub(__name__, __file__)
17+
# tangerine-end
18+
"
1219

1320
git_root=$(git rev-parse --show-toplevel)
14-
readarray -t files < <(fd --fixed-strings --type file '__init__.pyi' "$git_root/src/")
15-
for file in "${files[@]}"; do
16-
file="${file/%".pyi"/".py"}"
17-
if [[ ! -f $file ]]; then
18-
echo "$CODE" > "$file"
19-
continue
20-
fi
21-
last_lines=$(tail --lines="$N_LINES" "$file")
22-
if ! diff <(echo "$last_lines") <(echo "$CODE") &> /dev/null; then
23-
echo "$CODE" >> "$file"
24-
fi
25-
done
21+
src_dir="$git_root/src"
22+
if [[ -d $src_dir ]]; then
23+
find "$src_dir" -name '__init__.pyi' -type f -print0 |
24+
while IFS= read -d '' -r file; do
25+
file="${file/%'.pyi'/'.py'}"
26+
if has tangerine; then
27+
if [[ ! -f $file ]]; then
28+
tangerine <<< "$TEMPLATE" > "$file"
29+
else
30+
tangerine "$file"
31+
fi
32+
else
33+
if [[ ! -f $file ]]; then
34+
echo -n "$TEMPLATE" > "$file"
35+
else
36+
: # skip existing files
37+
fi
38+
fi
39+
done
40+
fi

template/.config/copier/mise/tasks/lint-toml.sh

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,22 @@ set -o errexit
55
set -o nounset
66
set -o pipefail
77

8-
sort-toml .ruff.toml pyproject.toml
8+
function has() {
9+
type "$@" &> /dev/null
10+
}
11+
12+
function pretty-toml() {
13+
if has toml-sort; then
14+
toml-sort --in-place --all "$@"
15+
sed --expression='s/# :schema /#:schema /g' --in-place "$@"
16+
fi
17+
if has tombi; then
18+
tombi format "$@"
19+
fi
20+
}
21+
22+
pretty-toml .ruff.toml pyproject.toml
23+
24+
if has tombi; then
25+
tombi lint
26+
fi

template/.config/copier/mkdocs.yaml.jinja

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,50 @@ plugins:
114114
handlers:
115115
python:
116116
inventories:
117+
- https://autoregistry.readthedocs.io/en/stable/objects.inv
118+
- https://beartype.github.io/plum/objects.inv
119+
- https://beartype.readthedocs.io/en/stable/objects.inv
120+
- https://cherries.readthedocs.io/en/stable/objects.inv
121+
- https://chex.readthedocs.io/en/stable/objects.inv
122+
- https://cyclopts.readthedocs.io/en/stable/objects.inv
123+
- https://docs.jax.dev/en/latest/objects.inv
124+
- https://docs.kidger.site/equinox/objects.inv
125+
- https://docs.kidger.site/jaxtyping/objects.inv
126+
- https://docs.kidger.site/wadler_lindig/objects.inv
127+
- https://docs.pola.rs/api/python/stable/objects.inv
128+
- https://docs.pydantic.dev/latest/objects.inv
117129
- https://docs.python.org/3/objects.inv
130+
- https://docs.pytorch.org/docs/stable/objects.inv
131+
- https://docs.pyvista.org/objects.inv
132+
- https://einops.rocks/objects.inv
133+
- https://etils.readthedocs.io/en/stable/objects.inv
134+
- https://felupe.readthedocs.io/en/stable/objects.inv
135+
- https://gitpython.readthedocs.io/en/stable/objects.inv
136+
- https://glom.readthedocs.io/en/stable/objects.inv
137+
- https://grantjenks.com/docs/sortedcollections/objects.inv
138+
- https://grantjenks.com/docs/sortedcontainers/objects.inv
139+
- https://ipctk.xyz/objects.inv
140+
- https://jcristharif.com/msgspec/objects.inv
141+
- https://jinja.palletsprojects.com/en/stable/objects.inv
142+
- https://joblib.readthedocs.io/en/stable/objects.inv
143+
- https://liblaf-apple.readthedocs.io/en/stable/objects.inv
144+
- https://liblaf-grapes.readthedocs.io/en/stable/objects.inv
145+
- https://loguru.readthedocs.io/en/stable/objects.inv
146+
- https://matplotlib.org/stable/objects.inv
147+
- https://melon.readthedocs.io/en/stable/objects.inv
148+
- https://networkx.org/documentation/stable/objects.inv
149+
- https://numpy.org/doc/stable/objects.inv
150+
- https://nvidia.github.io/warp/objects.inv
151+
- https://platformdirs.readthedocs.io/en/stable/objects.inv
152+
- https://pydicom.github.io/pydicom/stable/objects.inv
153+
- https://pymeshfix.pyvista.org/objects.inv
154+
- https://pytorch3d.readthedocs.io/en/latest/objects.inv
155+
- https://rich.readthedocs.io/en/stable/objects.inv
156+
- https://toolz.readthedocs.io/en/stable/objects.inv
157+
- https://trimesh.org/objects.inv
158+
- https://typing-extensions.readthedocs.io/en/stable/objects.inv
159+
- https://wrapt.readthedocs.io/en/latest/objects.inv
160+
- https://www.attrs.org/en/stable/objects.inv
118161
options:
119162
# General
120163
backlinks: tree
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# tangerine-start: lazy-loader.py.jinja
12
import lazy_loader as lazy
23

34
__getattr__, __dir__, __all__ = lazy.attach_stub(__name__, __file__)
5+
# tangerine-end

0 commit comments

Comments
 (0)