A programming framework for agentic AI
Add cookiecutter template for new package (#426)
Jack Gerrits67003593a08c
diff --git a/python/README.md b/python/README.mdindex 98b45a09e..25c4c957d 100644--- a/python/README.md+++ b/python/README.md@@ -41,3 +41,13 @@ source .venv/bin/activate> [!NOTE]> These need to be run in the virtual environment.++### Create new package++To create a new package, run:++```sh+uv sync+source .venv/bin/activate+cookiecutter ./templates/new-package/+```diff --git a/python/pyproject.toml b/python/pyproject.tomlindex 4a81df6af..5035f0f45 100644--- a/python/pyproject.toml+++ b/python/pyproject.toml@@ -13,7 +13,8 @@ dev-dependencies = ["rich","polars","pytest_mock",- "poethepoet"+ "poethepoet",+ "packaging"][tool.uv.sources]diff --git a/python/templates/new-package/cookiecutter.json b/python/templates/new-package/cookiecutter.jsonnew file mode 100644index 000000000..956f42f74--- /dev/null+++ b/python/templates/new-package/cookiecutter.json@@ -0,0 +1,8 @@+{+ "package_name": "my-project",+ "version": "0.1.0dev",+ "description": "My package description",+ "depends_on_core": false,+ "__final_destination": "../packages",+ "__project_slug": "{{ cookiecutter.package_name.replace(' ', '_').replace('-', '_') }}"+}\ No newline at end of filediff --git a/python/templates/new-package/hooks/post_gen_project.py b/python/templates/new-package/hooks/post_gen_project.pynew file mode 100644index 000000000..491d1284c--- /dev/null+++ b/python/templates/new-package/hooks/post_gen_project.py@@ -0,0 +1,7 @@+import os+import shutil++source_dir = os.getcwd()+target_dir = "{{ cookiecutter.__final_destination }}"++shutil.move(source_dir, target_dir)diff --git a/python/templates/new-package/hooks/pre_gen_project.py b/python/templates/new-package/hooks/pre_gen_project.pynew file mode 100644index 000000000..188546624--- /dev/null+++ b/python/templates/new-package/hooks/pre_gen_project.py@@ -0,0 +1,22 @@+import re+import sys+from packaging import version++MODULE_REGEX = r'^[a-zA-Z][\-a-zA-Z0-9]+$'++package_name = '{{ cookiecutter.package_name }}'++at_least_one_error = False+if not re.match(MODULE_REGEX, package_name):+ print(f'ERROR: "{package_name}" must use kebab case')+ at_least_one_error = True++packaging_version = '{{ cookiecutter.version }}'++# Check version format using version.VERSION_PATTERN+if not re.match(version.VERSION_PATTERN, packaging_version):+ print(f'ERROR: "{packaging_version}" is not a valid version string')+ at_least_one_error = True++if at_least_one_error:+ sys.exit(1)diff --git a/python/templates/new-package/{{cookiecutter.package_name}}/README.md b/python/templates/new-package/{{cookiecutter.package_name}}/README.mdnew file mode 100644index 000000000..cb5c10732--- /dev/null+++ b/python/templates/new-package/{{cookiecutter.package_name}}/README.md@@ -0,0 +1 @@+# {{cookiecutter.package_name}}diff --git a/python/templates/new-package/{{cookiecutter.package_name}}/pyproject.toml b/python/templates/new-package/{{cookiecutter.package_name}}/pyproject.tomlnew file mode 100644index 000000000..6f04dac59--- /dev/null+++ b/python/templates/new-package/{{cookiecutter.package_name}}/pyproject.toml@@ -0,0 +1,42 @@+[build-system]+requires = ["hatchling"]+build-backend = "hatchling.build"++[project]+name = "{{ cookiecutter.package_name }}"+version = "{{ cookiecutter.version }}"+description = "{{ cookiecutter.description }}"+readme = "README.md"+requires-python = ">=3.10"+classifiers = [+ "Programming Language :: Python :: 3",+ "License :: OSI Approved :: MIT License",+ "Operating System :: OS Independent",+]+dependencies = [+{%- if cookiecutter.depends_on_core -%}+"autogen-core",+{% endif %}+]++[tool.uv]+dev-dependencies = []+++[tool.ruff]+extend = "../../pyproject.toml"+include = ["src/**", "tests/*.py"]++[tool.pyright]+extend = "../../pyproject.toml"+include = ["src", "tests"]++[tool.pytest.ini_options]+minversion = "6.0"+testpaths = ["tests"]++[tool.poe]+include = "../../shared_tasks.toml"++[tool.poe.tasks]+test = "pytest -n auto"diff --git a/python/templates/new-package/{{cookiecutter.package_name}}/src/{{cookiecutter.__project_slug}}/__init__.py b/python/templates/new-package/{{cookiecutter.package_name}}/src/{{cookiecutter.__project_slug}}/__init__.pynew file mode 100644index 000000000..e69de29bbdiff --git a/python/templates/new-package/{{cookiecutter.package_name}}/src/{{cookiecutter.__project_slug}}/py.typed b/python/templates/new-package/{{cookiecutter.package_name}}/src/{{cookiecutter.__project_slug}}/py.typednew file mode 100644index 000000000..e69de29bbdiff --git a/python/templates/new-package/{{cookiecutter.package_name}}/tests/test_example.py b/python/templates/new-package/{{cookiecutter.package_name}}/tests/test_example.pynew file mode 100644index 000000000..1916ccc7c--- /dev/null+++ b/python/templates/new-package/{{cookiecutter.package_name}}/tests/test_example.py@@ -0,0 +1,2 @@+async def test_example() -> None:+ assert True\ No newline at end of file