From dcfe0be02abb31870e02de12c1928ac26ac10e13 Mon Sep 17 00:00:00 2001 From: Ben Trachtenberg Date: Sat, 26 Apr 2025 23:04:34 -0500 Subject: [PATCH] updated readthedocs to python 3.12, added uv github actions --- cookiecutter.json | 2 +- hooks/post_gen_project.py | 8 ++ tests/test_cookies.py | 32 ++++++ .../.github/workflows/publish-to-pypi-uv.yml | 32 ++++++ .../.github/workflows/publish-to-pypi.yml | 2 +- .../workflows/test-coverage-lint-uv.yml | 106 ++++++++++++++++++ .../.readthedocs.yaml | 2 +- 7 files changed, 181 insertions(+), 3 deletions(-) create mode 100644 {{cookiecutter.git_repo_name}}/.github/workflows/publish-to-pypi-uv.yml create mode 100644 {{cookiecutter.git_repo_name}}/.github/workflows/test-coverage-lint-uv.yml diff --git a/cookiecutter.json b/cookiecutter.json index 37f8978..2ca6e96 100644 --- a/cookiecutter.json +++ b/cookiecutter.json @@ -47,7 +47,7 @@ "https" ], "__template_repo": "https://github.com/btr1975/cookiecutter-python-fastapi-openapi", - "__template_version": "2.0.1", + "__template_version": "2.0.2", "_new_lines": "\n", "_copy_without_render": [ "{{cookiecutter.__app_name}}/templates", diff --git a/hooks/post_gen_project.py b/hooks/post_gen_project.py index 1085703..ca110db 100644 --- a/hooks/post_gen_project.py +++ b/hooks/post_gen_project.py @@ -23,6 +23,13 @@ REMOVE_PATHS_UV = [ '{% if cookiecutter.package_manager == "uv" %}requirements.txt{% endif %}', '{% if cookiecutter.package_manager == "uv" %}requirements-dev.txt{% endif %}', + '{% if cookiecutter.package_manager == "uv" %}.github/workflows/publish-to-pypi.yml{% endif %}', + '{% if cookiecutter.package_manager == "uv" %}.github/workflows/test-coverage-lint.yml{% endif %}', +] + +REMOVE_PATHS_PIP = [ + '{% if cookiecutter.package_manager == "pip" %}.github/workflows/publish-to-pypi-uv.yml{% endif %}', + '{% if cookiecutter.package_manager == "pip" %}.github/workflows/test-coverage-lint-uv.yml{% endif %}', ] @@ -47,3 +54,4 @@ def remove_paths(paths_to_remove: List[str]) -> None: remove_paths(REMOVE_PATHS_PODMAN) remove_paths(REMOVE_PATHS_DOCKER) remove_paths(REMOVE_PATHS_UV) + remove_paths(REMOVE_PATHS_PIP) diff --git a/tests/test_cookies.py b/tests/test_cookies.py index a8d0806..486f602 100644 --- a/tests/test_cookies.py +++ b/tests/test_cookies.py @@ -15,6 +15,10 @@ def test_bake_project_api_only_podman(cookies, bake_project_api_only_podman): assert not result.project_path.joinpath("api_only", "static").is_dir() assert not result.project_path.joinpath("api_only", "templates").is_dir() assert not result.project_path.joinpath("api_only", "routers", "hello_world.py").is_file() + assert result.project_path.joinpath(".github", "workflows", "publish-to-pypi.yml").is_file() + assert result.project_path.joinpath(".github", "workflows", "test-coverage-lint.yml").is_file() + assert not result.project_path.joinpath(".github", "workflows", "publish-to-pypi-uv.yml").is_file() + assert not result.project_path.joinpath(".github", "workflows", "test-coverage-lint-uv.yml").is_file() def test_bake_project_uv_api_only_podman(cookies, bake_project_uv_api_only_podman): @@ -34,6 +38,10 @@ def test_bake_project_uv_api_only_podman(cookies, bake_project_uv_api_only_podma assert not result.project_path.joinpath("api_only", "static").is_dir() assert not result.project_path.joinpath("api_only", "templates").is_dir() assert not result.project_path.joinpath("api_only", "routers", "hello_world.py").is_file() + assert not result.project_path.joinpath(".github", "workflows", "publish-to-pypi.yml").is_file() + assert not result.project_path.joinpath(".github", "workflows", "test-coverage-lint.yml").is_file() + assert result.project_path.joinpath(".github", "workflows", "publish-to-pypi-uv.yml").is_file() + assert result.project_path.joinpath(".github", "workflows", "test-coverage-lint-uv.yml").is_file() def test_bake_project_api_only_docker(cookies, bake_project_api_only_docker): @@ -53,6 +61,10 @@ def test_bake_project_api_only_docker(cookies, bake_project_api_only_docker): assert not result.project_path.joinpath("api_only", "static").is_dir() assert not result.project_path.joinpath("api_only", "templates").is_dir() assert not result.project_path.joinpath("api_only", "routers", "hello_world.py").is_file() + assert result.project_path.joinpath(".github", "workflows", "publish-to-pypi.yml").is_file() + assert result.project_path.joinpath(".github", "workflows", "test-coverage-lint.yml").is_file() + assert not result.project_path.joinpath(".github", "workflows", "publish-to-pypi-uv.yml").is_file() + assert not result.project_path.joinpath(".github", "workflows", "test-coverage-lint-uv.yml").is_file() def test_bake_project_uv_api_only_docker(cookies, bake_project_uv_api_only_docker): @@ -72,6 +84,10 @@ def test_bake_project_uv_api_only_docker(cookies, bake_project_uv_api_only_docke assert not result.project_path.joinpath("api_only", "static").is_dir() assert not result.project_path.joinpath("api_only", "templates").is_dir() assert not result.project_path.joinpath("api_only", "routers", "hello_world.py").is_file() + assert not result.project_path.joinpath(".github", "workflows", "publish-to-pypi.yml").is_file() + assert not result.project_path.joinpath(".github", "workflows", "test-coverage-lint.yml").is_file() + assert result.project_path.joinpath(".github", "workflows", "publish-to-pypi-uv.yml").is_file() + assert result.project_path.joinpath(".github", "workflows", "test-coverage-lint-uv.yml").is_file() def test_bake_project_api_with_webpages_podman(cookies, bake_project_api_with_webpages_podman): @@ -91,6 +107,10 @@ def test_bake_project_api_with_webpages_podman(cookies, bake_project_api_with_we assert result.project_path.joinpath("api_with_webpages", "static").is_dir() assert result.project_path.joinpath("api_with_webpages", "templates").is_dir() assert result.project_path.joinpath("api_with_webpages", "routers", "hello_world.py").is_file() + assert result.project_path.joinpath(".github", "workflows", "publish-to-pypi.yml").is_file() + assert result.project_path.joinpath(".github", "workflows", "test-coverage-lint.yml").is_file() + assert not result.project_path.joinpath(".github", "workflows", "publish-to-pypi-uv.yml").is_file() + assert not result.project_path.joinpath(".github", "workflows", "test-coverage-lint-uv.yml").is_file() def test_bake_project_uv_api_with_webpages_podman(cookies, bake_project_uv_api_with_webpages_podman): @@ -110,6 +130,10 @@ def test_bake_project_uv_api_with_webpages_podman(cookies, bake_project_uv_api_w assert result.project_path.joinpath("api_with_webpages", "static").is_dir() assert result.project_path.joinpath("api_with_webpages", "templates").is_dir() assert result.project_path.joinpath("api_with_webpages", "routers", "hello_world.py").is_file() + assert not result.project_path.joinpath(".github", "workflows", "publish-to-pypi.yml").is_file() + assert not result.project_path.joinpath(".github", "workflows", "test-coverage-lint.yml").is_file() + assert result.project_path.joinpath(".github", "workflows", "publish-to-pypi-uv.yml").is_file() + assert result.project_path.joinpath(".github", "workflows", "test-coverage-lint-uv.yml").is_file() def test_bake_project_api_with_webpages_docker(cookies, bake_project_api_with_webpages_docker): @@ -129,6 +153,10 @@ def test_bake_project_api_with_webpages_docker(cookies, bake_project_api_with_we assert result.project_path.joinpath("api_with_webpages", "static").is_dir() assert result.project_path.joinpath("api_with_webpages", "templates").is_dir() assert result.project_path.joinpath("api_with_webpages", "routers", "hello_world.py").is_file() + assert result.project_path.joinpath(".github", "workflows", "publish-to-pypi.yml").is_file() + assert result.project_path.joinpath(".github", "workflows", "test-coverage-lint.yml").is_file() + assert not result.project_path.joinpath(".github", "workflows", "publish-to-pypi-uv.yml").is_file() + assert not result.project_path.joinpath(".github", "workflows", "test-coverage-lint-uv.yml").is_file() def test_bake_project_uv_api_with_webpages_docker(cookies, bake_project_uv_api_with_webpages_docker): @@ -148,3 +176,7 @@ def test_bake_project_uv_api_with_webpages_docker(cookies, bake_project_uv_api_w assert result.project_path.joinpath("api_with_webpages", "static").is_dir() assert result.project_path.joinpath("api_with_webpages", "templates").is_dir() assert result.project_path.joinpath("api_with_webpages", "routers", "hello_world.py").is_file() + assert not result.project_path.joinpath(".github", "workflows", "publish-to-pypi.yml").is_file() + assert not result.project_path.joinpath(".github", "workflows", "test-coverage-lint.yml").is_file() + assert result.project_path.joinpath(".github", "workflows", "publish-to-pypi-uv.yml").is_file() + assert result.project_path.joinpath(".github", "workflows", "test-coverage-lint-uv.yml").is_file() diff --git a/{{cookiecutter.git_repo_name}}/.github/workflows/publish-to-pypi-uv.yml b/{{cookiecutter.git_repo_name}}/.github/workflows/publish-to-pypi-uv.yml new file mode 100644 index 0000000..d05b161 --- /dev/null +++ b/{{cookiecutter.git_repo_name}}/.github/workflows/publish-to-pypi-uv.yml @@ -0,0 +1,32 @@ +# This workflow will upload a Python Package using UV when a release is created +# For more information see: https://help.github.com/en/actions/language-and-framework-guides/using-python-with-github-actions#publishing-to-package-registries + +name: Upload Python Package to PyPi + +on: + release: + types: + - published + +jobs: + deploy: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: "3.12" + + - name: Install UV + run: | + pip install uv + - name: Build and publish + env: + UV_PUBLISH_USERNAME: ${{ secrets.PYPI_USERNAME }} + UV_PUBLISH_PASSWORD: ${{ secrets.PYPI_PASSWORD }} + run: | + make build + uv publish diff --git a/{{cookiecutter.git_repo_name}}/.github/workflows/publish-to-pypi.yml b/{{cookiecutter.git_repo_name}}/.github/workflows/publish-to-pypi.yml index 1f0d78c..ed65f58 100644 --- a/{{cookiecutter.git_repo_name}}/.github/workflows/publish-to-pypi.yml +++ b/{{cookiecutter.git_repo_name}}/.github/workflows/publish-to-pypi.yml @@ -18,7 +18,7 @@ jobs: - name: Set up Python uses: actions/setup-python@v5 with: - python-version: "3.10" + python-version: "3.12" - name: Upgrade pip setuptools wheel run: | diff --git a/{{cookiecutter.git_repo_name}}/.github/workflows/test-coverage-lint-uv.yml b/{{cookiecutter.git_repo_name}}/.github/workflows/test-coverage-lint-uv.yml new file mode 100644 index 0000000..0f8bb33 --- /dev/null +++ b/{{cookiecutter.git_repo_name}}/.github/workflows/test-coverage-lint-uv.yml @@ -0,0 +1,106 @@ +# This workflow will install Python dependencies, run tests and lint with a variety of Python versions +# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions + +name: Unit-Testing, Coverage, Linting + +on: + push: + branches: + - main + - develop + - feature/* + - bug/* + pull_request: + branches: + - main + - develop + - feature/* + - bug/* + +jobs: + linting: + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + python-version: + - "3.9" + - "3.10" + - "3.11" + - "3.12" + - "3.13" + os: + - ubuntu-latest + + steps: + - uses: actions/checkout@v4 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python-version }} + - name: Install UV + run: | + pip install uv + - name: Run Linting + run: | + make pylint + + testing-coverage: + needs: linting + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + python-version: + - "3.9" + - "3.10" + - "3.11" + - "3.12" + - "3.13" + os: + - ubuntu-latest + - windows-latest + - macos-latest + + steps: + - uses: actions/checkout@v4 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python-version }} + - name: Install UV + run: | + pip install uv + - name: Run Unit-Testing and Coverage + run: | + make coverage + + build: + needs: testing-coverage + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + python-version: + - "3.9" + - "3.10" + - "3.11" + - "3.12" + - "3.13" + os: + - ubuntu-latest + - windows-latest + - macos-latest + + steps: + - uses: actions/checkout@v4 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python-version }} + - name: Install UV + run: | + pip install uv + - name: Run Build + run: | + make build diff --git a/{{cookiecutter.git_repo_name}}/.readthedocs.yaml b/{{cookiecutter.git_repo_name}}/.readthedocs.yaml index 912f66e..fcfd00f 100644 --- a/{{cookiecutter.git_repo_name}}/.readthedocs.yaml +++ b/{{cookiecutter.git_repo_name}}/.readthedocs.yaml @@ -4,7 +4,7 @@ version: 2 build: os: "ubuntu-22.04" tools: - python: "3.8" + python: "3.12" sphinx: configuration: docs/conf.py