-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpost_gen_project.py
85 lines (66 loc) · 2.53 KB
/
post_gen_project.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
"""This module is called after project is created."""
import os
from pathlib import Path
from shutil import move, rmtree
# Project root directory
PROJECT_DIRECTORY = Path.cwd().absolute()
PROJECT_NAME = "{{ cookiecutter.project_name }}"
PROJECT_MODULE = "{{ cookiecutter.project_name }}"
# Values to generate correct license
LICENSE = "{{ cookiecutter.license }}"
ORGANIZATION = "{{ cookiecutter.organization }}"
# Values to generate github repository
GIT_HOST = "{{ cookiecutter.git_host }}"
USER_NAME = "{{ cookiecutter.user_name }}"
# Docs
DOCS_ENGINE = "{{ cookiecutter.docs }}"
licenses_dict = {
"MIT": "mit",
"BSD-3-Clause": "bsd3",
"GPL-3.0-only": "gpl3",
"Apache-2.0": "apache",
}
def generate_license(directory: Path, license_choice: str) -> None:
"""Generate license file for the project.
Args:
directory: path to the project directory
license_choice: chosen license
"""
move(
str(directory / "_licenses" / f"{license_choice}.md"),
str(directory / "LICENSE.md"),
)
rmtree(str(directory / "_licenses"))
def remove_unused_files(directory: Path) -> None:
"""Remove unused files.
Args:
directory: path to the project directory
module_name: project module name
need_to_remove_cli: flag for removing CLI related files
"""
files_to_delete: list[Path] = []
if GIT_HOST == "GitHub":
gitlab_path = os.path.join(directory, ".gitlab-ci.yml")
if os.path.exists(gitlab_path):
files_to_delete.append(gitlab_path)
if GIT_HOST == "GitLab":
files_to_delete.append(os.path.join(directory, ".github"))
if DOCS_ENGINE == "mkdocs":
files_to_delete.append(os.path.join(directory, "docs", "_templates"))
files_to_delete.append(os.path.join(directory, "docs", "conf.py"))
if DOCS_ENGINE == "sphinx":
files_to_delete.append(os.path.join(directory, "mkdocs.yml"))
files_to_delete.append(os.path.join(directory, "docs", "css"))
files_to_delete.append(os.path.join(directory, "docs", ".pages"))
files_to_delete.append(os.path.join(directory, "docs", ".overrides"))
files_to_delete.append(os.path.join(directory, "docs", "gen_ref_pages.py"))
for path in files_to_delete:
if os.path.isdir(path):
rmtree(path)
else:
os.remove(path)
def main() -> None:
generate_license(directory=PROJECT_DIRECTORY, license_choice=licenses_dict[LICENSE])
remove_unused_files(directory=PROJECT_DIRECTORY)
if __name__ == "__main__":
main()