From e4b1a08fe72147946f147afc41376e4fcd387ae5 Mon Sep 17 00:00:00 2001 From: Federico Busetti <729029+febus982@users.noreply.github.com> Date: Sat, 21 Jun 2025 13:09:54 +0100 Subject: [PATCH 1/7] Update pyproject.toml for uv --- .gitignore | 3 +- bootstrap_python_package/__init__.py | 5 +- pyproject.toml | 89 ++++++++++++++-------------- 3 files changed, 48 insertions(+), 49 deletions(-) diff --git a/.gitignore b/.gitignore index 4b14d04..5f825d9 100644 --- a/.gitignore +++ b/.gitignore @@ -282,4 +282,5 @@ dmypy.json # Cython debug symbols cython_debug/ -poetry.lock +uv.lock +version.py diff --git a/bootstrap_python_package/__init__.py b/bootstrap_python_package/__init__.py index 715bbf3..9971de9 100644 --- a/bootstrap_python_package/__init__.py +++ b/bootstrap_python_package/__init__.py @@ -1,5 +1,5 @@ # ============================================================================== -# Copyright (c) 2024 Federico Busetti = +# Copyright (c) 2025 Federico Busetti = # <729029+febus982@users.noreply.github.com> = # = # Permission is hereby granted, free of charge, to any person obtaining a = @@ -21,9 +21,6 @@ # DEALINGS IN THE SOFTWARE. = # ============================================================================== -__version__ = "0.0.0" -__version_tuple__ = (0, 0, 0) - def some_function() -> str: """ diff --git a/pyproject.toml b/pyproject.toml index fecb142..9d7425b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,14 +1,11 @@ -[tool.poetry] +[project] name = "bootstrap-python-package" -version = "0.0.0" +dynamic = ["version"] description = "A manager to easily handle multiple SQLAlchemy configurations" -license = "MIT" -authors = ["Federico Busetti <729029+febus982@users.noreply.github.com>"] -repository = "https://github.com/febus982/bootstrap-python-package" -homepage = "https://febus982.github.io/bootstrap-python-package" +authors = [{ name = "Federico Busetti", email = "729029+febus982@users.noreply.github.com" }] +requires-python = ">=3.9,<3.14" readme = "README.md" -packages = [{include = "bootstrap_python_package"}] -#keywords = ["add", "keywords", "here"] +license = "MIT" classifiers = [ "Development Status :: 4 - Beta", "Framework :: AsyncIO", @@ -24,54 +21,58 @@ classifiers = [ "Programming Language :: Python :: 3.11", "Programming Language :: Python :: 3.12", "Programming Language :: Python :: 3.13", - "Typing :: Typed" + "Typing :: Typed", ] -[tool.poetry-dynamic-versioning] -enable = false +[project.urls] +Homepage = "https://febus982.github.io/bootstrap-python-package" +Repository = "https://github.com/febus982/bootstrap-python-package" -[build-system] -requires = ["poetry-core", "poetry-dynamic-versioning"] -build-backend = "poetry_dynamic_versioning.backend" +[dependency-groups] +dev = [ + "coverage>=6.5.0", + "mkdocs>=1.4.3", + "mkdocstrings[python]>=0.24.0", + "mkdocs-awesome-pages-plugin", + "mkdocs-macros-adr-summary", + "mkdocs-gen-files>=0.5.0", + "mkdocs-material>=9.1.16", + "mike>=2.0.0", + "mypy>=0.990", + "pymdown-extensions>=10.0.1", + "pytest>=8.0.0,<9", + "pytest-asyncio>=0.20.3", + "pytest-cov>=4.0.0", + "pytest-factoryboy>=2.5.0", + "pytest-xdist>=3.0.2", + "ruff>=0.0.263", + "tox>=4.12.1", + "tox-uv>=1.26.0", + "uv-dynamic-versioning>=0.8.2", +] -############################ -### Package requirements ### -############################ +[build-system] +requires = ["hatchling", "uv-dynamic-versioning"] +build-backend = "hatchling.build" -[tool.poetry.dependencies] -python = ">=3.9,<3.14" +[tool.hatch.build.targets.sdist] +include = ["bootstrap_python_package"] -[tool.poetry.group.dev] -optional = true +[tool.hatch.build.targets.wheel] +include = ["bootstrap_python_package"] -[tool.poetry.group.dev.dependencies] -coverage = ">=6.5.0" -mkdocs = ">=1.4.3" -mkdocstrings = { version = ">=0.24.0", extras = ["python"] } -mkdocs-awesome-pages-plugin = "*" -mkdocs-macros-adr-summary = "*" -mkdocs-gen-files = ">=0.5.0" -mkdocs-material = ">=9.1.16" -mike = ">=2.0.0" -mypy = ">=0.990" -pymdown-extensions = ">=10.0.1" -pytest = "^8.0.0" -pytest-asyncio = ">=0.20.3" -pytest-cov = ">=4.0.0" -pytest-factoryboy = ">=2.5.0" -pytest-xdist = ">=3.0.2" -ruff = ">=0.0.263" -tox = ">=4.12.1" +[tool.hatch.version] +source = "uv-dynamic-versioning" -############################ -### Tools configuration ### -############################ +[tool.hatch.build.hooks.version] +path = "bootstrap_python_package/version.py" [tool.coverage.run] branch = true source = ["bootstrap_python_package"] -# It's not necessary to configure concurrency here -# because pytest-cov takes care of that +omit = [ + "bootstrap_python_package/version.py", +] [tool.coverage.report] fail_under = 100 From bd741abc7b31e4f9289757e8d27924c6e62338ab Mon Sep 17 00:00:00 2001 From: Federico Busetti <729029+febus982@users.noreply.github.com> Date: Sat, 21 Jun 2025 13:10:09 +0100 Subject: [PATCH 2/7] Integrate tox with uv --- tox.ini | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/tox.ini b/tox.ini index ff1c841..3e86820 100644 --- a/tox.ini +++ b/tox.ini @@ -11,14 +11,8 @@ env_list = format [testenv] -; The file /tmp/requirements.txt is created automatically if you run tox -; using `make check` command, otherwise manually run -; `poetry export -f requirements.txt --output /tmp/requirements.txt --with dev` -; Poetry is really bad in identifying running virtualenvs, so we can't use -; directly poetry install. This is the best hacky way to install poetry -; requirements inside tox. -deps = - -r/tmp/requirements.txt +runner = uv-venv-runner +dependency_groups = dev commands = pytest From 4bc7966e23a399b1a021a062713ea00b9a4f6d8c Mon Sep 17 00:00:00 2001 From: Federico Busetti <729029+febus982@users.noreply.github.com> Date: Sat, 21 Jun 2025 13:13:23 +0100 Subject: [PATCH 3/7] Update Makefile commands --- Makefile | 43 +++++++++++++++++++------------------------ 1 file changed, 19 insertions(+), 24 deletions(-) diff --git a/Makefile b/Makefile index 9ee8046..fc64c87 100644 --- a/Makefile +++ b/Makefile @@ -1,49 +1,44 @@ -.PHONY: dev-dependencies update-dependencies test docs fix check typing lint format ci-test ci-coverage poetry-export +.PHONY: dev-dependencies update-dependencies test docs fix check typing lint format ci-test ci-coverage ######################### ###### dev commands ##### ######################### dev-dependencies: - poetry install --with dev --no-root + uv sync --all-groups --frozen update-dependencies: - poetry update --with dev + uv lock --upgrade + uv sync --all-groups --frozen test: - poetry run pytest -n auto --cov + uv run pytest -n auto --cov docs: - poetry run mkdocs serve + uv run mkdocs serve fix: - poetry run ruff check . --fix - poetry run ruff format . + uv run ruff format . + uv run ruff check . --fix + uv run ruff format . -check: poetry-export - tox +check: + uv run tox -typing: poetry-export - tox -e typing +typing: + uv run tox -e typing -lint: poetry-export - tox -e lint +lint: + uv run tox -e lint -format: poetry-export - tox -e format - - -######################### -#### Helper commands #### -######################### -poetry-export: - poetry export -f requirements.txt --output /tmp/requirements.txt --with dev +format: + uv run tox -e format ######################### ###### CI commands ###### ######################### ci-test: - poetry run pytest + uv run pytest ci-coverage: - poetry run pytest --cov --cov-report lcov + uv run pytest --cov --cov-report lcov From ff5bddca7706d793787396bdd48f8a75ea065699 Mon Sep 17 00:00:00 2001 From: Federico Busetti <729029+febus982@users.noreply.github.com> Date: Sat, 21 Jun 2025 13:54:06 +0100 Subject: [PATCH 4/7] Update remaining references to poetry --- .github/workflows/python-code-style.yml | 6 +++--- .github/workflows/python-lint.yml | 6 +++--- .github/workflows/python-quality.yml | 7 +++---- .github/workflows/python-tests.yml | 9 ++++----- .github/workflows/python-typing.yml | 6 +++--- .github/workflows/release.yml | 7 ++++--- .github/workflows/reusable-github-pages.yml | 11 +++++------ CONTRIBUTING.md | 3 ++- README.md | 8 ++++---- pyproject.toml | 2 +- scripts/docs-version.sh | 2 +- 11 files changed, 33 insertions(+), 34 deletions(-) diff --git a/.github/workflows/python-code-style.yml b/.github/workflows/python-code-style.yml index 39769a7..a8efd85 100644 --- a/.github/workflows/python-code-style.yml +++ b/.github/workflows/python-code-style.yml @@ -21,11 +21,11 @@ jobs: uses: actions/setup-python@v5 with: python-version: "3.13" + - name: Install uv + uses: astral-sh/setup-uv@v6 - name: Install dependencies run: | - python -m pip install --upgrade pip - python -m pip install poetry tox - make poetry-export + make dev-dependencies - name: Check code style with black run: | make format diff --git a/.github/workflows/python-lint.yml b/.github/workflows/python-lint.yml index a00e294..1770883 100644 --- a/.github/workflows/python-lint.yml +++ b/.github/workflows/python-lint.yml @@ -21,10 +21,10 @@ jobs: uses: actions/setup-python@v5 with: python-version: "3.13" + - name: Install uv + uses: astral-sh/setup-uv@v6 - name: Install dependencies run: | - python -m pip install --upgrade pip - python -m pip install poetry tox - make poetry-export + make dev-dependencies - name: Lint with ruff run: make lint diff --git a/.github/workflows/python-quality.yml b/.github/workflows/python-quality.yml index fcc57e4..f14222f 100644 --- a/.github/workflows/python-quality.yml +++ b/.github/workflows/python-quality.yml @@ -21,12 +21,11 @@ jobs: uses: actions/setup-python@v5 with: python-version: "3.13" + - name: Install uv + uses: astral-sh/setup-uv@v6 - name: Install dependencies run: | - python -m pip install --upgrade pip - python -m pip install poetry - poetry config virtualenvs.create false - poetry install --no-root --with dev + make dev-dependencies - name: Test & publish code coverage uses: paambaati/codeclimate-action@v9.0.0 env: diff --git a/.github/workflows/python-tests.yml b/.github/workflows/python-tests.yml index 8335564..f91c663 100644 --- a/.github/workflows/python-tests.yml +++ b/.github/workflows/python-tests.yml @@ -28,12 +28,11 @@ jobs: uses: actions/setup-python@v5 with: python-version: "${{ matrix.version }}" + - name: Install uv + uses: astral-sh/setup-uv@v6 - name: Install dependencies run: | - python -m pip install --upgrade pip - python -m pip install poetry - poetry config virtualenvs.create false - poetry install --no-root --with dev + make dev-dependencies - name: Test with pytest id: citest run: | @@ -68,7 +67,7 @@ jobs: --body "$BODY") if [[ $PINNED == true ]]; then gh issue pin "$new_issue_url" - fi + fi fi env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/python-typing.yml b/.github/workflows/python-typing.yml index d92e04e..4090f5c 100644 --- a/.github/workflows/python-typing.yml +++ b/.github/workflows/python-typing.yml @@ -21,10 +21,10 @@ jobs: uses: actions/setup-python@v5 with: python-version: "3.13" + - name: Install uv + uses: astral-sh/setup-uv@v6 - name: Install dependencies run: | - python -m pip install --upgrade pip - python -m pip install poetry tox - make poetry-export + make dev-dependencies - name: Check typing run: make typing diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 2812e19..e346987 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -22,14 +22,15 @@ jobs: with: python-version: "3.13" + - name: Install uv + uses: astral-sh/setup-uv@v6 - name: Install dependencies run: | - python -m pip install --upgrade pip - python -m pip install poetry poetry-dynamic-versioning + make dev-dependencies - name: Build package run: | - poetry build + uv build - name: Archive the dist folder uses: actions/upload-artifact@v4 diff --git a/.github/workflows/reusable-github-pages.yml b/.github/workflows/reusable-github-pages.yml index 26794b3..22fdf56 100644 --- a/.github/workflows/reusable-github-pages.yml +++ b/.github/workflows/reusable-github-pages.yml @@ -46,12 +46,11 @@ jobs: # Here we want to install the current package in editable mode, # in case mkdocs needs the package (i.e. we are building a mkdocs plugin). + - name: Install uv + uses: astral-sh/setup-uv@v6 - name: Install dependencies run: | - python -m pip install --upgrade pip - python -m pip install poetry - poetry config virtualenvs.create false - poetry install --with dev + make dev-dependencies - name: Configure Git user run: | @@ -64,12 +63,12 @@ jobs: - name: Build and deploy static pages run: | - mike deploy ${{ inputs.site-version }} ${{ inputs.version-alias }} --update-aliases --push --branch ${{ inputs.branch }} + uv run mike deploy ${{ inputs.site-version }} ${{ inputs.version-alias }} --update-aliases --push --branch ${{ inputs.branch }} - name: Set default site version if: ${{ inputs.set-default }} run: | - mike set-default ${{ inputs.site-version }} --push --branch ${{ inputs.branch }} + uv run mike set-default ${{ inputs.site-version }} --push --branch ${{ inputs.branch }} # `mike` is specifically built to be used together with GitHub pages. # To upload the website to another service (i.e. AWS S3) uncomment diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index ae11d1a..f518506 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -8,8 +8,9 @@ Please note that this project is released with a Contributor Code of Conduct. By ## Submitting a pull request +Before running any commands, [install `uv`](https://docs.astral.sh/uv/getting-started/installation/): + 0. Fork and clone the repository -0. Install poetry: `pip install -g poetry` 0. Configure and install the dependencies: `make dev-dependencies` 0. Make sure the tests pass on your machine: `make check` 0. Create a new branch: `git checkout -b my-branch-name` diff --git a/README.md b/README.md index 14e4e24..6d8869e 100644 --- a/README.md +++ b/README.md @@ -43,12 +43,12 @@ It is configured with all the following features: * Update the PyCharm Copyright profile in the IDE settings: Editor | Copyright | Copyright Profiles (if you want to use it) * Setup local development: * Clone the repository - * Install poetry `pip install poetry` + * [Install uv](https://docs.astral.sh/uv/getting-started/installation/) * Install dev dependencies with `make dev-dependencies` * (optional) It is strongly recommended to install [pre-commit](https://pre-commit.com/#installation) and run `pre-commit install` so that formatting and linting are automatically executed during `git commit`. * Setup GitHub pages (this need local development setup): - * Initialise documentation branch `poetry run mike deploy dev latest --update-aliases --push` + * Initialise documentation branch `uv run mike deploy dev latest --update-aliases --push` * Configure GitHub Pages to deploy from the `gh-pages` branch (at URL `https://github.com/GITHUB_NAME_OR_ORGANIZATION/GITHUB_REPOSITORY/settings/pages`) * Add the `main` branch and the `v*.*.*` tag rules to the "deployment branches and tags" list in the `gh-pages` environment (at URL `https://github.com/GITHUB_NAME_OR_ORGANIZATION/GITHUB_REPOSITORY/settings/environments`) @@ -59,7 +59,7 @@ and remove the marked lines in `workflows/release.yml`. ## Package release -This setup uses [poetry-dynamic-versioning](https://github.com/mtkennerly/poetry-dynamic-versioning). +This setup uses [uv-dynamic-versioning](https://github.com/ninoseki/uv-dynamic-versioning/tree/main). This means it's not necessary to commit the version in the code but the CI pipeline will infer it from the git tag. @@ -72,7 +72,7 @@ To release a new version, just create a new release and tag in the GitHub reposi the convention `vX.X.X` (semantic versioning preceded by lowercase `v`). It will publish the correct version on Pypi, omitting the `v` (ie. `v1.0.0` will publish `1.0.0`). -This format can be customized, refer to [poetry-dynamic-versioning docs](https://github.com/mtkennerly/poetry-dynamic-versioning) +This format can be customized, refer to [uv-dynamic-versioning docs](https://github.com/ninoseki/uv-dynamic-versioning/tree/main). ## Commands for development diff --git a/pyproject.toml b/pyproject.toml index 9d7425b..a8ab171 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,7 +1,7 @@ [project] name = "bootstrap-python-package" dynamic = ["version"] -description = "A manager to easily handle multiple SQLAlchemy configurations" +description = "A nice package meant to achieve world domination!" authors = [{ name = "Federico Busetti", email = "729029+febus982@users.noreply.github.com" }] requires-python = ">=3.9,<3.14" readme = "README.md" diff --git a/scripts/docs-version.sh b/scripts/docs-version.sh index 7212215..3fdbeb9 100755 --- a/scripts/docs-version.sh +++ b/scripts/docs-version.sh @@ -24,6 +24,6 @@ # DEALINGS IN THE SOFTWARE. = #=============================================================================== -VERSION=$(poetry version -s) +VERSION=$(uv version --short) SEMVER=( ${VERSION//./ } ) echo "${SEMVER[0]}.${SEMVER[1]}" From a0dee0d1a8bcfbc1cf4c609a22a04b3b309efce9 Mon Sep 17 00:00:00 2001 From: Federico Busetti <729029+febus982@users.noreply.github.com> Date: Sat, 21 Jun 2025 14:06:35 +0100 Subject: [PATCH 5/7] Add workaround to calculate package version for docs --- .idea/bootstrap-python-package.iml | 3 ++- .idea/misc.xml | 2 +- scripts/docs-version.sh | 4 +++- scripts/version_from_git.py | 26 ++++++++++++++++++++++++++ 4 files changed, 32 insertions(+), 3 deletions(-) create mode 100644 scripts/version_from_git.py diff --git a/.idea/bootstrap-python-package.iml b/.idea/bootstrap-python-package.iml index 53b24a8..9f1eb92 100644 --- a/.idea/bootstrap-python-package.iml +++ b/.idea/bootstrap-python-package.iml @@ -4,8 +4,9 @@ + - + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index 692a896..83d9b9a 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -4,5 +4,5 @@