From 412d50c0b9e995d13c14d0ae272176631e43b823 Mon Sep 17 00:00:00 2001 From: joncrall Date: Sun, 3 Dec 2023 14:17:08 -0500 Subject: [PATCH] Move __version__ single source of truth to package __init__ --- jellyfin_apiclient_python/__init__.py | 2 ++ setup.py | 45 ++++++++++++++++++++++++++- 2 files changed, 46 insertions(+), 1 deletion(-) diff --git a/jellyfin_apiclient_python/__init__.py b/jellyfin_apiclient_python/__init__.py index 0ba94cc..0e425b4 100644 --- a/jellyfin_apiclient_python/__init__.py +++ b/jellyfin_apiclient_python/__init__.py @@ -8,6 +8,8 @@ ################################################################################################# +__version__ = '1.9.2' + class NullHandler(logging.Handler): def emit(self, record): diff --git a/setup.py b/setup.py index 713aa81..eac8472 100644 --- a/setup.py +++ b/setup.py @@ -1,11 +1,54 @@ from setuptools import setup + +def parse_version(fpath): + """ + Statically parse the version number from a python file + """ + value = static_parse("__version__", fpath) + return value + + +def static_parse(varname, fpath): + """ + Statically parse the a constant variable from a python file + """ + import ast + from os.path import exists + + if not exists(fpath): + raise ValueError("fpath={!r} does not exist".format(fpath)) + with open(fpath, "r") as file_: + sourcecode = file_.read() + pt = ast.parse(sourcecode) + + class StaticVisitor(ast.NodeVisitor): + def visit_Assign(self, node): + for target in node.targets: + if getattr(target, "id", None) == varname: + self.static_value = node.value.s + + visitor = StaticVisitor() + visitor.visit(pt) + try: + value = visitor.static_value + except AttributeError: + import warnings + + value = "Unknown {}".format(varname) + warnings.warn(value) + return value + with open("README.md", "r") as fh: long_description = fh.read() + +INIT_PATH = "jellyfin_apiclient_python/__init__.py" +VERSION = parse_version(INIT_PATH) + setup( name='jellyfin-apiclient-python', - version='1.9.2', + version=VERSION, author="Ian Walton", author_email="iwalton3@gmail.com", description="Python API client for Jellyfin",