Determine version with versioningit tool
This tool is similar to the setuptools-scm but offers more configuration options which were required in the hivemind use case. Needed: - File-based versioning (write to file) - Substitutions (commit sha) - Substitutions (commit timestamp) Good comparison is available here: https://setuptools-git-versioning.readthedocs.io/en/latest/differences.html
This commit is contained in:
parent
e2d9b4d068
commit
bb931d6ffb
|
@ -1,31 +1,8 @@
|
|||
from datetime import datetime
|
||||
from datetime import timezone
|
||||
from typing import Final
|
||||
|
||||
import git
|
||||
import hive._version as generated
|
||||
|
||||
|
||||
class VersionProvider:
|
||||
"""Static class to provide version and git revision information"""
|
||||
|
||||
repo = git.Repo(search_parent_directories=True)
|
||||
|
||||
@classmethod
|
||||
def latest_tag_on_current_branch(cls) -> str:
|
||||
version = cls.repo.git.describe('--tags', '--abbrev=0')
|
||||
return version
|
||||
|
||||
@classmethod
|
||||
def git_revision(cls, short: bool = False) -> str:
|
||||
sha = cls.repo.head.object.hexsha
|
||||
return sha[:8] if short else sha
|
||||
|
||||
@classmethod
|
||||
def git_revision_datetime(cls) -> datetime:
|
||||
git_datetime = cls.repo.head.object.committed_datetime
|
||||
return git_datetime.astimezone(timezone.utc)
|
||||
|
||||
|
||||
VERSION: Final[str] = VersionProvider.latest_tag_on_current_branch()
|
||||
GIT_REVISION: Final[str] = VersionProvider.git_revision()
|
||||
GIT_DATE: Final[datetime] = VersionProvider.git_revision_datetime()
|
||||
VERSION: Final[str] = generated.__version__
|
||||
GIT_REVISION: Final[str] = generated.__git_revision__
|
||||
GIT_DATE: Final[datetime] = datetime.fromisoformat(generated.__git_revision_date__)
|
||||
|
|
|
@ -3,10 +3,28 @@ build-backend = 'setuptools.build_meta'
|
|||
requires = [
|
||||
'setuptools == 63.1.0',
|
||||
'wheel == 0.37.1',
|
||||
'gitpython == 3.1.27',
|
||||
'versioningit == 2.0.1',
|
||||
]
|
||||
|
||||
|
||||
[tool.versioningit.write]
|
||||
file = 'hive/_version.py'
|
||||
template = """
|
||||
# This file is automatically generated by versioningit during build stage. Do not edit it manually.
|
||||
# Configuration is stored in the pyproject.toml file.
|
||||
|
||||
__version__ = '{version}'
|
||||
__git_revision__ = '{revision}'
|
||||
__git_revision_date__ = '{author_date:%Y-%m-%dT%H:%M:%S}'
|
||||
"""
|
||||
|
||||
|
||||
[tool.versioningit.format]
|
||||
distance = "{base_version}-{distance}+{vcs}{rev}.{author_date:%Y%m%dT%H%M%S}"
|
||||
dirty = "{base_version}+{vcs}{rev}-dirty.{author_date:%Y%m%dT%H%M%S}"
|
||||
distance-dirty = "{base_version}-{distance}+{vcs}{rev}-dirty.{author_date:%Y%m%dT%H%M%S}"
|
||||
|
||||
|
||||
[tool.black]
|
||||
line-length = 120
|
||||
skip-string-normalization = true
|
||||
|
|
Loading…
Reference in New Issue