| 1 |
# vim: set ft=python ts=4 sw=4 expandtab: |
| 2 |
# ruff: file-ignore[if-else-block-instead-of-dict-get] # _METADATA is not a dict and this doesn't work |
| 3 |
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # |
| 4 |
# |
| 5 |
# C E D A R |
| 6 |
# S O L U T I O N S "Software done right." |
| 7 |
# S O F T W A R E |
| 8 |
# |
| 9 |
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # |
| 10 |
# |
| 11 |
# Author : Kenneth J. Pronovici <[email protected]> |
| 12 |
# Language : Python 3 |
| 13 |
# Project : Cedar Backup, release 3 |
| 14 |
# Purpose : Provides location to maintain release information. |
| 15 |
# |
| 16 |
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # |
| 17 |
|
| 18 |
""" |
| 19 |
Provides a location to maintain version information. |
| 20 |
|
| 21 |
Module Attributes |
| 22 |
================= |
| 23 |
|
| 24 |
Attributes: |
| 25 |
AUTHOR: Author of software |
| 26 |
EMAIL: Email address of author |
| 27 |
VERSION: Software version |
| 28 |
URL: Homepage URL |
| 29 |
|
| 30 |
:author: Kenneth J. Pronovici <[email protected]> |
| 31 |
""" |
| 32 |
|
| 33 |
# Historically, this information was tracked directly within this file as part of the |
| 34 |
# release process. In modern Python, it's better to rely on the package metadata, which |
| 35 |
# is managed by UV on our behalf. |
| 36 |
# |
| 37 |
# The metadata will always be set any time the package has been completely and properly |
| 38 |
# installed. However, there are other cases where it won't be available, such as when |
| 39 |
# running the smoke tests during the Debian build process, or when running the unit tests |
| 40 |
# from within the source tree as a part of the Debian CI suite. So, default values are |
| 41 |
# provided. |
| 42 |
# |
| 43 |
# Note: previously, we also tracked release date and copyright date range, but that |
| 44 |
# information is not available in the package metadata. These values are maintained to |
| 45 |
# avoid breaking the public interface, but are always "unset". |
| 46 |
|
| 47 |
import re |
| 48 |
from importlib.metadata import metadata |
| 49 |
|
| 50 |
try: |
| 51 |
_METADATA = metadata("cedar-backup3") |
| 52 |
except ImportError: |
| 53 |
_METADATA = {} |
| 54 |
|
| 55 |
# Regex matching the Author-email metadata entry generated by UV, an optionally-quoted name plus email address |
| 56 |
_REGEX = r"(^)(\"?)([^<\"]*)(\"?)( <)([^>]*)(>$)" |
| 57 |
|
| 58 |
|
| 59 |
def _project_url(key: str, default: str) -> str: |
| 60 |
urls = _METADATA.get_all("Project-URL") |
| 61 |
if urls is None: |
| 62 |
urls = [] |
| 63 |
return next( |
| 64 |
iter([url.replace(f"{key}, ", "") for url in urls if url.startswith(f"{key}, ")]), |
| 65 |
default, |
| 66 |
) |
| 67 |
|
| 68 |
|
| 69 |
AUTHOR = re.sub(_REGEX, r"\3", _METADATA["Author-email"]) if "Author-email" in _METADATA else "unset" |
| 70 |
EMAIL = re.sub(_REGEX, r"\6", _METADATA["Author-email"]) if "Author-email" in _METADATA else "unset" |
| 71 |
VERSION = _METADATA["Version"] if "Version" in _METADATA else "0.0.0" |
| 72 |
URL = _project_url("Homepage", "unset") |
| 73 |
|
| 74 |
COPYRIGHT = "unset" |
| 75 |
DATE = "unset" |