diff --git a/.jules/bolt.md b/.jules/bolt.md new file mode 100644 index 0000000..47e7789 --- /dev/null +++ b/.jules/bolt.md @@ -0,0 +1,3 @@ +## 2025-05-14 - Initial Performance Audit +**Learning:** The project is a small Python template. Major overhead comes from `uv run` and `click` imports. +**Action:** Minimize overhead in CLI entry points and avoid unnecessary imports in hot paths. diff --git a/project/app.py b/project/app.py index 4e9ac38..2c424b5 100644 --- a/project/app.py +++ b/project/app.py @@ -1,16 +1,18 @@ -from click import command, option +from argparse import ArgumentParser -@command(context_settings={"help_option_names": ["-h", "--help"]}, help="Say hello") -@option("-n", "--name", default="World", help="Name", show_default=True) -def main(name: str = "World"): +def main(argv: list[str] | None = None): """ Say hello to the given name. Args: - name: the name to be greeted + argv: list of command line arguments """ - print(f"Hello {name}!") + parser = ArgumentParser(prog="app", description="Say hello", add_help=False) + parser.add_argument("-n", "--name", default="World", help="Name (default: World)") + parser.add_argument("-h", "--help", action="help", help="Show this message and exit.") + args = parser.parse_args(argv) + print(f"Hello {args.name}!") if __name__ == "__main__": diff --git a/pyproject.toml b/pyproject.toml index 7b1fdf4..201fb40 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -6,9 +6,7 @@ readme = "docs/README.md" authors = [{name = "Amr Abed", email = "amrabed@gmail.com"}] license = {text = "MIT"} requires-python = ">=3.12" -dependencies = [ - "click>=8.1.8", -] +dependencies = [] [project.scripts] app = "project.app:main" diff --git a/tests/test_app.py b/tests/test_app.py index c2a18e3..6d080ab 100644 --- a/tests/test_app.py +++ b/tests/test_app.py @@ -1,8 +1,17 @@ from pytest import main +from project.app import main as app_main +from io import StringIO +from contextlib import redirect_stdout -def test_main(): - pass +def test_main(monkeypatch): + with redirect_stdout(StringIO()) as out: + app_main(["-n", "Bolt"]) + assert out.getvalue().strip() == "Hello Bolt!" + + with redirect_stdout(StringIO()) as out: + app_main([]) + assert out.getvalue().strip() == "Hello World!" if __name__ == "__main__": diff --git a/uv.lock b/uv.lock index 720563f..c51ffeb 100644 --- a/uv.lock +++ b/uv.lock @@ -573,9 +573,6 @@ wheels = [ name = "project" version = "0.1.0" source = { editable = "." } -dependencies = [ - { name = "click" }, -] [package.dev-dependencies] dev = [ @@ -590,7 +587,6 @@ dev = [ ] [package.metadata] -requires-dist = [{ name = "click", specifier = ">=8.1.8" }] [package.metadata.requires-dev] dev = [