Skip to content

Commit b844b77

Browse files
committed
Ensure cleanup_docs.py handles globs correctly
1 parent 2d03f75 commit b844b77

File tree

1 file changed

+23
-11
lines changed

1 file changed

+23
-11
lines changed

{{cookiecutter.package_name}}/scripts/cleanup_docs.py

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,28 @@
33
import shutil
44
from pathlib import Path
55

6-
paths = [
7-
"docs/build",
8-
"docs/source/api/modules.rst",
9-
"docs/source/api/{{cookiecutter.package_name}}*.rst",
6+
_LITERAL_PATHS = [
7+
Path("docs/build"),
8+
Path("docs/source/api/modules.rst"),
109
]
10+
_GLOB_PATTERNS = [
11+
("docs/source/api", "reposcan*.rst"),
12+
]
13+
14+
15+
def clean() -> None:
16+
"""Delete build artefacts and generated API documentation files."""
17+
for path in _LITERAL_PATHS:
18+
if path.exists():
19+
if path.is_dir():
20+
shutil.rmtree(path)
21+
else:
22+
path.unlink()
23+
24+
for parent_str, pattern in _GLOB_PATTERNS:
25+
for match in Path(parent_str).glob(pattern):
26+
match.unlink()
27+
1128

12-
for path in paths:
13-
p = Path(path)
14-
if p.exists():
15-
if p.is_dir():
16-
shutil.rmtree(p)
17-
else:
18-
p.unlink()
29+
if __name__ == "__main__":
30+
clean()

0 commit comments

Comments
 (0)