Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build: migrate from bump-my-version to versioningit #1832

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ repos:

- repo: https://github.com/astral-sh/uv-pre-commit
# uv version.
rev: 0.5.10
rev: 0.5.25
hooks:
- id: uv-lock

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ Follow the installation instructions below to initialize a development virtual e

### Development Environment Installation using `uv`

GT4Py uses the [`uv`](https://docs.astral.sh/uv/) project manager for the development workflow. `uv` is a versatile tool that consolidates functionality usually distributed across different applications into subcommands.
GT4Py uses the [`uv`](https://docs.astral.sh/uv/) project manager (`uv>=0.5.25`) for the development workflow. `uv` is a versatile tool that consolidates functionality usually distributed across different applications into subcommands.

- The `uv pip` subcommand provides a _fast_ Python package manager, emulating [`pip`](https://pip.pypa.io/en/stable/).
- The `uv export | lock | sync` subcommands manage dependency versions in a manner similar to the [`pip-tools`](https://pip-tools.readthedocs.io/en/stable/) command suite.
Expand Down Expand Up @@ -111,7 +111,7 @@ Recurrent development tasks like bumping versions of used development tools or r
GT4Py uses the Sphinx tool for the documentation. To build browseable HTML documentation, install the required tools provided in the `docs` dependency group:

```bash
uv install --group docs --extra all # or --group dev
uv sync --group docs --extra all # or --group dev
```

(Note that most likely these tools are already installed in your development environment, since the `docs` group is included in the `dev` group, which installed by default by `uv sync` if no dependency groups are specified.)
Expand Down
2 changes: 1 addition & 1 deletion dev-tasks.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#! /usr/bin/env -S uv run -q
#! /usr/bin/env -S uv run -q --script
#
# GT4Py - GridTools Framework
#
Expand Down
14 changes: 8 additions & 6 deletions docs/development/tools/release.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,20 @@ Currently, GT4Py releases are published in PyPI (and TestPyPI) and also as commi

1. Make sure all the expected changes (new features, bug fixes, documentation changes, etc.) are already included in the `main` public branch.

2. Use **bump-my-version** to update the version number.
2. Update the [CHANGELOG.md](CHANGELOG.md) file to document the changes included in the new release. Note that this step becomes much simpler when commit messages follow the [Conventional Commits][conventional-commits] convention as encouraged in the [Pull Request and Merge Guidelines](CONTRIBUTING.md#pull-request-and-merge-guidelines) section of the contributing guidelines.

3. Commit the changes with the following message:

```bash
$ bump-my-version bump minor # or patch
$ git commit -m 'Releasing {M}.{m}.{p} version.'
```

3. Update the [CHANGELOG.md](CHANGELOG.md) file to document the changes included in the new release. Note that this step becomes much simpler when commit messages follow the [Conventional Commits][conventional-commits] convention as encouraged in the [Pull Request and Merge Guidelines](CONTRIBUTING.md#pull-request-and-merge-guidelines) section of the contributing guidelines.

4. Commit the changes with the following message:
4. Tag the previous commit with the exact `v{M}.{m}.{p}` tag to update the version number and push all the changes:

```bash
$ git commit -m 'Releasing {M}.{m}.{p} version.'
$ git tag v0.1.2 # replace by the right version tag
$ git push origin master
$ git push --tags origin
```
Comment on lines -16 to 23
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is implicit in the next step.


5. On the GitHub website go to _Releases_ and _Draft a new release_. Choose `v{M}.{m}.{p}` as tag and select a branch (usually `main`). Follow the style of the previous releases for the title (`GT4Py v{M}.{m}.{p}`) and description. Then _Publish release_.
Expand Down
15 changes: 8 additions & 7 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@

import nox

#: This should just be `pytest.ExitCode.NO_TESTS_COLLECTED` but `pytest`
#: is not guaranteed to be available in the venv where `nox` is running.
NO_TESTS_COLLECTED_EXIT_CODE: Final = 5

# -- nox configuration --
nox.options.default_venv_backend = "uv"
nox.options.sessions = [
Expand Down Expand Up @@ -64,6 +60,11 @@


# -- nox sessions --
#: This should just be `pytest.ExitCode.NO_TESTS_COLLECTED` but `pytest`
#: is not guaranteed to be available in the venv where `nox` is running.
NO_TESTS_COLLECTED_EXIT_CODE: Final = 5


@nox.session(python=["3.10", "3.11"], tags=["cartesian"])
@nox.parametrize("device", [DeviceNoxParam.cpu, DeviceNoxParam.cuda12])
@nox.parametrize("codegen", [CodeGenNoxParam.internal, CodeGenNoxParam.dace])
Expand Down Expand Up @@ -231,21 +232,21 @@ def _install_session_venv(
groups: Sequence[str] = (),
) -> None:
"""Install session packages using uv."""
env = dict(os.environ.items()) | {"UV_PROJECT_ENVIRONMENT": session.virtualenv.location}
session.run_install(
"uv",
"sync",
*("--python", session.python),
"--no-dev",
*(f"--extra={e}" for e in extras),
*(f"--group={g}" for g in groups),
env={key: value for key, value in os.environ.items()}
| {"UV_PROJECT_ENVIRONMENT": session.virtualenv.location},
env=env,
)
for item in args:
session.run_install(
"uv",
"pip",
"install",
*((item,) if isinstance(item, str) else item),
env={"UV_PROJECT_ENVIRONMENT": session.virtualenv.location},
env=env,
)
40 changes: 14 additions & 26 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

[build-system]
build-backend = 'setuptools.build_meta'
requires = ['setuptools>=70.0.0', 'wheel>=0.33.6', 'cython>=3.0.0']
requires = ['cython>=3.0.0', 'setuptools>=70.0.0', 'versioningit>=3.1.1', 'wheel>=0.33.6']

# -- Dependency groups --
[dependency-groups]
build = [
'bump-my-version>=0.16.0',
'cython>=3.0.0',
'pip>=22.1.1',
'setuptools>=70.0.0',
'versioningit>=3.1.1',
'wheel>=0.33.6'
]
dev = [
Expand Down Expand Up @@ -150,27 +150,6 @@ Homepage = 'https://gridtools.github.io/'
Repository = 'https://github.com/GridTools/gt4py'

# ---- Other tools ----
# -- bump-my-version --
[tool.bumpversion]
allow_dirty = false
commit = false
commit_args = ''
current_version = '1.0.4'
ignore_missing_version = false
message = 'Bump version: {current_version} → {new_version}'
parse = '(?P<major>\d+)\.(?P<minor>\d+)(\.(?P<patch>\d+))?'
regex = false
replace = '{new_version}'
search = '{current_version}'
serialize = ['{major}.{minor}.{patch}']
sign_tags = false
tag = false
tag_message = 'Bump version: {current_version} → {new_version}'
tag_name = 'v{new_version}'

[[tool.bumpversion.files]]
filename = 'src/gt4py/__about__.py'

# -- coverage --
[tool.coverage]

Expand Down Expand Up @@ -420,9 +399,6 @@ max-complexity = 15
[tool.setuptools]
platforms = ['Linux', 'Mac']

[tool.setuptools.dynamic]
version = {attr = 'gt4py.__about__.__version__'}

[tool.setuptools.package-data]
'*' = ['*.in', '*.txt']
'gt4py' = ['py.typed', '*.md', '*.rst']
Expand All @@ -448,3 +424,15 @@ url = 'https://test.pypi.org/simple/'

[tool.uv.sources]
atlas4py = {index = "test.pypi"}

# -- versioningit --
[tool.versioningit]

[tool.versioningit.format]
dirty = "{base_version}+d{build_date:%Y%m%d}" # Example: 1.2.3+d20230922
distance = "{base_version}.post{distance}+{rev}" # Example: 1.2.3.post42+e174a1f
distance-dirty = "{base_version}.post{distance}+{rev}.d{build_date:%Y%m%d}" # Example: 1.2.3.post42+e174a1f.d20230922

[tool.versioningit.vcs]
describe-subst = "$Format:%(describe:tags,match=v*)$"
method = "git-archive" # git
31 changes: 30 additions & 1 deletion src/gt4py/__about__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

"""Package metadata: version, authors, license and copyright."""

import importlib.metadata as _imp_metadata
from typing import Final

from packaging import version as pkg_version
Expand All @@ -21,5 +22,33 @@
__license__: Final = "BSD-3-Clause"


__version__: Final = "1.0.4"
if dist := _imp_metadata.distribution("gt4py"):
_version: str = dist.version

if contents := dist.read_text("direct_url.json"):
# This branch should only be executed in editable installs.
# In this case, the version reported by `gt4py.__version__`
# is directly computed from the status of the `git` repository
# with the source code, if available, which might differ from the
# version reported by `importlib.metadata.version("gt4py")`
# (and `$ pip show gt4py`).
try:
import json as _json

import versioningit as _versioningit

_url_data = _json.loads(contents)
assert _url_data["dir_info"]["editable"] is True
assert _url_data["url"].startswith("file://")

_src_path = _url_data["url"][7:]
_version = _versioningit.get_version(_src_path)
except Exception:
pass

else:
# TODO(egparedes): should we fallback to a default version instead??
raise RuntimeError("Could not find 'gt4py' package metadata")

__version__: Final[str] = _version
__version_info__: Final = pkg_version.parse(__version__)
Loading
Loading