diff --git a/cookiecutter.json b/cookiecutter.json index 4ea59c0..8b9867d 100644 --- a/cookiecutter.json +++ b/cookiecutter.json @@ -1,4 +1,5 @@ { "project_name": "Best Practices", - "repo_name": "{{ cookiecutter.project_name.lower().replace(' ', '_').replace('-', '_') }}" + "repo_name": "{{ cookiecutter.project_name.lower().replace(' ', '_').replace('-', '_') }}", + "binary":"y" } diff --git a/hooks/post_gen_project.py b/hooks/post_gen_project.py index afcc8ba..058f92f 100644 --- a/hooks/post_gen_project.py +++ b/hooks/post_gen_project.py @@ -1,9 +1,10 @@ import os import sys +repo_name = '{{cookiecutter.repo_name }}' def set_python_version(): - python_version = str(sys.version_info.major) + "." + str(sys.version_info.minor) + python_version = f"{str(sys.version_info.major)}.{str(sys.version_info.minor)}" file_names = ["Dockerfile", "Pipfile", ".github/workflows/test.yml"] for file_name in file_names: @@ -13,6 +14,11 @@ def set_python_version(): with open(file_name, "w") as f: f.write(contents) +def remove_main_if_lib(): + is_lib = '{{ cookiecutter.binary }}' + if is_lib not in {"y", "Y"}: + main_file_path = os.path.join(repo_name, '__main__.py') + os.remove(main_file_path) SUCCESS = "\x1b[1;32m" INFO = "\x1b[1;33m" @@ -21,7 +27,8 @@ def set_python_version(): def main(): set_python_version() - print(SUCCESS + "Project successfully initialized" + TERMINATOR) + remove_main_if_lib() + print(f"{SUCCESS}Project successfully initialized{TERMINATOR}") if __name__ == "__main__":