From fed67dc4e8e09208c1b747ad97dc5eca7ca27afd Mon Sep 17 00:00:00 2001 From: Michael Wagner Date: Wed, 15 Jan 2025 12:43:21 +0100 Subject: [PATCH 1/3] Add `__main__.py` for package entry point and debugging support - Enable running the package with `python -m MY_PACKAGE` by adding `__main__.py`. - Enable debugging by providing a clear entry point for the application. --- .../src/{{cookiecutter.project_slug}}/__main__.py | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 {{cookiecutter.project_slug}}/src/{{cookiecutter.project_slug}}/__main__.py diff --git a/{{cookiecutter.project_slug}}/src/{{cookiecutter.project_slug}}/__main__.py b/{{cookiecutter.project_slug}}/src/{{cookiecutter.project_slug}}/__main__.py new file mode 100644 index 000000000..d5cf0fd24 --- /dev/null +++ b/{{cookiecutter.project_slug}}/src/{{cookiecutter.project_slug}}/__main__.py @@ -0,0 +1,4 @@ +from .cli import app + +if __name__ == "__main__": + app() From 7f1d0b3b2e71e95c83eacdd8ab927b2cfbcbc991 Mon Sep 17 00:00:00 2001 From: Michael Wagner Date: Wed, 15 Jan 2025 13:22:20 +0100 Subject: [PATCH 2/3] Remove trailing whitespaces --- {{cookiecutter.project_slug}}/pyproject.toml | 2 +- .../src/{{cookiecutter.project_slug}}/cli.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/{{cookiecutter.project_slug}}/pyproject.toml b/{{cookiecutter.project_slug}}/pyproject.toml index 9f74ba2d7..843ca609d 100644 --- a/{{cookiecutter.project_slug}}/pyproject.toml +++ b/{{cookiecutter.project_slug}}/pyproject.toml @@ -18,7 +18,7 @@ classifiers = [ ] license = {text = "{{cookiecutter.open_source_license}}"} dependencies = [ - {% if cookiecutter.command_line_interface.lower() == "typer" -%} +{% if cookiecutter.command_line_interface.lower() == "typer" -%} "typer" {%- endif %} ] diff --git a/{{cookiecutter.project_slug}}/src/{{cookiecutter.project_slug}}/cli.py b/{{cookiecutter.project_slug}}/src/{{cookiecutter.project_slug}}/cli.py index 0b83d39fa..f61968fb7 100644 --- a/{{cookiecutter.project_slug}}/src/{{cookiecutter.project_slug}}/cli.py +++ b/{{cookiecutter.project_slug}}/src/{{cookiecutter.project_slug}}/cli.py @@ -14,7 +14,7 @@ def main(): console.print("Replace this message by putting your code into " "{{cookiecutter.project_slug}}.cli.main") console.print("See Typer documentation at https://typer.tiangolo.com/") - + if __name__ == "__main__": From 1084be2422deb532c8b300a58af9b07bd05abb86 Mon Sep 17 00:00:00 2001 From: Michael Wagner Date: Wed, 15 Jan 2025 14:42:31 +0100 Subject: [PATCH 3/3] Remove __main__.py when CLI is set to None --- hooks/post_gen_project.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/hooks/post_gen_project.py b/hooks/post_gen_project.py index 48df5c13d..64bf5e301 100644 --- a/hooks/post_gen_project.py +++ b/hooks/post_gen_project.py @@ -10,6 +10,7 @@ if 'no' in '{{ cookiecutter.command_line_interface|lower }}': pathlib.Path('src', '{{ cookiecutter.project_slug }}', 'cli.py').unlink() - + pathlib.Path('src', '{{ cookiecutter.project_slug }}', '__main__.py').unlink() + if 'Not open source' == '{{ cookiecutter.open_source_license }}': pathlib.Path('LICENSE').unlink()