Skip to content

Make template usable for writing python libraries #21

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion cookiecutter.json
Original file line number Diff line number Diff line change
@@ -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"
}
7 changes: 7 additions & 0 deletions hooks/post_gen_project.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
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)
Expand All @@ -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 }}'
main_file_path = os.path.join(repo_name, '__main__.py')
if not (is_lib == "y" or is_lib == "Y"):
os.remove(main_file_path)

SUCCESS = "\x1b[1;32m"
INFO = "\x1b[1;33m"
Expand All @@ -21,6 +27,7 @@ def set_python_version():

def main():
set_python_version()
remove_main_if_lib()
print(SUCCESS + "Project successfully initialized" + TERMINATOR)


Expand Down