Skip to content

Commit dac1cc7

Browse files
committed
feat: add in post_gen_project.py from hypermodern cookiecutter hooks
1 parent 128cfd5 commit dac1cc7

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

hooks/post_gen_project.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/usr/bin/env python
2+
import json
3+
from pathlib import Path
4+
5+
6+
def reindent_cookiecutter_json():
7+
"""Indent .cookiecutter.json using two spaces.
8+
9+
The jsonify extension distributed with Cookiecutter uses an indentation
10+
width of four spaces. This conflicts with the default indentation width of
11+
Prettier for JSON files. Prettier is run as a pre-commit hook in CI.
12+
"""
13+
path = Path(".cookiecutter.json")
14+
15+
with path.open() as io:
16+
data = json.load(io)
17+
18+
with path.open(mode="w") as io:
19+
json.dump(data, io, sort_keys=True, indent=2)
20+
io.write("\n")
21+
22+
23+
if __name__ == "__main__":
24+
reindent_cookiecutter_json()

0 commit comments

Comments
 (0)