11"""This module is called after project is created."""
2-
3- from typing import Callable , List
2+ from typing import List
43
54import textwrap
65from pathlib import Path
1918# Values to generate github repository
2019GITHUB_USER = "{{ cookiecutter.github_name }}"
2120
22- licenses = {
21+ licences_dict = {
2322 "MIT" : "mit" ,
2423 "BSD-3" : "bsd3" ,
2524 "GNU GPL v3.0" : "gpl3" ,
2625 "Apache Software License 2.0" : "apache" ,
2726}
2827
2928
30- def generate_license () -> None :
31- """Generate license file for the project."""
32- move (f"{ PROJECT_DIRECTORY } /_licences/{ licenses [LICENSE ]} .txt" , f"{ PROJECT_DIRECTORY } /LICENSE" )
33- rmtree (f"{ PROJECT_DIRECTORY } /_licences/" )
29+ def generate_license (directory : Path , licence : str ) -> None :
30+ """Generate license file for the project.
31+
32+ Args:
33+ directory: path to the project directory
34+ licence: chosen licence
35+ """
36+ move (str (directory / "_licences" / f"{ licence } .txt" ), str (directory / "LICENSE" ))
37+ rmtree (str (directory / "_licences" ))
38+
3439
40+ def remove_unused_files (directory : Path , module_name : str , need_to_remove_cli : bool ) -> None :
41+ """Remove unused files.
3542
36- def remove_unused_files () -> None :
37- """Remove unused files."""
43+ Args:
44+ directory: path to the project directory
45+ module_name: project module name
46+ need_to_remove_cli: flag for removing CLI related files
47+ """
3848 files_to_delete : List [Path ] = []
3949
4050 def _cli_specific_files () -> List [Path ]:
41- return [Path ( f" { PROJECT_DIRECTORY } / { PROJECT_MODULE } / __main__.py") ]
51+ return [directory / module_name / " __main__.py" ]
4252
43- if CREATE_EXAMPLE_TEMPLATE != "cli" :
53+ if need_to_remove_cli :
4454 files_to_delete .extend (_cli_specific_files ())
4555
4656 for path in files_to_delete :
4757 path .unlink ()
4858
4959
50- def print_futher_instuctions () -> None :
51- """Show user what to do next after project creation."""
60+ def print_futher_instuctions (project_name : str , github : str ) -> None :
61+ """Show user what to do next after project creation.
62+
63+ Args:
64+ project_name: current project name
65+ github: GitHub username
66+ """
5267 message = f"""
53- Your project { PROJECT_NAME } is created.
68+ Your project { project_name } is created.
5469
5570 1) Now you can start working on it:
5671
57- $ cd { PROJECT_NAME } && git init
72+ $ cd { project_name } && git init
5873
5974 2) If you don't have Poetry installed run:
6075
@@ -74,17 +89,21 @@ def print_futher_instuctions() -> None:
7489 $ git add .
7590 $ git commit -m ":tada: Initial commit"
7691 $ git branch -M main
77- $ git remote add origin https://github.com/{ GITHUB_USER } /{ PROJECT_NAME } .git
92+ $ git remote add origin https://github.com/{ github } /{ project_name } .git
7893 $ git push -u origin main
7994 """
8095 print (textwrap .dedent (message ))
8196
8297
83- post_functions : List [Callable [[], None ]] = [
84- generate_license ,
85- remove_unused_files ,
86- print_futher_instuctions ,
87- ]
98+ def main () -> None :
99+ generate_license (directory = PROJECT_DIRECTORY , licence = licences_dict [LICENSE ])
100+ remove_unused_files (
101+ directory = PROJECT_DIRECTORY ,
102+ module_name = PROJECT_MODULE ,
103+ need_to_remove_cli = CREATE_EXAMPLE_TEMPLATE != "cli" ,
104+ )
105+ print_futher_instuctions (project_name = PROJECT_NAME , github = GITHUB_USER )
106+
88107
89- for fn in post_functions :
90- fn ()
108+ if __name__ == "__main__" :
109+ main ()
0 commit comments