From 48da76c09e4d648cab8c437acc0d87a0bc217648 Mon Sep 17 00:00:00 2001 From: Ben Trachtenberg Date: Sat, 26 Apr 2025 22:40:24 -0500 Subject: [PATCH 1/2] updated readthedoc python version, added actions for uv, updated publish version to 3.12 --- 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 +- 6 files changed, 180 insertions(+), 2 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/hooks/post_gen_project.py b/hooks/post_gen_project.py index a446f3f..daa5d46 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 b9e51a9..cc962e1 100644 --- a/tests/test_cookies.py +++ b/tests/test_cookies.py @@ -13,6 +13,10 @@ def test_bake_project_no_cli_podman(cookies, bake_project_no_cli_podman_data): assert not result.project_path.joinpath("python_no_cli", "example.py").is_file() assert result.project_path.joinpath("containers", "Containerfile").is_file() assert not result.project_path.joinpath("containers", "Dockerfile").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_no_cli_podman(cookies, bake_project_uv_no_cli_podman_data): @@ -30,6 +34,10 @@ def test_bake_project_uv_no_cli_podman(cookies, bake_project_uv_no_cli_podman_da assert not result.project_path.joinpath("python_no_cli", "example.py").is_file() assert result.project_path.joinpath("containers", "Containerfile").is_file() assert not result.project_path.joinpath("containers", "Dockerfile").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_no_cli_docker(cookies, bake_project_no_cli_docker_data): @@ -47,6 +55,10 @@ def test_bake_project_no_cli_docker(cookies, bake_project_no_cli_docker_data): assert not result.project_path.joinpath("python_no_cli", "example.py").is_file() assert not result.project_path.joinpath("containers", "Containerfile").is_file() assert result.project_path.joinpath("containers", "Dockerfile").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_no_cli_docker(cookies, bake_project_uv_no_cli_docker_data): @@ -64,6 +76,10 @@ def test_bake_project_uv_no_cli_docker(cookies, bake_project_uv_no_cli_docker_da assert not result.project_path.joinpath("python_no_cli", "example.py").is_file() assert not result.project_path.joinpath("containers", "Containerfile").is_file() assert result.project_path.joinpath("containers", "Dockerfile").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_cli_podman(cookies, bake_project_cli_podman_data): @@ -81,6 +97,10 @@ def test_bake_project_cli_podman(cookies, bake_project_cli_podman_data): assert result.project_path.joinpath("python_with_cli", "example.py").is_file() assert result.project_path.joinpath("containers", "Containerfile").is_file() assert not result.project_path.joinpath("containers", "Dockerfile").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_cli_podman(cookies, bake_project_uv_cli_podman_data): @@ -98,6 +118,10 @@ def test_bake_project_uv_cli_podman(cookies, bake_project_uv_cli_podman_data): assert result.project_path.joinpath("python_with_cli", "example.py").is_file() assert result.project_path.joinpath("containers", "Containerfile").is_file() assert not result.project_path.joinpath("containers", "Dockerfile").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_cli_docker(cookies, bake_project_cli_docker_data): @@ -115,6 +139,10 @@ def test_bake_project_cli_docker(cookies, bake_project_cli_docker_data): assert result.project_path.joinpath("python_with_cli", "example.py").is_file() assert not result.project_path.joinpath("containers", "Containerfile").is_file() assert result.project_path.joinpath("containers", "Dockerfile").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_cli_docker(cookies, bake_project_uv_cli_docker_data): @@ -132,3 +160,7 @@ def test_bake_project_uv_cli_docker(cookies, bake_project_uv_cli_docker_data): assert result.project_path.joinpath("python_with_cli", "example.py").is_file() assert not result.project_path.joinpath("containers", "Containerfile").is_file() assert result.project_path.joinpath("containers", "Dockerfile").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..78f5cf3 --- /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 Twine 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..f40c850 --- /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 911b724..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.9" + python: "3.12" sphinx: configuration: docs/conf.py From 36cb83e02017be74d058278cb6bdf6fee4fc7f95 Mon Sep 17 00:00:00 2001 From: Ben Trachtenberg Date: Sat, 26 Apr 2025 22:42:44 -0500 Subject: [PATCH 2/2] Template version to 2.0.2 --- cookiecutter.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cookiecutter.json b/cookiecutter.json index 7a8e584..8e61a10 100644 --- a/cookiecutter.json +++ b/cookiecutter.json @@ -47,7 +47,7 @@ "https" ], "__template_repo": "https://github.com/btr1975/cookiecutter-python-library", - "__template_version": "2.0.1", + "__template_version": "2.0.2", "_new_lines": "\n", "_copy_without_render": [ ".github"