Skip to content
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

Make template usable for writing python libraries (Sourcery refactored) #22

Open
wants to merge 4 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"
}
11 changes: 9 additions & 2 deletions hooks/post_gen_project.py
Original file line number Diff line number Diff line change
@@ -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:
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 }}'
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"
Expand All @@ -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__":
Expand Down