From 333108a90fd307851e6dcea87f941647c7029a06 Mon Sep 17 00:00:00 2001 From: joncrall Date: Sun, 3 Dec 2023 14:17:08 -0500 Subject: [PATCH 1/2] 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", From 023606895606741393675fc23cfad7a288c8cd28 Mon Sep 17 00:00:00 2001 From: joncrall Date: Sun, 21 Jan 2024 13:00:29 -0500 Subject: [PATCH 2/2] switch from setup.py to pyproject.toml --- pyproject.toml | 33 +++++++++++++++++++++++++ setup.py | 67 -------------------------------------------------- 2 files changed, 33 insertions(+), 67 deletions(-) create mode 100644 pyproject.toml delete mode 100644 setup.py diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..0558f1e --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,33 @@ +[build-system] +requires = [ "setuptools>=61.0.0",] + +[project] +name = "jellyfin-apiclient-python" +authors = [ + {name = "Ian Walton", email = "iwalton3@gmail.com"}, +] +dynamic = ["version"] +description = "Python API client for Jellyfin" +readme = "README.md" +license = {file = "LICENSE.md"} +classifiers = [ + "Programming Language :: Python :: 3", + "License :: OSI Approved :: GNU General Public License v3 (GPLv3)", + "Operating System :: OS Independent", +] +requires-python='>=3.6' +dependencies=[ + 'requests', + 'urllib3', + 'websocket_client', + 'certifi' +] + +[project.urls] +Repository = "https://github.com/iwalton3/jellyfin-apiclient-python" + +[tool.setuptools] +packages = ["jellyfin_apiclient_python"] + +[tool.setuptools.dynamic] +version = {attr = "jellyfin_apiclient_python.__version__"} diff --git a/setup.py b/setup.py deleted file mode 100644 index eac8472..0000000 --- a/setup.py +++ /dev/null @@ -1,67 +0,0 @@ -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=VERSION, - author="Ian Walton", - author_email="iwalton3@gmail.com", - description="Python API client for Jellyfin", - license='GPLv3', - long_description=open('README.md').read(), - long_description_content_type="text/markdown", - url="https://github.com/iwalton3/jellyfin-apiclient-python", - packages=['jellyfin_apiclient_python'], - classifiers=[ - "Programming Language :: Python :: 3", - "License :: OSI Approved :: GNU General Public License v3 (GPLv3)", - "Operating System :: OS Independent", - ], - python_requires='>=3.6', - install_requires=['requests', 'urllib3', 'websocket_client', 'certifi'] -)