diff --git a/.github/workflows/testing-and-deployment.yml b/.github/workflows/testing-and-deployment.yml index 422dc9e..88cd6cf 100644 --- a/.github/workflows/testing-and-deployment.yml +++ b/.github/workflows/testing-and-deployment.yml @@ -23,6 +23,8 @@ jobs: steps: - uses: actions/checkout@v4 + with: + fetch-depth: 0 - name: Set up Python ${{ matrix.python-version }} uses: actions/setup-python@v6 diff --git a/.gitignore b/.gitignore index 656291f..97871cf 100644 --- a/.gitignore +++ b/.gitignore @@ -15,6 +15,8 @@ # Pip generated folders # ######################### keepa.egg-info/ +src/*.egg-info/ +src/keepa/_version.py build/ dist/ keepa/__pycache__/ diff --git a/docs/source/conf.py b/docs/source/conf.py index aa46264..377b921 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -3,6 +3,7 @@ # import pydata_sphinx_theme # noqa from datetime import datetime import importlib +import importlib.metadata import inspect from pathlib import Path @@ -15,6 +16,19 @@ with (PROJECT_ROOT / "pyproject.toml").open("rb") as project_file: project_metadata = tomllib.load(project_file)["project"] + +def get_release() -> str: + """Return the installed package version for Sphinx.""" + try: + return importlib.metadata.version("keepa") + except importlib.metadata.PackageNotFoundError: + try: + from setuptools_scm import get_version + except ModuleNotFoundError: + return "0.0.0" + return get_version(root=PROJECT_ROOT, fallback_version="1.5.0.dev0") + + # If your documentation needs a minimal Sphinx version, state it here. # # needs_sphinx = '1.0' @@ -109,7 +123,7 @@ def linkcode_resolve(domain: str, info: dict[str, str]) -> str | None: # # The full version, including alpha/beta/rc tags. # The short X.Y version. -release = project_metadata["version"] +release = get_release() version = ".".join(release.split(".")[:2]) # The language for content autogenerated by Sphinx. Refer to documentation diff --git a/pyproject.toml b/pyproject.toml index 0b2efaf..164ef0b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [build-system] -build-backend = "flit_core.buildapi" -requires = ["flit_core >=3,<4"] +build-backend = "setuptools.build_meta" +requires = ["setuptools >=64", "setuptools-scm >=8"] [project] authors = [ @@ -26,11 +26,11 @@ dependencies = [ "pydantic >=2" ] description = "Interfaces with keepa.com's API." +dynamic = ["version"] keywords = ["keepa"] name = "keepa" readme = "README.rst" requires-python = ">=3.10" -version = "1.5.dev0" [project.optional-dependencies] doc = [ @@ -70,3 +70,12 @@ line-length = 100 [tool.ruff.lint] ignore = [] select = ["E", "F", "W", "I001"] # pyflakes, pycodestyle, isort + +[tool.setuptools.packages.find] +where = ["src"] + +[tool.setuptools_scm] +fallback_version = "1.5.0.dev0" +git_describe_command = "git describe --dirty --tags --long --match v*" +tag_regex = "^v(?P[0-9]+\\.[0-9]+\\.[0-9]+(?:[abrc][0-9]+)?(?:\\.post[0-9]+)?(?:\\.dev[0-9]+)?)$" +version_file = "src/keepa/_version.py" diff --git a/src/keepa/__init__.py b/src/keepa/__init__.py index 5f748e4..10068fb 100644 --- a/src/keepa/__init__.py +++ b/src/keepa/__init__.py @@ -2,7 +2,7 @@ from importlib.metadata import PackageNotFoundError, version -# single source versioning from the installed package (stored in pyproject.toml) +# Single source versioning from installed package metadata. try: __version__ = version("keepa") except PackageNotFoundError: diff --git a/uv.lock b/uv.lock index e5a7cac..0145473 100644 --- a/uv.lock +++ b/uv.lock @@ -869,7 +869,6 @@ dependencies = [ ] name = "keepa" source = {editable = "."} -version = "1.5.dev0" [package.metadata] provides-extras = ["doc", "test"]