Mercurial > hgrepos > Python > apps > py-cutils
changeset 285:39a19c008708
Now dynamically the version attribute from setup.cfg
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Sun, 23 Feb 2025 21:40:37 +0100 |
| parents | b65d25882e44 |
| children | 9518944ed42e |
| files | _postprocess-sdist.py |
| diffstat | 1 files changed, 9 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/_postprocess-sdist.py Sun Feb 23 21:27:48 2025 +0100 +++ b/_postprocess-sdist.py Sun Feb 23 21:40:37 2025 +0100 @@ -5,18 +5,15 @@ from __future__ import print_function, absolute_import -import ast try: from configparser import ConfigParser except ImportError: from ConfigParser import SafeConfigParser as ConfigParser +import importlib import io import os import tarfile -import cutils -import cutils.util.walk - def main(): with io.open("setup.cfg", "rt", encoding="utf-8") as cfgfile: @@ -28,8 +25,14 @@ project_name = cp.get("metadata", "name") project_version = cp.get("metadata", "version") if project_version.startswith("attr:"): - assert project_version == "attr: cutils.__version__" - project_version = ast.literal_eval(repr(cutils.__version__)) + vermodname, dummy, vermodattr = (project_version[5:] + .strip() + .rpartition('.')) + assert dummy is not None and vermodattr is not None + vermod = importlib.import_module(vermodname) + project_version = getattr(vermod, vermodattr) + else: + assert False # # Compressed tar files cannot be modified by Python: make sure the # originally generated archive is uncompressed.
