diff --git a/DEVELOP.rst b/DEVELOP.rst index 2f39ede0..449c8a13 100644 --- a/DEVELOP.rst +++ b/DEVELOP.rst @@ -114,8 +114,6 @@ To create a new release, you must: In the release branch: -- Update ``__version__`` in ``src/crate/client/__init__.py`` - - Add a section for the new version in the ``CHANGES.rst`` file - Commit your changes with a message like "prepare release x.y.z" diff --git a/pyproject.toml b/pyproject.toml index 9d1df102..dde91b73 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,12 +1,13 @@ [build-system] -requires = ["hatchling >= 1.26"] +requires = ["hatchling >= 1.26", "versioningit"] build-backend = "hatchling.build" [tool.hatch.build.targets.wheel] packages = ["src/crate"] [tool.hatch.version] -path = "src/crate/client/__init__.py" +source = "versioningit" +default-version = "0.0.0+unknown" [project] name = "crate" @@ -32,6 +33,7 @@ classifiers = [ "Topic :: Database", ] dependencies = [ + "importlib-metadata; python_version<'3.8'", "orjson>=3.11.3", "urllib3", "verlib2>=0.3.1", diff --git a/src/crate/client/__init__.py b/src/crate/client/__init__.py index ac58fb77..092e0bc0 100644 --- a/src/crate/client/__init__.py +++ b/src/crate/client/__init__.py @@ -27,9 +27,21 @@ "Error", ] -# version string read from setup.py using a regex. Take care not to break the -# regex! -__version__ = "2.0.0" +# ruff: noqa: E402 +try: + from importlib.metadata import PackageNotFoundError, version +except (ImportError, ModuleNotFoundError): # pragma: no cover + from importlib_metadata import ( # type: ignore[assignment,no-redef,unused-ignore] + PackageNotFoundError, + version, + ) + +__appname__ = "crate" + +try: + __version__ = version(__appname__) +except PackageNotFoundError: # pragma: no cover + __version__ = "unknown" # codeql[py/unused-global-variable] apilevel = "2.0"