From 0ec93d7d0ffe6dd8f56bed3c9e9b4f268a752689 Mon Sep 17 00:00:00 2001 From: krateng Date: Sat, 25 Dec 2021 23:43:34 +0100 Subject: [PATCH] Reworked pkginfo again --- maloja/__pkginfo__.py | 25 ++++++++++++++----------- maloja/apis/native_v1.py | 6 +++--- maloja/globalconf.py | 4 ++-- maloja/proccontrol/control.py | 6 +++--- maloja/thirdparty/musicbrainz.py | 4 ++-- maloja/utilities/maintenance.py | 4 ++-- pyproject.toml | 2 +- 7 files changed, 27 insertions(+), 24 deletions(-) diff --git a/maloja/__pkginfo__.py b/maloja/__pkginfo__.py index df9a902..470c50e 100644 --- a/maloja/__pkginfo__.py +++ b/maloja/__pkginfo__.py @@ -2,19 +2,22 @@ # the package access to some global meta-information about itself try: - # package distributrion - import pkg_resources - self = pkg_resources.get_distribution('maloja') - metadata = {'version':self.version} -except: # from source import toml with open("./pyproject.toml") as filed: metadata = toml.load(filed)['project'] + VERSIONSTR = metadata['version'] + HOMEPAGE = metadata['urls']['homepage'] +except: + # package distributrion + from importlib import metadata + VERSIONSTR = metadata.version('maloja') + urls = metadata.metadata('maloja').get_all('Project-URL') + urls = [e.split(', ') for e in urls] + HOMEPAGE = [e[1] for e in urls if e[0] == 'homepage'][0] -versionstr = metadata['version'] -version = versionstr.split('.') -urls = { - "repo":"https://github.com/krateng/maloja" -} -user_agent = f"Maloja/{versionstr} ( {urls['repo']} )" + +VERSION = VERSIONSTR.split('.') + + +USER_AGENT = f"Maloja/{VERSIONSTR} ( {HOMEPAGE} )" diff --git a/maloja/apis/native_v1.py b/maloja/apis/native_v1.py index 31acac2..d3c5c0e 100644 --- a/maloja/apis/native_v1.py +++ b/maloja/apis/native_v1.py @@ -1,6 +1,6 @@ from ..database import * from ..globalconf import malojaconfig, apikeystore -from ..__pkginfo__ import version +from ..__pkginfo__ import VERSION, VERSIONSTR from ..malojauri import uri_to_internal from .. import utilities @@ -42,8 +42,8 @@ def server_info(): return { "name":malojaconfig["NAME"], - "version":version, - "versionstring":".".join(str(n) for n in version), + "version":VERSION, + "versionstring":VERSIONSTR, "db_status":dbstatus } diff --git a/maloja/globalconf.py b/maloja/globalconf.py index a4cf65b..a032deb 100644 --- a/maloja/globalconf.py +++ b/maloja/globalconf.py @@ -3,7 +3,7 @@ from doreah.configuration import Configuration from doreah.configuration import types as tp from doreah.keystore import KeyStore -from .__pkginfo__ import versionstr +from .__pkginfo__ import VERSIONSTR @@ -275,7 +275,7 @@ data_dir = { ### write down the last ran version with open(pthj(dir_settings['state'],".lastmalojaversion"),"w") as filed: - filed.write(versionstr) + filed.write(VERSIONSTR) filed.write("\n") diff --git a/maloja/proccontrol/control.py b/maloja/proccontrol/control.py index c27cd3a..1df22bb 100644 --- a/maloja/proccontrol/control.py +++ b/maloja/proccontrol/control.py @@ -15,8 +15,8 @@ from .. import globalconf def print_header_info(): print() print("#####") - print("Maloja v" + info.versionstr) - print(info.urls['repo']) + print("Maloja v" + info.VERSIONSTR) + print(info.HOMEPAGE) print("#####") print() @@ -120,7 +120,7 @@ def main(*args,**kwargs): } if "version" in kwargs: - print(info.versionstr) + print(info.VERSIONSTR) elif len(args) > 0: action = args[0] diff --git a/maloja/thirdparty/musicbrainz.py b/maloja/thirdparty/musicbrainz.py index ee86a49..c100d3f 100644 --- a/maloja/thirdparty/musicbrainz.py +++ b/maloja/thirdparty/musicbrainz.py @@ -3,7 +3,7 @@ import urllib.parse, urllib.request import json import time import threading -from ..__pkginfo__ import user_agent +from ..__pkginfo__ import USER_AGENT class MusicBrainz(MetadataInterface): name = "MusicBrainz" @@ -11,7 +11,7 @@ class MusicBrainz(MetadataInterface): # musicbrainz is rate-limited lock = threading.Lock() - useragent = user_agent + useragent = USER_AGENT settings = { } diff --git a/maloja/utilities/maintenance.py b/maloja/utilities/maintenance.py index 8181b62..bd6ec3c 100644 --- a/maloja/utilities/maintenance.py +++ b/maloja/utilities/maintenance.py @@ -1,4 +1,4 @@ -from ..__pkginfo__ import version +from ..__pkginfo__ import VERSIONSTR from ..malojatime import ranges, thisweek, thisyear from ..globalconf import malojaconfig @@ -100,7 +100,7 @@ def send_stats(): "data":json.dumps({ "name":malojaconfig["NAME"], "url":malojaconfig["PUBLIC_URL"], - "version":".".join(str(d) for d in version), + "version":VERSIONSTR, "artists":len(ARTISTS), "tracks":len(TRACKS), "scrobbles":len(SCROBBLES) diff --git a/pyproject.toml b/pyproject.toml index a1e2f50..715a8c9 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -9,7 +9,7 @@ authors = [ { name="Johannes Krattenmacher", email="maloja@dev.krateng.ch" } ] urls.repository = "https://github.com/krateng/maloja" urls.documentation = "https://github.com/krateng/maloja" -urls.homepage = "https://maloja.krateng.ch" +urls.homepage = "https://github.com/krateng/maloja" keywords = ["scrobbling", "music", "selfhosted", "database", "charts", "statistics"] classifiers = [