From 8e06110648fb4c182f75eddcf8787ed7e81f213c Mon Sep 17 00:00:00 2001 From: Max Gautier Date: Mon, 19 Sep 2022 11:10:25 +0200 Subject: [PATCH] Use dynamic versioning with git tags --- producer.py | 16 +++++++++++----- pyproject.toml | 6 ++++-- version.py | 20 -------------------- 3 files changed, 15 insertions(+), 27 deletions(-) delete mode 100644 version.py diff --git a/producer.py b/producer.py index 227af79..53ecb65 100644 --- a/producer.py +++ b/producer.py @@ -26,15 +26,12 @@ import click as cli -from version import __version__ +from importlib.metadata import version, PackageNotFoundError -from thoth.common import __version__ as __common__version__ from thoth.common import init_logging -from thoth.storages import __version__ as __storages__version__ from thoth.storages import GraphDatabase -from thoth.messaging import __version__ as __messaging__version__ import thoth.messaging.producer as producer from thoth.messaging import package_released_message from thoth.messaging.package_releases import MessageContents as PackageReleasedContent @@ -46,6 +43,11 @@ from thoth.python import AIOSource from thoth.python.exceptions import NotFoundError +try: + __version__ = version(__package__) +except PackageNotFoundError: + __version__ = "v0.11.10" # TODO makes this unnecessary by fixing users of the package + init_logging() prometheus_registry = CollectorRegistry() @@ -53,7 +55,11 @@ p = producer.create_producer() _LOGGER = logging.getLogger("thoth.package_releases_job") -__service_version__ = f"{__version__}+storages.{__storages__version__}.common.{__common__version__}.messaging.{__messaging__version__}.python.{__python__version__}" # noqa: E501 +__service_version__ = ( + f"{__version__}+" + + ".".join(version(f"thoth-{p}") for p in ["storages", "common", "messaging"]) + + f".python.{__python__version__}" +) _LOGGER.info("Thoth-package-releases-job-producer v%s", __service_version__) _THOTH_DEPLOYMENT_NAME = os.environ["THOTH_DEPLOYMENT_NAME"] diff --git a/pyproject.toml b/pyproject.toml index a5c5a22..96b706d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,13 +4,15 @@ description = "Check packages updates on Python package indexes" readme = "README.rst" requires-python = ">=3.8" license = {file = "LICENSE"} -version = "v0.11.10" +dynamic = ["version"] [project.scripts] package-releases-job = "producer:main" [build-system] -requires = ["setuptools", "wheel"] +requires = ["setuptools", "wheel", "setuptools_scm"] + +[tool.setuptools_scm] [tool.black] line-length = 120 diff --git a/version.py b/version.py deleted file mode 100644 index 1ae9748..0000000 --- a/version.py +++ /dev/null @@ -1,20 +0,0 @@ -#!/usr/bin/env python3 -# Package Releases Job -# Copyright(C) 2020 Red Hat, Inc. -# -# This program is free software: you can redistribute it and / or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - -"""This file carries the version of the package releases job.""" - -__version__ = "0.11.10"