Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into pretend-version2
Browse files Browse the repository at this point in the history
  • Loading branch information
basnijholt committed Oct 21, 2024
2 parents 10c4116 + 6cc54bc commit 99a9de7
Show file tree
Hide file tree
Showing 47 changed files with 217 additions and 79 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/install-git-url.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
2 changes: 0 additions & 2 deletions .github/workflows/install-zip-url.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
10 changes: 4 additions & 6 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/tools/minimum-vcs/Dockerfile
Original file line number Diff line number Diff line change
@@ -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; \
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/tools/no-vcs/Dockerfile
Original file line number Diff line number Diff line change
@@ -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
8 changes: 4 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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:
Expand Down
18 changes: 18 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -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
Expand Down
16 changes: 9 additions & 7 deletions README.rst
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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
<https://pip.pypa.io>`_ for Python 3 (You have pip, right?) to install
``versioningit`` and its dependencies::

Expand Down
21 changes: 21 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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 <https://github.com/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
Expand Down
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
<https://pip.pypa.io>`_ for Python 3 (You have pip, right?) to install
``versioningit`` and its dependencies::

Expand Down
4 changes: 2 additions & 2 deletions docs/requirements.txt
Original file line number Diff line number Diff line change
@@ -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
3 changes: 1 addition & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand All @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion src/versioningit/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
<https://versioningit.rtfd.io> for more information.
"""

__version__ = "3.0.0"
__version__ = "3.1.2"
__author__ = "John Thorvald Wodder II"
__author_email__ = "[email protected]"
__license__ = "MIT"
Expand Down
6 changes: 3 additions & 3 deletions src/versioningit/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
17 changes: 13 additions & 4 deletions src/versioningit/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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]:
"""
Expand Down Expand Up @@ -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:
Expand Down
5 changes: 4 additions & 1 deletion src/versioningit/hatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
12 changes: 10 additions & 2 deletions src/versioningit/hg.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Loading

0 comments on commit 99a9de7

Please sign in to comment.