Skip to content

Commit d01e069

Browse files
committed
Added argument to remove __main__.py file
1 parent 5a88822 commit d01e069

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

cookiecutter.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
22
"project_name": "Best Practices",
3-
"repo_name": "{{ cookiecutter.project_name.lower().replace(' ', '_').replace('-', '_') }}"
3+
"repo_name": "{{ cookiecutter.project_name.lower().replace(' ', '_').replace('-', '_') }}",
4+
"binary":"y"
45
}

hooks/post_gen_project.py

+7
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ def set_python_version():
1313
with open(file_name, "w") as f:
1414
f.write(contents)
1515

16+
def remove_main_if_lib():
17+
is_lib = '{{ cookiecutter.binary }}'
18+
main_file_path = os.path.join('{{ cookiecutter.repo_name }}', '__main__.py')
19+
if not (is_lib == "y" or is_lib == "Y"):
20+
os.remove(main_file_path)
21+
print(main_file_path)
1622

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

2228
def main():
2329
set_python_version()
30+
remove_main_if_lib()
2431
print(SUCCESS + "Project successfully initialized" + TERMINATOR)
2532

2633

0 commit comments

Comments
 (0)