From 7bbd2d9cd10daf66de6434a14305412ba1b5d0e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Edgar=20Ram=C3=ADrez-Mondrag=C3=B3n?= Date: Fri, 31 Jan 2025 09:31:10 -0600 Subject: [PATCH] fix: Use uv in tap, target and mapper templates --- .github/workflows/cookiecutter-e2e.yml | 16 ++--- .github/workflows/resources/requirements.txt | 4 +- .../.github/workflows/test.yml | 4 +- .../.pre-commit-config.yaml | 8 +++ .../{{cookiecutter.mapper_id}}/README.md | 14 ++-- .../{{cookiecutter.mapper_id}}/pyproject.toml | 51 +++++++------ .../.github/workflows/test.yml | 4 +- .../.pre-commit-config.yaml | 8 +++ .../{{cookiecutter.tap_id}}/README.md | 14 ++-- .../{{cookiecutter.tap_id}}/pyproject.toml | 71 ++++++++++--------- .../.github/workflows/test.yml | 4 +- .../.pre-commit-config.yaml | 8 +++ .../{{cookiecutter.target_id}}/README.md | 14 ++-- .../{{cookiecutter.target_id}}/pyproject.toml | 57 ++++++++------- noxfile.py | 10 ++- 15 files changed, 172 insertions(+), 115 deletions(-) diff --git a/.github/workflows/cookiecutter-e2e.yml b/.github/workflows/cookiecutter-e2e.yml index 21b08bff0..be60ecf89 100644 --- a/.github/workflows/cookiecutter-e2e.yml +++ b/.github/workflows/cookiecutter-e2e.yml @@ -33,14 +33,7 @@ jobs: - uses: astral-sh/setup-uv@v5 with: - version: ">=0.4.30" - - - name: Install Poetry - env: - UV_CONSTRAINT: ${{ github.workspace }}/.github/workflows/resources/requirements.txt - run: | - uv tool install poetry - poetry --version + version: ">=0.5.19" - uses: actions/setup-python@v5 with: @@ -53,6 +46,13 @@ jobs: uv tool install --with=pre-commit-uv pre-commit pre-commit --version + - name: Install twine + env: + UV_CONSTRAINT: ${{ github.workspace }}/.github/workflows/resources/requirements.txt + run: | + uv tool install twine + twine --version + - name: Install Nox env: UV_CONSTRAINT: ${{ github.workspace }}/.github/workflows/resources/requirements.txt diff --git a/.github/workflows/resources/requirements.txt b/.github/workflows/resources/requirements.txt index 8a61ee357..73981c47a 100644 --- a/.github/workflows/resources/requirements.txt +++ b/.github/workflows/resources/requirements.txt @@ -1,5 +1,5 @@ griffe~=1.5 +nox==2024.10.9 pip==25.0 -poetry==2.0.1 pre-commit==4.1.0 -nox==2024.10.9 +twine==6.1.0 diff --git a/cookiecutter/mapper-template/{{cookiecutter.mapper_id}}/.github/workflows/test.yml b/cookiecutter/mapper-template/{{cookiecutter.mapper_id}}/.github/workflows/test.yml index 4acc3b57b..4bcb5fe9a 100644 --- a/cookiecutter/mapper-template/{{cookiecutter.mapper_id}}/.github/workflows/test.yml +++ b/cookiecutter/mapper-template/{{cookiecutter.mapper_id}}/.github/workflows/test.yml @@ -10,8 +10,8 @@ on: - .github/workflows/test.yml - {{ cookiecutter.library_name }}/** - tests/** - - poetry.lock - pyproject.toml + - uv.lock - tox.ini pull_request: branches: [main] @@ -19,8 +19,8 @@ on: - .github/workflows/test.yml - {{ cookiecutter.library_name }}/** - tests/** - - poetry.lock - pyproject.toml + - uv.lock - tox.ini workflow_dispatch: diff --git a/cookiecutter/mapper-template/{{cookiecutter.mapper_id}}/.pre-commit-config.yaml b/cookiecutter/mapper-template/{{cookiecutter.mapper_id}}/.pre-commit-config.yaml index 876efb216..6edbf6c39 100644 --- a/cookiecutter/mapper-template/{{cookiecutter.mapper_id}}/.pre-commit-config.yaml +++ b/cookiecutter/mapper-template/{{cookiecutter.mapper_id}}/.pre-commit-config.yaml @@ -2,6 +2,8 @@ ci: autofix_prs: true autoupdate_schedule: weekly autoupdate_commit_msg: 'chore: pre-commit autoupdate' + skip: + - uv-lock repos: - repo: https://github.com/pre-commit/pre-commit-hooks @@ -34,3 +36,9 @@ repos: rev: v1.14.1 hooks: - id: mypy + +- repo: https://github.com/astral-sh/uv-pre-commit + rev: 0.5.26 + hooks: + - id: uv-lock + - id: uv-sync diff --git a/cookiecutter/mapper-template/{{cookiecutter.mapper_id}}/README.md b/cookiecutter/mapper-template/{{cookiecutter.mapper_id}}/README.md index 8f24517b3..36d6fd896 100644 --- a/cookiecutter/mapper-template/{{cookiecutter.mapper_id}}/README.md +++ b/cookiecutter/mapper-template/{{cookiecutter.mapper_id}}/README.md @@ -74,9 +74,13 @@ Follow these instructions to contribute to this project. ### Initialize your Development Environment +Prerequisites: + +- Python 3.9+ +- [uv](https://docs.astral.sh/uv/) + ```bash -pipx install poetry -poetry install +uv sync ``` ### Create and Run Tests @@ -85,13 +89,13 @@ Create tests within the `tests` subfolder and then run: ```bash -poetry run pytest +uv run pytest ``` -You can also test the `{{cookiecutter.mapper_id}}` CLI interface directly using `poetry run`: +You can also test the `{{cookiecutter.mapper_id}}` CLI interface directly using `uv run`: ```bash -poetry run {{cookiecutter.mapper_id}} --help +uv run {{cookiecutter.mapper_id}} --help ``` ### Testing with [Meltano](https://www.meltano.com) diff --git a/cookiecutter/mapper-template/{{cookiecutter.mapper_id}}/pyproject.toml b/cookiecutter/mapper-template/{{cookiecutter.mapper_id}}/pyproject.toml index b2a7ce578..7567c5ae2 100644 --- a/cookiecutter/mapper-template/{{cookiecutter.mapper_id}}/pyproject.toml +++ b/cookiecutter/mapper-template/{{cookiecutter.mapper_id}}/pyproject.toml @@ -26,25 +26,35 @@ classifiers = [ license = "Apache-2.0" license-files = [ "LICENSE" ] requires-python = ">=3.9" -dynamic = ["dependencies"] +dependencies = [ + {%- if cookiecutter.faker_extra %} + "singer-sdk[faker]~=0.44.1", + {%- else %} + "singer-sdk~=0.44.1", + {%- endif %} +] -[tool.poetry] -{%- if cookiecutter.variant != "None (Skip)" %} -packages = [ - { include = "{{cookiecutter.library_name}}" }, +[project.optional-dependencies] +s3 = [ + "fs-s3fs~=1.1.1", ] -{%- endif %} -[tool.poetry.dependencies] -singer-sdk = { version="~=0.44.1"{{ ', extras = ["faker"]' if cookiecutter.faker_extra }} } -fs-s3fs = { version = "~=1.1.1", optional = true } +[project.scripts] +# CLI declaration +{{cookiecutter.mapper_id}} = '{{cookiecutter.library_name}}.mapper:{{cookiecutter.name}}Mapper.cli' -[tool.poetry.group.dev.dependencies] -pytest = ">=8" -singer-sdk = { version="~=0.44.1", extras = ["testing"] } +[dependency-groups] +dev = [ + "pytest>=8", + "singer-sdk[testing]~=0.44.1", +] -[tool.poetry.extras] -s3 = ["fs-s3fs"] +{%- if cookiecutter.variant != "None (Skip)" %} +[tool.hatch.build.targets.wheel] +packages = [ + "{{cookiecutter.library_name}}", +] +{%- endif %} [tool.pytest.ini_options] addopts = [ @@ -55,9 +65,6 @@ addopts = [ python_version = "3.12" warn_unused_configs = true -[tool.ruff] -target-version = "py39" - [tool.ruff.lint] ignore = [ "COM812", # missing-trailing-comma @@ -71,9 +78,7 @@ allow-star-arg-any = true convention = "google" [build-system] -requires = ["poetry-core>=2,<3"] -build-backend = "poetry.core.masonry.api" - -[tool.poetry.scripts] -# CLI declaration -{{cookiecutter.mapper_id}} = '{{cookiecutter.library_name}}.mapper:{{cookiecutter.name}}Mapper.cli' +requires = [ + "hatchling>=1,<2", +] +build-backend = "hatchling.build" diff --git a/cookiecutter/tap-template/{{cookiecutter.tap_id}}/.github/workflows/test.yml b/cookiecutter/tap-template/{{cookiecutter.tap_id}}/.github/workflows/test.yml index 380e39371..cc75548aa 100644 --- a/cookiecutter/tap-template/{{cookiecutter.tap_id}}/.github/workflows/test.yml +++ b/cookiecutter/tap-template/{{cookiecutter.tap_id}}/.github/workflows/test.yml @@ -10,8 +10,8 @@ on: - .github/workflows/test.yml - {{ cookiecutter.library_name }}/** - tests/** - - poetry.lock - pyproject.toml + - uv.lock - tox.ini pull_request: branches: [main] @@ -19,8 +19,8 @@ on: - .github/workflows/test.yml - {{ cookiecutter.library_name }}/** - tests/** - - poetry.lock - pyproject.toml + - uv.lock - tox.ini workflow_dispatch: diff --git a/cookiecutter/tap-template/{{cookiecutter.tap_id}}/.pre-commit-config.yaml b/cookiecutter/tap-template/{{cookiecutter.tap_id}}/.pre-commit-config.yaml index efc51ca1f..ff4b7faa5 100644 --- a/cookiecutter/tap-template/{{cookiecutter.tap_id}}/.pre-commit-config.yaml +++ b/cookiecutter/tap-template/{{cookiecutter.tap_id}}/.pre-commit-config.yaml @@ -2,6 +2,8 @@ ci: autofix_prs: true autoupdate_schedule: weekly autoupdate_commit_msg: 'chore: pre-commit autoupdate' + skip: + - uv-lock repos: - repo: https://github.com/pre-commit/pre-commit-hooks @@ -40,3 +42,9 @@ repos: {%- else %} - types-requests {%- endif %} + +- repo: https://github.com/astral-sh/uv-pre-commit + rev: 0.5.26 + hooks: + - id: uv-lock + - id: uv-sync diff --git a/cookiecutter/tap-template/{{cookiecutter.tap_id}}/README.md b/cookiecutter/tap-template/{{cookiecutter.tap_id}}/README.md index 3aa834221..fdac6023d 100644 --- a/cookiecutter/tap-template/{{cookiecutter.tap_id}}/README.md +++ b/cookiecutter/tap-template/{{cookiecutter.tap_id}}/README.md @@ -75,9 +75,13 @@ Follow these instructions to contribute to this project. ### Initialize your Development Environment +Prerequisites: + +- Python 3.9+ +- [uv](https://docs.astral.sh/uv/) + ```bash -pipx install poetry -poetry install +uv sync ``` ### Create and Run Tests @@ -86,13 +90,13 @@ Create tests within the `tests` subfolder and then run: ```bash -poetry run pytest +uv run pytest ``` -You can also test the `{{cookiecutter.tap_id}}` CLI interface directly using `poetry run`: +You can also test the `{{cookiecutter.tap_id}}` CLI interface directly using `uv run`: ```bash -poetry run {{cookiecutter.tap_id}} --help +uv run {{cookiecutter.tap_id}} --help ``` ### Testing with [Meltano](https://www.meltano.com) diff --git a/cookiecutter/tap-template/{{cookiecutter.tap_id}}/pyproject.toml b/cookiecutter/tap-template/{{cookiecutter.tap_id}}/pyproject.toml index f376111e4..ba30048aa 100644 --- a/cookiecutter/tap-template/{{cookiecutter.tap_id}}/pyproject.toml +++ b/cookiecutter/tap-template/{{cookiecutter.tap_id}}/pyproject.toml @@ -1,3 +1,7 @@ +{%- set extras = [] -%} +{%- if cookiecutter.faker_extra -%}{%- set extras = extras + ["faker"] -%}{%- endif -%} +{%- if cookiecutter.auth_method == "JWT" -%}{%- set extras = extras + ["jwt"] -%}{%- endif -%} + [project] {%- if cookiecutter.variant != "None (Skip)" %} name = "{{cookiecutter.variant}}-{{cookiecutter.tap_id}}" @@ -25,38 +29,41 @@ classifiers = [ license = "Apache-2.0" license-files = [ "LICENSE" ] requires-python = ">=3.9" -dynamic = ["dependencies"] +dependencies = [ + {%- if extras %} + "singer-sdk[{{ extras|join(',') }}]~=0.44.1", + {%- else %} + "singer-sdk~=0.44.1", + {%- endif %} + {%- if cookiecutter.stream_type in ["REST", "GraphQL"] %} + "requests~=2.32.3", + {%- endif %} + {%- if cookiecutter.stream_type == "SQL" %} + "sqlalchemy~=2.0.36", + {%- endif %} +] -[tool.poetry] -{%- if cookiecutter.variant != "None (Skip)" %} -packages = [ - { include = "{{cookiecutter.library_name}}" }, +[project.optional-dependencies] +s3 = [ + "fs-s3fs~=1.1.1", ] -{%- endif %} -[tool.poetry.dependencies] -singer-sdk = { version="~=0.44.1", extras = [ - {%- if cookiecutter.auth_method == "JWT" -%}"jwt", {% endif -%} - {%- if cookiecutter.faker_extra -%}"faker",{%- endif -%} -] } -fs-s3fs = { version = "~=1.1.1", optional = true } -{%- if cookiecutter.stream_type in ["REST", "GraphQL"] %} -requests = "~=2.32.3" -{%- endif %} -{%- if cookiecutter.stream_type == "SQL" %} -sqlalchemy = "~=2.0.36" -{%- endif %} +[project.scripts] +# CLI declaration +{{cookiecutter.tap_id}} = '{{cookiecutter.library_name}}.tap:Tap{{cookiecutter.source_name}}.cli' -[tool.poetry.group.dev.dependencies] -pytest = ">=8" -{%- if cookiecutter.auth_method == "JWT" %} -singer-sdk = { version="~=0.44.1", extras = ["jwt", "testing"] } -{%- else %} -singer-sdk = { version="~=0.44.1", extras = ["testing"] } -{%- endif %} +[dependency-groups] +dev = [ + "pytest>=8", + "singer-sdk[testing]~=0.44.1", +] -[tool.poetry.extras] -s3 = ["fs-s3fs"] +{%- if cookiecutter.variant != "None (Skip)" %} +[tool.hatch.build.targets.wheel] +packages = [ + "{{cookiecutter.library_name}}", +] +{%- endif %} [tool.pytest.ini_options] addopts = [ @@ -88,9 +95,7 @@ allow-star-arg-any = true convention = "google" [build-system] -requires = ["poetry-core>=2,<3"] -build-backend = "poetry.core.masonry.api" - -[tool.poetry.scripts] -# CLI declaration -{{cookiecutter.tap_id}} = '{{cookiecutter.library_name}}.tap:Tap{{cookiecutter.source_name}}.cli' +requires = [ + "hatchling>=1,<2", +] +build-backend = "hatchling.build" diff --git a/cookiecutter/target-template/{{cookiecutter.target_id}}/.github/workflows/test.yml b/cookiecutter/target-template/{{cookiecutter.target_id}}/.github/workflows/test.yml index db8a39d17..81944350b 100644 --- a/cookiecutter/target-template/{{cookiecutter.target_id}}/.github/workflows/test.yml +++ b/cookiecutter/target-template/{{cookiecutter.target_id}}/.github/workflows/test.yml @@ -10,8 +10,8 @@ on: - .github/workflows/test.yml - {{ cookiecutter.library_name }}/** - tests/** - - poetry.lock - pyproject.toml + - uv.lock - tox.ini pull_request: branches: [main] @@ -19,8 +19,8 @@ on: - .github/workflows/test.yml - {{ cookiecutter.library_name }}/** - tests/** - - poetry.lock - pyproject.toml + - uv.lock - tox.ini workflow_dispatch: diff --git a/cookiecutter/target-template/{{cookiecutter.target_id}}/.pre-commit-config.yaml b/cookiecutter/target-template/{{cookiecutter.target_id}}/.pre-commit-config.yaml index 3ba7f67f3..fb6af088f 100644 --- a/cookiecutter/target-template/{{cookiecutter.target_id}}/.pre-commit-config.yaml +++ b/cookiecutter/target-template/{{cookiecutter.target_id}}/.pre-commit-config.yaml @@ -2,6 +2,8 @@ ci: autofix_prs: true autoupdate_schedule: weekly autoupdate_commit_msg: 'chore: pre-commit autoupdate' + skip: + - uv-lock repos: - repo: https://github.com/pre-commit/pre-commit-hooks @@ -40,3 +42,9 @@ repos: {%- else %} - types-requests {%- endif %} + +- repo: https://github.com/astral-sh/uv-pre-commit + rev: 0.5.26 + hooks: + - id: uv-lock + - id: uv-sync diff --git a/cookiecutter/target-template/{{cookiecutter.target_id}}/README.md b/cookiecutter/target-template/{{cookiecutter.target_id}}/README.md index b4fd87fbc..bc35b56fc 100644 --- a/cookiecutter/target-template/{{cookiecutter.target_id}}/README.md +++ b/cookiecutter/target-template/{{cookiecutter.target_id}}/README.md @@ -76,9 +76,13 @@ Follow these instructions to contribute to this project. ### Initialize your Development Environment +Prerequisites: + +- Python 3.9+ +- [uv](https://docs.astral.sh/uv/) + ```bash -pipx install poetry -poetry install +uv sync ``` ### Create and Run Tests @@ -87,13 +91,13 @@ Create tests within the `tests` subfolder and then run: ```bash -poetry run pytest +uv run pytest ``` -You can also test the `{{cookiecutter.target_id}}` CLI interface directly using `poetry run`: +You can also test the `{{cookiecutter.target_id}}` CLI interface directly using `uv run`: ```bash -poetry run {{cookiecutter.target_id}} --help +uv run {{cookiecutter.target_id}} --help ``` ### Testing with [Meltano](https://meltano.com/) diff --git a/cookiecutter/target-template/{{cookiecutter.target_id}}/pyproject.toml b/cookiecutter/target-template/{{cookiecutter.target_id}}/pyproject.toml index 8975b9a99..17b5bbea8 100644 --- a/cookiecutter/target-template/{{cookiecutter.target_id}}/pyproject.toml +++ b/cookiecutter/target-template/{{cookiecutter.target_id}}/pyproject.toml @@ -25,36 +25,43 @@ classifiers = [ license = "Apache-2.0" license-files = [ "LICENSE" ] requires-python = ">=3.9" -dynamic = ["dependencies"] +dependencies = [ + {%- if cookiecutter.faker_extra %} + "singer-sdk[faker]~=0.44.1", + {%- else %} + "singer-sdk~=0.44.1", + {%- endif %} + {%- if cookiecutter.serialization_method != "SQL" %} + "requests~=2.32.3", + {%- endif %} +] -[tool.poetry] -{%- if cookiecutter.variant != "None (Skip)" %} -packages = [ - { include = "{{cookiecutter.library_name}}" }, +[project.optional-dependencies] +s3 = [ + "fs-s3fs~=1.1.1", ] -{%- endif %} -[tool.poetry.dependencies] -singer-sdk = { version="~=0.44.1"{{ ', extras = ["faker"]' if cookiecutter.faker_extra }} } -fs-s3fs = { version = "~=1.1.1", optional = true } -{%- if cookiecutter.serialization_method != "SQL" %} -requests = "~=2.32.3" -{%- endif %} +[project.scripts] +# CLI declaration +{{cookiecutter.target_id}} = '{{cookiecutter.library_name}}.target:Target{{ cookiecutter.destination_name }}.cli' -[tool.poetry.dev-dependencies] -pytest = ">=8" -singer-sdk = { version="~=0.44.1", extras = ["testing"] } +[dependency-groups] +dev = [ + "pytest>=8", + "singer-sdk[testing]~=0.44.1", +] -[tool.poetry.extras] -s3 = ["fs-s3fs"] +{%- if cookiecutter.variant != "None (Skip)" %} +[tool.hatch.build.targets.wheel] +packages = [ + "{{cookiecutter.library_name}}", +] +{%- endif %} [tool.mypy] python_version = "3.12" warn_unused_configs = true -[tool.ruff] -target-version = "py39" - [tool.ruff.lint] ignore = [ "COM812", # missing-trailing-comma @@ -68,9 +75,7 @@ allow-star-arg-any = true convention = "google" [build-system] -requires = ["poetry-core>=2,<3"] -build-backend = "poetry.core.masonry.api" - -[tool.poetry.scripts] -# CLI declaration -{{cookiecutter.target_id}} = '{{cookiecutter.library_name}}.target:Target{{ cookiecutter.destination_name }}.cli' +requires = [ + "hatchling>=1,<2", +] +build-backend = "hatchling.build" diff --git a/noxfile.py b/noxfile.py index ca87ceb3a..bcc7084be 100644 --- a/noxfile.py +++ b/noxfile.py @@ -241,8 +241,14 @@ def test_cookiecutter(session: nox.Session, replay_file_path: str) -> None: + '", develop = true \\}|', "pyproject.toml", ) - session.run("poetry", "lock", external=True) - session.run("poetry", "install", external=True) + + # Check that the project can be installed for development + session.run("uv", "lock", external=True) + session.run("uv", "sync", external=True) + + # Check that the project can be built for distribution + session.run("uv", "build", external=True) + session.run("twine", "check", "dist/*", external=True) session.run("git", "init", "-b", "main", external=True) session.run("git", "add", ".", external=True)