diff --git a/MANIFEST.in b/MANIFEST.in index 1b7e7a88..6086421e 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -11,6 +11,7 @@ include .project include .pydevproject include .yamllint include _release_date +include linkcheck/data/linkcheckerrc recursive-include cgi-bin \ *.css \ @@ -23,8 +24,7 @@ recursive-include cgi-bin \ recursive-include config \ *.sql \ linkchecker-completion \ - linkchecker.apache2.conf \ - linkcheckerrc + linkchecker.apache2.conf recursive-include doc \ *.1 \ *.5 \ diff --git a/linkcheck/__init__.py b/linkcheck/__init__.py index c3543f57..a13f0a49 100644 --- a/linkcheck/__init__.py +++ b/linkcheck/__init__.py @@ -42,6 +42,8 @@ from .logconf import ( ) import _LinkChecker_configdata as configdata +PACKAGE_NAME = __package__ + def module_path(): """Return absolute directory of system executable.""" diff --git a/linkcheck/configuration/__init__.py b/linkcheck/configuration/__init__.py index 42bd2ba1..43b8539f 100644 --- a/linkcheck/configuration/__init__.py +++ b/linkcheck/configuration/__init__.py @@ -17,13 +17,14 @@ Store metadata and options. """ +import importlib.resources import os import re import urllib.parse import shutil import socket import _LinkChecker_configdata as configdata -from .. import log, LOG_CHECK, get_install_data, fileutil +from .. import log, LOG_CHECK, PACKAGE_NAME, fileutil from . import confparse from xdg.BaseDirectory import xdg_config_home, xdg_data_home @@ -89,11 +90,6 @@ def get_modules_info(): return "Modules: %s" % (", ".join(module_infos)) -def get_share_dir(): - """Return absolute path of LinkChecker example configuration.""" - return os.path.join(get_install_data(), "share", "linkchecker") - - def get_system_cert_file(): """Try to find a system-wide SSL certificate file. @return: the filename to the cert file @@ -368,8 +364,6 @@ def get_user_config(): @return configuration filename @rtype string """ - # initial config (with all options explained) - initialconf = normpath(os.path.join(get_share_dir(), "linkcheckerrc")) # per user config settings homedotfile = normpath("~/.linkchecker/linkcheckerrc") userconf = ( @@ -377,18 +371,21 @@ def get_user_config(): if os.path.isfile(homedotfile) else os.path.join(xdg_config_home, "linkchecker", "linkcheckerrc") ) - if os.path.isfile(initialconf) and not os.path.exists(userconf): - # copy the initial configuration to the user configuration - try: - make_userdir(userconf) - shutil.copy(initialconf, userconf) - except Exception as errmsg: - msg = _( - "could not copy initial configuration file %(src)r" - " to %(dst)r: %(errmsg)r" - ) - args = dict(src=initialconf, dst=userconf, errmsg=errmsg) - log.warn(LOG_CHECK, msg % args) + if not os.path.exists(userconf): + # initial config (with all options explained) + with importlib.resources.path( + f"{PACKAGE_NAME}.data", "linkcheckerrc") as initialconf: + # copy the initial configuration to the user configuration + try: + make_userdir(userconf) + shutil.copy(initialconf, userconf) + except Exception as errmsg: + msg = _( + "could not copy initial configuration file %(src)r" + " to %(dst)r: %(errmsg)r" + ) + args = dict(src=initialconf, dst=userconf, errmsg=errmsg) + log.warn(LOG_CHECK, msg % args) return userconf diff --git a/linkcheck/data/__init__.py b/linkcheck/data/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/config/linkcheckerrc b/linkcheck/data/linkcheckerrc similarity index 100% rename from config/linkcheckerrc rename to linkcheck/data/linkcheckerrc diff --git a/setup.py b/setup.py index 22409a49..bcb9c2d0 100755 --- a/setup.py +++ b/setup.py @@ -294,7 +294,6 @@ myname = "LinkChecker Authors" myemail = "" data_files = [ - ("share/linkchecker", ["config/linkcheckerrc"]), ( "share/linkchecker/examples", [ @@ -358,6 +357,7 @@ setup( ] }, data_files=data_files, + include_package_data=True, classifiers=[ "Topic :: Internet :: WWW/HTTP :: Site Management :: Link Checking", "Development Status :: 5 - Production/Stable",