diff --git a/.github/workflows/install-git-url.yml b/.github/workflows/install-git-url.yml index 4a5bcd1..5d7918a 100644 --- a/.github/workflows/install-git-url.yml +++ b/.github/workflows/install-git-url.yml @@ -27,13 +27,11 @@ jobs: - ubuntu-latest - windows-latest python-version: - - '3.7' - '3.8' - '3.9' - '3.10' - '3.11' - '3.12' - - 'pypy-3.7' - 'pypy-3.8' - 'pypy-3.9' - 'pypy-3.10' diff --git a/.github/workflows/install-zip-url.yml b/.github/workflows/install-zip-url.yml index e9357ca..b4a80fa 100644 --- a/.github/workflows/install-zip-url.yml +++ b/.github/workflows/install-zip-url.yml @@ -27,13 +27,11 @@ jobs: - ubuntu-latest - windows-latest python-version: - - '3.7' - '3.8' - '3.9' - '3.10' - '3.11' - '3.12' - - 'pypy-3.7' - 'pypy-3.8' - 'pypy-3.9' - 'pypy-3.10' diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 3e79b73..11b2bd2 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -23,25 +23,23 @@ jobs: - ubuntu-latest - windows-latest python-version: - - '3.7' - '3.8' - '3.9' - '3.10' - '3.11' - '3.12' - - 'pypy-3.7' - 'pypy-3.8' - 'pypy-3.9' - 'pypy-3.10' toxenv: [py] include: - - python-version: '3.7' + - python-version: '3.8' toxenv: lint os: ubuntu-latest - - python-version: '3.7' + - python-version: '3.8' toxenv: typing os: ubuntu-latest - - python-version: '3.7' + - python-version: '3.8' toxenv: py-oldsetup os: ubuntu-latest steps: @@ -52,7 +50,7 @@ jobs: # Mercurial seems to be broken on PyPy, so we need to install it before # overriding the default Python. if: startsWith(matrix.os, 'macos-') - run: python3 -m pip install mercurial + run: brew install mercurial - name: Set up Python uses: actions/setup-python@v5 diff --git a/.github/workflows/tools/minimum-vcs/Dockerfile b/.github/workflows/tools/minimum-vcs/Dockerfile index 5f2e3fd..359de45 100644 --- a/.github/workflows/tools/minimum-vcs/Dockerfile +++ b/.github/workflows/tools/minimum-vcs/Dockerfile @@ -1,4 +1,4 @@ -FROM python:3.7-buster +FROM python:3.8-buster RUN set -ex; \ cd tmp; \ wget http://snapshot.debian.org/archive/debian/20121102T092448Z/pool/main/g/git/git-man_1.8.0-1_all.deb; \ diff --git a/.github/workflows/tools/no-vcs/Dockerfile b/.github/workflows/tools/no-vcs/Dockerfile index b7d38e8..5501124 100644 --- a/.github/workflows/tools/no-vcs/Dockerfile +++ b/.github/workflows/tools/no-vcs/Dockerfile @@ -1,4 +1,4 @@ -FROM python:3.7-slim +FROM python:3.8-slim RUN set -ex; \ pip install --upgrade pip wheel; \ pip install --upgrade --upgrade-strategy=eager tox diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index c0d9f21..b2a1a1d 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,6 +1,6 @@ repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.4.0 + rev: v4.6.0 hooks: - id: check-added-large-files - id: check-json @@ -12,19 +12,19 @@ repos: exclude: '\.eml$' - repo: https://github.com/psf/black - rev: 23.1.0 + rev: 24.4.2 hooks: - id: black exclude: ^test/data - repo: https://github.com/PyCQA/isort - rev: 5.12.0 + rev: 5.13.2 hooks: - id: isort exclude: ^test/data - repo: https://github.com/PyCQA/flake8 - rev: 6.0.0 + rev: 7.0.0 hooks: - id: flake8 additional_dependencies: diff --git a/CHANGELOG.md b/CHANGELOG.md index 0b16a07..e1a7efe 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,21 @@ +v3.1.2 (2024-07-20) +------------------- +- Drop support for Python 3.7 +- **Bugfix**: When using `versioningit` with Hatch, don't run the `onbuild` + step for editable builds + +v3.1.1 (2024-04-29) +------------------- +- Correctly mark a certain test as requiring Mercurial + +v3.1.0 (2024-03-16) +------------------- +- When `git describe` fails to retrieve a tag, the resulting log/error message + now includes all options passed to the command (based on contribution by + [@jenshnielsen](https://github.com/jenshnielsen)) +- When `hg log` fails to retrieve a tag, the resulting log/error message now + includes the tag pattern passed to `latesttag()`, if any + v3.0.0 (2023-12-13) ------------------- - Migrated from setuptools to hatch diff --git a/LICENSE b/LICENSE index 48e904b..9e4d4ed 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2021-2023 John Thorvald Wodder II and contributors +Copyright (c) 2021-2024 John Thorvald Wodder II and contributors Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.rst b/README.rst index 7805ec8..e52b915 100644 --- a/README.rst +++ b/README.rst @@ -1,23 +1,25 @@ -.. image:: https://www.repostatus.org/badges/latest/active.svg +|repostatus| |ci-status| |coverage| |pyversions| |conda| |license| + +.. |repostatus| image:: https://www.repostatus.org/badges/latest/active.svg :target: https://www.repostatus.org/#active :alt: Project Status: Active — The project has reached a stable, usable state and is being actively developed. -.. image:: https://github.com/jwodder/versioningit/actions/workflows/test.yml/badge.svg +.. |ci-status| image:: https://github.com/jwodder/versioningit/actions/workflows/test.yml/badge.svg :target: https://github.com/jwodder/versioningit/actions/workflows/test.yml :alt: CI Status -.. image:: https://codecov.io/gh/jwodder/versioningit/branch/master/graph/badge.svg +.. |coverage| image:: https://codecov.io/gh/jwodder/versioningit/branch/master/graph/badge.svg :target: https://codecov.io/gh/jwodder/versioningit -.. image:: https://img.shields.io/pypi/pyversions/versioningit.svg +.. |pyversions| image:: https://img.shields.io/pypi/pyversions/versioningit.svg :target: https://pypi.org/project/versioningit/ -.. image:: https://img.shields.io/conda/vn/conda-forge/versioningit.svg +.. |conda| image:: https://img.shields.io/conda/vn/conda-forge/versioningit.svg :target: https://anaconda.org/conda-forge/versioningit :alt: Conda Version -.. image:: https://img.shields.io/github/license/jwodder/versioningit.svg +.. |license| image:: https://img.shields.io/github/license/jwodder/versioningit.svg :target: https://opensource.org/licenses/MIT :alt: MIT License @@ -71,7 +73,7 @@ extraction & calculation. Installation & Setup ==================== -``versioningit`` requires Python 3.7 or higher. Just use `pip +``versioningit`` requires Python 3.8 or higher. Just use `pip `_ for Python 3 (You have pip, right?) to install ``versioningit`` and its dependencies:: diff --git a/docs/changelog.rst b/docs/changelog.rst index 1f42052..6969d36 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -3,6 +3,27 @@ Changelog ========= +v3.1.2 (2024-07-20) +------------------- +- Drop support for Python 3.7 +- **Bugfix**: When using `versioningit` with Hatch, don't run the `onbuild` + step for editable builds + + +v3.1.1 (2024-04-29) +------------------- +- Correctly mark a certain test as requiring Mercurial + + +v3.1.0 (2024-03-16) +------------------- +- When :command:`git describe` fails to retrieve a tag, the resulting log/error + message now includes all options passed to the command (based on contribution + by `@jenshnielsen `_) +- When :command:`hg log` fails to retrieve a tag, the resulting log/error + message now includes the tag pattern passed to ``latesttag()``, if any + + v3.0.0 (2023-12-13) ------------------- - Migrated from setuptools to hatch diff --git a/docs/conf.py b/docs/conf.py index f2ff574..9bb5553 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -2,7 +2,7 @@ project = "versioningit" author = "John Thorvald Wodder II" -copyright = "2021-2023 John Thorvald Wodder II" # noqa: A001 +copyright = "2021-2024 John Thorvald Wodder II" # noqa: A001 extensions = [ "sphinx.ext.autodoc", diff --git a/docs/index.rst b/docs/index.rst index b4b4626..50bebbf 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -66,7 +66,7 @@ extraction & calculation. Installation & Setup ==================== -``versioningit`` requires Python 3.7 or higher. Just use `pip +``versioningit`` requires Python 3.8 or higher. Just use `pip `_ for Python 3 (You have pip, right?) to install ``versioningit`` and its dependencies:: diff --git a/docs/requirements.txt b/docs/requirements.txt index 8b64efa..d657b42 100644 --- a/docs/requirements.txt +++ b/docs/requirements.txt @@ -1,4 +1,4 @@ -Sphinx~=7.0 +Sphinx~=8.0 sphinx-copybutton~=0.5.0 sphinx-inline-tabs -sphinx_rtd_theme~=2.0 +sphinx_rtd_theme~=3.0 diff --git a/pyproject.toml b/pyproject.toml index 868c2f5..fb46e97 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -7,7 +7,7 @@ name = "versioningit" dynamic = ["version"] description = "Versioning It with your Version In Git" readme = "README.rst" -requires-python = ">=3.7" +requires-python = ">=3.8" license = "MIT" license-files = { paths = ["LICENSE"] } authors = [ @@ -26,7 +26,6 @@ classifiers = [ "Development Status :: 5 - Production/Stable", "Programming Language :: Python :: 3 :: Only", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.7", "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", diff --git a/src/versioningit/__init__.py b/src/versioningit/__init__.py index c908432..d92f0dc 100644 --- a/src/versioningit/__init__.py +++ b/src/versioningit/__init__.py @@ -43,7 +43,7 @@ for more information. """ -__version__ = "3.0.0" +__version__ = "3.1.2" __author__ = "John Thorvald Wodder II" __author_email__ = "versioningit@varonathe.org" __license__ = "MIT" diff --git a/src/versioningit/core.py b/src/versioningit/core.py index 3ba39ec..cbc3b2d 100644 --- a/src/versioningit/core.py +++ b/src/versioningit/core.py @@ -190,9 +190,9 @@ def from_config(cls, project_dir: str | Path, config: Config) -> Versioningit: format=config.format.load(project_dir), template_fields=config.template_fields.load(project_dir), write=config.write.load(project_dir) if config.write is not None else None, - onbuild=config.onbuild.load(project_dir) - if config.onbuild is not None - else None, + onbuild=( + config.onbuild.load(project_dir) if config.onbuild is not None else None + ), ) def get_version(self, write: bool = False, fallback: bool = True) -> str: diff --git a/src/versioningit/git.py b/src/versioningit/git.py index 75de4c1..125396a 100644 --- a/src/versioningit/git.py +++ b/src/versioningit/git.py @@ -3,6 +3,7 @@ from datetime import datetime from pathlib import Path import re +import shlex import subprocess from typing import Any, NamedTuple, Optional from .core import VCSDescription @@ -128,6 +129,11 @@ def as_args(self) -> list[str]: args.append(f"--exclude={pat}") return args + def as_cmdline_str(self) -> str: + return "git describe --long --dirty --always" + "".join( + " " + shlex.quote(a) for a in self.as_args() + ) + @dataclass class GitRepo: @@ -194,7 +200,9 @@ def describe(self, opts: DescribeOpts) -> str: except subprocess.CalledProcessError as e: # As far as I'm aware, this only happens in a repo without any # commits or a corrupted repo. - raise NoTagError(f"`git describe` command failed: {e.stderr.strip()}") + raise NoTagError( + f"`{opts.as_cmdline_str()}` command failed: {e.stderr.strip()}" + ) def get_branch(self) -> Optional[str]: """ @@ -338,15 +346,16 @@ def describe_git_core( except ValueError: if default_tag is not None: log.info( - "`git describe` returned a hash instead of a tag; falling back to" - " default tag %r", + "`%s` returned a hash instead of a tag; falling back to default" + " tag %r", + opts.as_cmdline_str(), default_tag, ) tag = default_tag distance = int(repo.read("rev-list", "--count", "HEAD")) - 1 rev = description else: - raise NoTagError("`git describe` could not find a tag") + raise NoTagError(f"`{opts.as_cmdline_str()}` could not find a tag") if distance and dirty: state = "distance-dirty" elif distance: diff --git a/src/versioningit/hatch.py b/src/versioningit/hatch.py index e0acac8..a4c0471 100644 --- a/src/versioningit/hatch.py +++ b/src/versioningit/hatch.py @@ -28,7 +28,7 @@ def get_version_data(self) -> dict: init_logging() PROJECT_ROOT = Path(self.root) log.info("Project dir: %s", PROJECT_ROOT) - pretend_version = get_pretend_version() + pretend_version = get_pretend_version(project_root=PROJECT_ROOT) if pretend_version is not None: return {"version": pretend_version} try: @@ -76,8 +76,11 @@ def __init__(self, *args: Any, **kwargs: Any) -> None: super().__init__(*args, **kwargs) self.__tmpdir = Path(tempfile.mkdtemp()) - def initialize(self, _version: str, build_data: dict[str, Any]) -> None: + def initialize(self, version: str, build_data: dict[str, Any]) -> None: init_logging() + if self.target_name == "wheel" and version == "editable": + log.debug("Not running onbuild step for editable build") + return None version_source = self.metadata.hatch.version.source if not isinstance(version_source, VersioningitSource): raise RuntimeError( diff --git a/src/versioningit/hg.py b/src/versioningit/hg.py index 538e8df..1360670 100644 --- a/src/versioningit/hg.py +++ b/src/versioningit/hg.py @@ -102,15 +102,23 @@ def describe_hg(*, project_dir: str | Path, params: dict[str, Any]) -> VCSDescri else: dirty = False if tag == "null": + if pattern is None: + suffix = "" + else: + suffix = f" (pattern = {pattern!r})" + # Unlike the Git methods, don't show the full `hg log` command run, as + # shlex.quote() on `--template` arguments returns something *ugly*. if default_tag is not None: - log.info("No latest tag; falling back to default tag %r", default_tag) + log.info( + "No latest tag%s; falling back to default tag %r", suffix, default_tag + ) tag = default_tag # Act as though the first commit is the one with the default tag, # i.e., don't count it (unless there is no first commit, of course) if distance > 0: distance -= 1 else: - raise NoTagError("No latest tag in Mercurial repository") + raise NoTagError(f"No latest tag in Mercurial repository{suffix}") if distance and dirty: state = "distance-dirty" elif distance: diff --git a/src/versioningit/onbuild.py b/src/versioningit/onbuild.py index c7c076f..7931a02 100644 --- a/src/versioningit/onbuild.py +++ b/src/versioningit/onbuild.py @@ -63,8 +63,7 @@ def open( encoding: str | None = None, errors: str | None = None, newline: str | None = None, - ) -> TextIO: - ... + ) -> TextIO: ... @overload def open( @@ -73,8 +72,7 @@ def open( encoding: None = None, errors: None = None, newline: None = None, - ) -> IO[bytes]: - ... + ) -> IO[bytes]: ... @abstractmethod def open( @@ -142,8 +140,7 @@ def open( encoding: str | None = None, errors: str | None = None, newline: str | None = None, - ) -> TextIO: - ... + ) -> TextIO: ... @overload def open( @@ -152,8 +149,7 @@ def open( encoding: None = None, errors: None = None, newline: None = None, - ) -> IO[bytes]: - ... + ) -> IO[bytes]: ... def open( self, @@ -236,8 +232,7 @@ def open( encoding: str | None = None, errors: str | None = None, newline: str | None = None, - ) -> TextIO: - ... + ) -> TextIO: ... @overload def open( @@ -246,8 +241,7 @@ def open( encoding: None = None, errors: None = None, newline: None = None, - ) -> IO[bytes]: - ... + ) -> IO[bytes]: ... def open( self, diff --git a/test/data/repos/errors/hatch-no-tag.json b/test/data/repos/errors/hatch-no-tag.json deleted file mode 100644 index 26fd050..0000000 --- a/test/data/repos/errors/hatch-no-tag.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "type": "NoTagError", - "message": "`git describe` could not find a tag" -} diff --git a/test/data/repos/errors/no-tag.json b/test/data/repos/errors/no-tag.json deleted file mode 100644 index 26fd050..0000000 --- a/test/data/repos/errors/no-tag.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "type": "NoTagError", - "message": "`git describe` could not find a tag" -} diff --git a/test/data/repos/git-errors/archive-no-tag.json b/test/data/repos/git-errors/archive-no-tag.json new file mode 100644 index 0000000..a59a9f0 --- /dev/null +++ b/test/data/repos/git-errors/archive-no-tag.json @@ -0,0 +1,4 @@ +{ + "type": "NoTagError", + "message": "`git describe --long --dirty --always '--exclude=v*'` could not find a tag" +} diff --git a/test/data/repos/errors/hatch-no-tag.marks b/test/data/repos/git-errors/archive-no-tag.marks similarity index 100% rename from test/data/repos/errors/hatch-no-tag.marks rename to test/data/repos/git-errors/archive-no-tag.marks diff --git a/test/data/repos/git-errors/archive-no-tag.zip b/test/data/repos/git-errors/archive-no-tag.zip new file mode 100644 index 0000000..85e135f Binary files /dev/null and b/test/data/repos/git-errors/archive-no-tag.zip differ diff --git a/test/data/repos/git-errors/hatch-no-tag.json b/test/data/repos/git-errors/hatch-no-tag.json new file mode 100644 index 0000000..8cb1d08 --- /dev/null +++ b/test/data/repos/git-errors/hatch-no-tag.json @@ -0,0 +1,4 @@ +{ + "type": "NoTagError", + "message": "`git describe --long --dirty --always --tags '--exclude=*'` could not find a tag" +} diff --git a/test/data/repos/errors/no-tag.marks b/test/data/repos/git-errors/hatch-no-tag.marks similarity index 100% rename from test/data/repos/errors/no-tag.marks rename to test/data/repos/git-errors/hatch-no-tag.marks diff --git a/test/data/repos/errors/hatch-no-tag.zip b/test/data/repos/git-errors/hatch-no-tag.zip similarity index 100% rename from test/data/repos/errors/hatch-no-tag.zip rename to test/data/repos/git-errors/hatch-no-tag.zip diff --git a/test/data/repos/git-errors/no-tag.json b/test/data/repos/git-errors/no-tag.json new file mode 100644 index 0000000..8cb1d08 --- /dev/null +++ b/test/data/repos/git-errors/no-tag.json @@ -0,0 +1,4 @@ +{ + "type": "NoTagError", + "message": "`git describe --long --dirty --always --tags '--exclude=*'` could not find a tag" +} diff --git a/test/data/repos/git-errors/no-tag.marks b/test/data/repos/git-errors/no-tag.marks new file mode 100644 index 0000000..40e6dd3 --- /dev/null +++ b/test/data/repos/git-errors/no-tag.marks @@ -0,0 +1 @@ +describe_exclude diff --git a/test/data/repos/errors/no-tag.zip b/test/data/repos/git-errors/no-tag.zip similarity index 100% rename from test/data/repos/errors/no-tag.zip rename to test/data/repos/git-errors/no-tag.zip diff --git a/test/data/repos/errors/template-fields-error.json b/test/data/repos/git-errors/template-fields-error.json similarity index 100% rename from test/data/repos/errors/template-fields-error.json rename to test/data/repos/git-errors/template-fields-error.json diff --git a/test/data/repos/errors/template-fields-error.zip b/test/data/repos/git-errors/template-fields-error.zip similarity index 100% rename from test/data/repos/errors/template-fields-error.zip rename to test/data/repos/git-errors/template-fields-error.zip diff --git a/test/data/repos/git/added-no-commits-default-tag.json b/test/data/repos/git/added-no-commits-default-tag.json index 780dea1..2bfffba 100644 --- a/test/data/repos/git/added-no-commits-default-tag.json +++ b/test/data/repos/git/added-no-commits-default-tag.json @@ -1,4 +1,14 @@ { "version": "0.0.0+d20380119", - "next_version": "0.1.0" + "next_version": "0.1.0", + "logmsgs": [ + { + "level": "ERROR", + "message": "`git describe --long --dirty --always --tags` command failed: fatal: bad revision 'HEAD'" + }, + { + "level": "INFO", + "message": "Falling back to default tag 'v0.0.0'" + } + ] } diff --git a/test/data/repos/git/default-tag.json b/test/data/repos/git/default-tag.json index 7a15df2..2f694bb 100644 --- a/test/data/repos/git/default-tag.json +++ b/test/data/repos/git/default-tag.json @@ -1,4 +1,10 @@ { "version": "0.0.0.post2+gb4461bd", - "next_version": "0.1.0" + "next_version": "0.1.0", + "logmsgs": [ + { + "level": "INFO", + "message": "`git describe --long --dirty --always --tags` returned a hash instead of a tag; falling back to default tag 'v0.0.0'" + } + ] } diff --git a/test/data/repos/git/default-version-bad.json b/test/data/repos/git/default-version-bad.json index 66d81b8..9c3299a 100644 --- a/test/data/repos/git/default-version-bad.json +++ b/test/data/repos/git/default-version-bad.json @@ -2,12 +2,12 @@ "version": "1.1.1m", "next_version": { "type": "NoTagError", - "message": "`git describe` could not find a tag" + "message": "`git describe --long --dirty --always --tags` could not find a tag" }, "logmsgs": [ { "level": "ERROR", - "message": "NoTagError: `git describe` could not find a tag" + "message": "NoTagError: `git describe --long --dirty --always --tags` could not find a tag" }, { "level": "INFO", diff --git a/test/data/repos/git/default-version-onbuild-write.json b/test/data/repos/git/default-version-onbuild-write.json index e923fe8..f79911b 100644 --- a/test/data/repos/git/default-version-onbuild-write.json +++ b/test/data/repos/git/default-version-onbuild-write.json @@ -2,12 +2,12 @@ "version": "0.0.0+error", "next_version": { "type": "NoTagError", - "message": "`git describe` could not find a tag" + "message": "`git describe --long --dirty --always --tags '--match=v*'` could not find a tag" }, "logmsgs": [ { "level": "ERROR", - "message": "NoTagError: `git describe` could not find a tag" + "message": "NoTagError: `git describe --long --dirty --always --tags '--match=v*'` could not find a tag" }, { "level": "INFO", diff --git a/test/data/repos/git/default-version.json b/test/data/repos/git/default-version.json index 0f3e8d3..26ee5e8 100644 --- a/test/data/repos/git/default-version.json +++ b/test/data/repos/git/default-version.json @@ -2,12 +2,12 @@ "version": "0.0.0+error", "next_version": { "type": "NoTagError", - "message": "`git describe` could not find a tag" + "message": "`git describe --long --dirty --always --tags` could not find a tag" }, "logmsgs": [ { "level": "ERROR", - "message": "NoTagError: `git describe` could not find a tag" + "message": "NoTagError: `git describe --long --dirty --always --tags` could not find a tag" }, { "level": "INFO", diff --git a/test/data/repos/hg-errors/hg-no-tag.json b/test/data/repos/hg-errors/hg-no-tag.json new file mode 100644 index 0000000..f70dcfb --- /dev/null +++ b/test/data/repos/hg-errors/hg-no-tag.json @@ -0,0 +1,4 @@ +{ + "type": "NoTagError", + "message": "No latest tag in Mercurial repository (pattern = 're:^v')" +} diff --git a/test/data/repos/hg-errors/hg-no-tag.zip b/test/data/repos/hg-errors/hg-no-tag.zip new file mode 100644 index 0000000..dbe99e1 Binary files /dev/null and b/test/data/repos/hg-errors/hg-no-tag.zip differ diff --git a/test/data/repos/hg/default-tag-fallback.fields.json b/test/data/repos/hg/default-tag-fallback.fields.json new file mode 100644 index 0000000..0ed570c --- /dev/null +++ b/test/data/repos/hg/default-tag-fallback.fields.json @@ -0,0 +1,8 @@ +{ + "build_date": "2038-01-19 03:14:07+00:00", + "distance": 3, + "rev": "5296453555c9", + "revision": "5296453555c92c22bab469752758a549e297c922", + "vcs": "h", + "vcs_name": "hg" +} diff --git a/test/data/repos/hg/default-tag-fallback.json b/test/data/repos/hg/default-tag-fallback.json new file mode 100644 index 0000000..be4ec96 --- /dev/null +++ b/test/data/repos/hg/default-tag-fallback.json @@ -0,0 +1,10 @@ +{ + "version": "0.0.0.post3+h5296453555c9", + "next_version": "0.1.0", + "logmsgs": [ + { + "level": "INFO", + "message": "No latest tag (pattern = 're:^v'); falling back to default tag 'v0.0.0'" + } + ] +} diff --git a/test/data/repos/hg/default-tag-fallback.zip b/test/data/repos/hg/default-tag-fallback.zip new file mode 100644 index 0000000..39bf79b Binary files /dev/null and b/test/data/repos/hg/default-tag-fallback.zip differ diff --git a/test/test_end2end.py b/test/test_end2end.py index c021741..04b37d1 100644 --- a/test/test_end2end.py +++ b/test/test_end2end.py @@ -240,9 +240,32 @@ def test_get_version_config_only( @pytest.mark.parametrize( - "repozip,details", mkcases("errors", [needs_git], details_cls=ErrorDetails) + "repozip,details", mkcases("git-errors", [needs_git], details_cls=ErrorDetails) ) -def test_end2end_error(tmp_path: Path, repozip: Path, details: ErrorDetails) -> None: +def test_end2end_git_error( + tmp_path: Path, repozip: Path, details: ErrorDetails +) -> None: + shutil.unpack_archive(repozip, tmp_path) + with pytest.raises(Error) as excinfo: + get_version(project_dir=tmp_path, write=False, fallback=True) + assert type(excinfo.value).__name__ == details.type + assert str(excinfo.value) == details.message + r = subprocess.run( + [sys.executable, "-m", "build", "--no-isolation", str(tmp_path)], + stdout=subprocess.PIPE, + stderr=subprocess.STDOUT, + text=True, + ) + assert r.returncode != 0 + out = r.stdout + assert isinstance(out, str) + assert details.message in out + + +@pytest.mark.parametrize( + "repozip,details", mkcases("hg-errors", [needs_hg], details_cls=ErrorDetails) +) +def test_end2end_hg_error(tmp_path: Path, repozip: Path, details: ErrorDetails) -> None: shutil.unpack_archive(repozip, tmp_path) with pytest.raises(Error) as excinfo: get_version(project_dir=tmp_path, write=False, fallback=True) @@ -376,6 +399,10 @@ def test_editable_mode(cmd: list[str], tmp_path: Path) -> None: assert get_repo_status(srcdir) == status info = readcmd(sys.executable, "-m", "pip", "show", "mypackage") assert parse_version_from_metadata(info) == details.version + version_var = readcmd( + sys.executable, "-c", "import mypackage; print(mypackage.__version__)" + ) + assert version_var == "NOT SET" for f in details.files: f.check(srcdir, "project") finally: @@ -402,6 +429,10 @@ def test_editable_mode_hatch(tmp_path: Path) -> None: assert get_repo_status(srcdir) == status info = readcmd(sys.executable, "-m", "pip", "show", "mypackage") assert parse_version_from_metadata(info) == details.version + version_var = readcmd( + sys.executable, "-c", "import mypackage; print(mypackage.__version__)" + ) + assert version_var == "NOT SET" for f in details.files: f.check(srcdir, "project") finally: diff --git a/test/test_methods/test_git.py b/test/test_methods/test_git.py index 7fa25d2..cb7a422 100644 --- a/test/test_methods/test_git.py +++ b/test/test_methods/test_git.py @@ -81,7 +81,10 @@ def test_describe_git_no_tag(tmp_path: Path) -> None: shutil.unpack_archive(DATA_DIR / "repos" / "git" / "default-tag.zip", tmp_path) with pytest.raises(NoTagError) as excinfo: describe_git(project_dir=tmp_path, params={}) - assert str(excinfo.value) == "`git describe` could not find a tag" + assert ( + str(excinfo.value) + == "`git describe --long --dirty --always --tags` could not find a tag" + ) @needs_git @@ -105,7 +108,10 @@ def test_describe_git_added_no_commits(tmp_path: Path) -> None: shutil.unpack_archive( DATA_DIR / "repos" / "git" / "added-no-commits-default-tag.zip", tmp_path ) - with pytest.raises(NoTagError, match=r"^`git describe` command failed: "): + with pytest.raises( + NoTagError, + match=r"^`git describe --long --dirty --always --tags` command failed: ", + ): describe_git(project_dir=tmp_path, params={}) @@ -226,7 +232,7 @@ def test_describe_git_archive_added_no_commits_default_tag( assert any( logger == "versioningit" and level == logging.ERROR - and re.match("^`git describe` command failed: ", msg) + and re.match("^`git describe --long --dirty --always` command failed: ", msg) for logger, level, msg in caplog.record_tuples ) assert ( @@ -244,7 +250,10 @@ def test_describe_git_archive_lightweight_only(tmp_path: Path) -> None: project_dir=tmp_path, params={"describe-subst": "$Format:%(describe)$"}, ) - assert str(excinfo.value) == "`git describe` could not find a tag" + assert ( + str(excinfo.value) + == "`git describe --long --dirty --always` could not find a tag" + ) @needs_git @@ -274,8 +283,8 @@ def test_describe_git_archive_lightweight_only_default_tag( assert ( "versioningit", logging.INFO, - "`git describe` returned a hash instead of a tag; falling back to" - " default tag '0.0.0'", + "`git describe --long --dirty --always` returned a hash instead of a" + " tag; falling back to default tag '0.0.0'", ) in caplog.record_tuples diff --git a/test/test_methods/test_hg.py b/test/test_methods/test_hg.py index 79c7029..4ed77a1 100644 --- a/test/test_methods/test_hg.py +++ b/test/test_methods/test_hg.py @@ -39,6 +39,12 @@ class HGFields(BaseModel): ("distance", {}, "v0.1.0", "distance"), ("distance-dirty", {}, "v0.1.0", "distance-dirty"), ("default-tag", {"default-tag": "v0.0.0"}, "v0.0.0", "distance"), + ( + "default-tag-fallback", + {"default-tag": "v0.0.0", "pattern": "re:^v"}, + "v0.0.0", + "distance", + ), ("pattern", {"pattern": r"re:^v"}, "v0.1.0", "distance"), ], ) diff --git a/tox.ini b/tox.ini index b24e124..414e19f 100644 --- a/tox.ini +++ b/tox.ini @@ -1,5 +1,5 @@ [tox] -envlist = lint,typing,py37,py38,py39,py310,py311,py312,pypy3,py-oldsetup +envlist = lint,typing,py38,py39,py310,py311,py312,pypy3,py-oldsetup skip_missing_interpreters = True isolated_build = True minversion = 3.3.0 @@ -7,6 +7,7 @@ minversion = 3.3.0 [testenv] deps = build>=0.7 # Must be a version that builds wheels from sdists + editables hatchling setuptools>=42 pip @@ -87,7 +88,7 @@ max-doc-length = 100 max-line-length = 80 unused-arguments-ignore-stub-functions = True extend-select = B901,B902,B950 -ignore = A003,B005,E203,E262,E266,E501,U101,W503 +ignore = A003,A005,B005,E203,E262,E266,E501,E704,U101,W503 [isort] atomic = True