Skip to content

Commit 79621f0

Browse files
committed
Replace shell with python
1 parent 034596c commit 79621f0

5 files changed

Lines changed: 44 additions & 32 deletions

File tree

.pre-commit-hooks.yaml

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,10 @@
11
- id: sphinx-apidoc
22
name: Update Sphinx Documentation
33
description: Fails, if documentation is not complete and updates the sphinx doc.
4-
entry: sphinx_apidoc.sh
4+
entry: sphinx_apidoc
55
args: [--force, --no-toc, -o docs, src]
66
always_run: true
77
files: '^$'
88
pass_filenames: false
9-
language: script
10-
11-
- id: activate-venv
12-
name: Activate venv
13-
description: Activate the virtual environment
14-
entry: run_command.sh
15-
args: [.venv\Scripts\activate]
16-
always_run: true
17-
files: '^$'
18-
pass_filenames: false
19-
language: script
9+
language: python
10+
additional_dependencies: [sphinx]

pyproject.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[project]
2+
name = "sphinx_apidoc"
3+
version = "0.12.0"
4+
5+
[build-system]
6+
requires = ["hatchling"]
7+
build-backend = "hatchling.build"

run_command.sh

Lines changed: 0 additions & 3 deletions
This file was deleted.

sphinx_apidoc.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#!/usr/bin/env python
2+
import subprocess
3+
import sys
4+
5+
6+
def get_git_diff():
7+
return subprocess.run(
8+
["git", "diff", "*.rst"], capture_output=True, text=True
9+
).stdout
10+
11+
12+
def get_git_status():
13+
return subprocess.run(
14+
["git", "status", "-s"], capture_output=True, text=True
15+
).stdout
16+
17+
18+
def main():
19+
prediff = get_git_diff()
20+
prestatus = get_git_status()
21+
22+
subprocess.run(["sphinx-apidoc"] + sys.argv[1:])
23+
24+
postdiff = get_git_diff()
25+
poststatus = get_git_status()
26+
27+
if prediff == postdiff and prestatus == poststatus:
28+
sys.exit(0)
29+
else:
30+
sys.exit(1)
31+
32+
33+
if __name__ == "__main__":
34+
main()

sphinx_apidoc.sh

Lines changed: 0 additions & 17 deletions
This file was deleted.

0 commit comments

Comments
 (0)