From edeb480c7e84c1ce25806aa4ed6499ff1e2ab49c Mon Sep 17 00:00:00 2001 From: Alexandru Fikl <alexfikl@gmail.com> Date: Tue, 9 Jul 2024 20:15:54 +0300 Subject: [PATCH] version: use importlib --- arraycontext/version.py | 17 +++++++++++++++-- doc/conf.py | 9 +++------ 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/arraycontext/version.py b/arraycontext/version.py index 30c9629..a1da82c 100644 --- a/arraycontext/version.py +++ b/arraycontext/version.py @@ -1,2 +1,15 @@ -VERSION = (2021, 1) -VERSION_TEXT = ".".join(str(i) for i in VERSION) +from importlib import metadata +from typing import Tuple + + +def _parse_version(version: str) -> Tuple[Tuple[int, ...], str]: + import re + + m = re.match("^([0-9.]+)([a-z0-9]*?)$", VERSION_TEXT) + assert m is not None + + return tuple([int(nr) for nr in m.group(1).split(".")]), m.group(2) + + +VERSION_TEXT = metadata.version("arraycontext") +VERSION, VERSION_STATUS = _parse_version(VERSION_TEXT) diff --git a/doc/conf.py b/doc/conf.py index 13c8dd2..0ba4930 100644 --- a/doc/conf.py +++ b/doc/conf.py @@ -1,3 +1,4 @@ +from importlib import metadata from urllib.request import urlopen @@ -8,12 +9,8 @@ with urlopen(_conf_url) as _inf: copyright = "2021, University of Illinois Board of Trustees" author = "Arraycontext Contributors" - -ver_dic = {} -exec(compile(open("../arraycontext/version.py").read(), "../arraycontext/version.py", - "exec"), ver_dic) -version = ".".join(str(x) for x in ver_dic["VERSION"]) -release = ver_dic["VERSION_TEXT"] +release = metadata.version("arraycontext") +version = ".".join(release.split(".")[:2]) intersphinx_mapping = { "jax": ("https://jax.readthedocs.io/en/latest/", None), -- GitLab