From 1d10fffde4d3f4fc0235abba8afc4904a91c4ebd Mon Sep 17 00:00:00 2001 From: Chris Mayo Date: Thu, 30 Dec 2021 19:27:04 +0000 Subject: [PATCH] Use package metadata --- .github/workflows/build.yml | 2 +- .github/workflows/publish-pages.yml | 2 +- linkcheck/__init__.py | 6 ++++-- linkcheck/configuration/__init__.py | 18 +++++++++++++----- setup.py | 24 +----------------------- 5 files changed, 20 insertions(+), 32 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index d96551c3..c89c584b 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -106,7 +106,7 @@ jobs: - name: Build run: | - python3 setup.py build + python3 setup.py build egg_info make -C doc code make -C doc html make -C doc locale diff --git a/.github/workflows/publish-pages.yml b/.github/workflows/publish-pages.yml index 43a5472d..5aa6576c 100644 --- a/.github/workflows/publish-pages.yml +++ b/.github/workflows/publish-pages.yml @@ -32,7 +32,7 @@ jobs: - name: Build run: | - python3 setup.py build + python3 setup.py build egg_info make -C doc code make -C doc html diff --git a/linkcheck/__init__.py b/linkcheck/__init__.py index a13f0a49..e71503e7 100644 --- a/linkcheck/__init__.py +++ b/linkcheck/__init__.py @@ -42,6 +42,7 @@ from .logconf import ( ) import _LinkChecker_configdata as configdata +COMMAND_NAME = "linkchecker" PACKAGE_NAME = __package__ @@ -107,8 +108,9 @@ def init_i18n(loc=None): if 'LOCPATH' in os.environ: locdir = os.environ['LOCPATH'] else: - locdir = os.path.join(get_install_data(), 'share', 'locale') - i18n.init(configdata.name.lower(), locdir, loc=loc) + # Need Python 3.9 for importlib.resources.files + locdir = os.path.join(__path__[0], 'data', 'locale') + i18n.init(COMMAND_NAME, locdir, loc=loc) # install translated log level names import logging diff --git a/linkcheck/configuration/__init__.py b/linkcheck/configuration/__init__.py index 43b8539f..fc9d4387 100644 --- a/linkcheck/configuration/__init__.py +++ b/linkcheck/configuration/__init__.py @@ -23,22 +23,30 @@ import re import urllib.parse import shutil import socket + +try: + from importlib.metadata import metadata +except ImportError: + # Python 3.7 + from importlib_metadata import metadata + import _LinkChecker_configdata as configdata -from .. import log, LOG_CHECK, PACKAGE_NAME, fileutil +from .. import log, LOG_CHECK, COMMAND_NAME, PACKAGE_NAME, fileutil from . import confparse from xdg.BaseDirectory import xdg_config_home, xdg_data_home -Version = configdata.version +linkchecker_metadata = metadata(COMMAND_NAME) +Version = linkchecker_metadata["Version"] ReleaseDate = configdata.release_date -AppName = configdata.name +AppName = linkchecker_metadata["Name"] App = AppName + " " + Version -Author = configdata.author +Author = linkchecker_metadata["Author"] HtmlAuthor = Author.replace(' ', ' ') Copyright = "Copyright (C) 2000-2016 Bastian Kleineidam, 2010-2022 " + Author HtmlCopyright = ("Copyright © 2000-2016 Bastian Kleineidam, 2010-2022 " + HtmlAuthor) HtmlAppInfo = App + ", " + HtmlCopyright -Url = configdata.url +Url = linkchecker_metadata["Home-page"] SupportUrl = "https://github.com/linkchecker/linkchecker/issues" UserAgent = "Mozilla/5.0 (compatible; %s/%s; +%s)" % (AppName, Version, Url) Freeware = ( diff --git a/setup.py b/setup.py index fe11f6fc..de0fee6d 100755 --- a/setup.py +++ b/setup.py @@ -141,7 +141,7 @@ class MyInstallLib(install_lib): cmd_obj = self.distribution.get_command_obj("install") cmd_obj.ensure_finalized() # we have to write a configuration file because we need the - # directory (and other stuff like author, url, ...) + # directory # all paths are made absolute by cnormpath() data = [] for d in ["purelib", "platlib", "lib", "headers", "scripts", "data"]: @@ -230,28 +230,6 @@ class MyDistribution(Distribution): directory = os.getcwd() filename = self.get_conf_filename(directory) # add metadata - metanames = ( - "name", - "version", - "author", - "author_email", - "maintainer", - "maintainer_email", - "url", - "license", - "description", - "long_description", - "keywords", - "platforms", - "fullname", - "contact", - "contact_email", - ) - for name in metanames: - method = "get_" + name - val = getattr(self.metadata, method)() - cmd = "%s = %r" % (name, val) - data.append(cmd) data.append('release_date = "%s"' % get_release_date()) # write the config file util.execute(