Skip to content

Commit 4be472b

Browse files
authored
Merge pull request #24
develop
2 parents bb9c25b + df787be commit 4be472b

17 files changed

+166
-374
lines changed

hooks/post_gen_project.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,23 @@
11
#!/usr/bin/env python
22
import json
3+
import shutil
4+
import stat
35
from pathlib import Path
6+
from typing import Any
7+
from typing import Callable
8+
9+
10+
REMOVE_PATHS: list[str] = [
11+
"{% if cookiecutter.platform_provider != github %}.github{% endif %}",
12+
"{% if cookiecutter.platform_provider != gitlab %}.gitlab-ci.yml{% endif %}",
13+
"{% if cookiecutter.platform_provider != bitbucket %}.bitbucket-pipelines.yml{% endif %}",
14+
]
15+
16+
17+
def post_gen_project() -> None:
18+
"""Run post-generation tasks."""
19+
reindent_cookiecutter_json()
20+
remove_undesired_files()
421

522

623
def reindent_cookiecutter_json():
@@ -20,5 +37,30 @@ def reindent_cookiecutter_json():
2037
io.write("\n")
2138

2239

40+
def remove_undesired_files() -> None:
41+
"""Removes any files that are not desired in the generated project based on the cookiecutter.json.
42+
43+
This is done to avoid issues that tend to arise when the name of the template file contains a conditional.
44+
"""
45+
for path in REMOVE_PATHS:
46+
if path == "":
47+
continue
48+
49+
path: Path = Path.cwd() / path
50+
if path.is_dir():
51+
shutil.rmtree(path, onerror=remove_readonly)
52+
else:
53+
path.unlink()
54+
55+
56+
def remove_readonly(func: Callable[[str], Any], path: str, _: Any) -> None:
57+
"""Clears the readonly bit and attempts to call the provided function.
58+
59+
This is passed to shutil.rmtree as the onerror kwarg.
60+
"""
61+
Path(path).chmod(stat.S_IWRITE)
62+
func(path)
63+
64+
2365
if __name__ == "__main__":
2466
reindent_cookiecutter_json()

scripts/generate-demo.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
"""Python script for generating a demo project."""
22
import sys
3-
from functools import partial
43
from pathlib import Path
54
from typing import Annotated
65

scripts/prepare-github-release.py

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

scripts/publish-github-release.py

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

{{cookiecutter.project_name}}/{% if cookiecutter.repository_provider == 'github' %}.github{% endif %}/dependabot.yml renamed to {{cookiecutter.project_name}}/.github/dependabot.yml

File renamed without changes.

{{cookiecutter.project_name}}/{% if cookiecutter.repository_provider == 'github' %}.github{% endif %}/workflows/.python-version renamed to {{cookiecutter.project_name}}/.github/workflows/.python-version

File renamed without changes.

{{cookiecutter.project_name}}/{% if cookiecutter.repository_provider == 'github' %}.github{% endif %}/workflows/build-docs.yml renamed to {{cookiecutter.project_name}}/.github/workflows/build-docs.yml

File renamed without changes.

{{cookiecutter.project_name}}/{% if cookiecutter.repository_provider == 'github' %}.github{% endif %}/workflows/lint-python.yml renamed to {{cookiecutter.project_name}}/.github/workflows/lint-python.yml

File renamed without changes.

{{cookiecutter.project_name}}/{% if cookiecutter.repository_provider == 'github' %}.github{% endif %}/workflows/prepare-release.yml renamed to {{cookiecutter.project_name}}/.github/workflows/prepare-release.yml

File renamed without changes.

{{cookiecutter.project_name}}/{% if cookiecutter.repository_provider == 'github' %}.github{% endif %}/workflows/release-python.yml renamed to {{cookiecutter.project_name}}/.github/workflows/release-python.yml

File renamed without changes.

0 commit comments

Comments
 (0)