# HG changeset patch # User Mads Kiilerich # Date 2025-10-05 13:32:36 # Node ID 3dabbbc9da8976dd60a836302375a82dfb79b03d # Parent 90e1a287b7a2a09219d7c948b4ccefefa444058d setup: use importlib instead of pkg_resources Address warnings like: UserWarning: pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html. The pkg_resources package is slated for removal as early as 2025-11-30. Refrain from using this package or pin to Setuptools<81. import pkg_resources diff --git a/kallithea/bin/kallithea_cli_extensions.py b/kallithea/bin/kallithea_cli_extensions.py --- a/kallithea/bin/kallithea_cli_extensions.py +++ b/kallithea/bin/kallithea_cli_extensions.py @@ -19,10 +19,10 @@ Original author and date, and relevant c :copyright: (c) 2013 RhodeCode GmbH, and others. :license: GPLv3, see LICENSE.md for more details. """ +import importlib.resources import os import click -import pkg_resources import kallithea.bin.kallithea_cli_base as cli_base from kallithea.lib.utils2 import ask_ok @@ -37,9 +37,8 @@ def extensions_create(config): instructions on how it can be customized. """ here = config['here'] - content = pkg_resources.resource_string( - 'kallithea', os.path.join('templates', 'py', 'extensions.py') - ) + content = importlib.resources.files('kallithea').joinpath( + 'templates', 'py', 'extensions.py').read_bytes() ext_file = os.path.join(here, 'extensions.py') if os.path.exists(ext_file): msg = ('Extension file %s already exists, do you want ' diff --git a/kallithea/model/db.py b/kallithea/model/db.py --- a/kallithea/model/db.py +++ b/kallithea/model/db.py @@ -30,8 +30,10 @@ import collections import datetime import functools import hashlib +import importlib.metadata import logging import os +import platform import time import traceback @@ -306,11 +308,8 @@ class Setting(meta.Base, BaseDbModel): @classmethod def get_server_info(cls): - import platform - - import pkg_resources - - mods = [(p.project_name, p.version) for p in pkg_resources.working_set] + # Python 3.9 PathDistribution doesn't have .name + mods = set((p.metadata['Name'], p.version) for p in importlib.metadata.distributions()) info = { 'modules': sorted(mods, key=lambda k: k[0].lower()), 'py_version': platform.python_version(), diff --git a/kallithea/model/scm.py b/kallithea/model/scm.py --- a/kallithea/model/scm.py +++ b/kallithea/model/scm.py @@ -25,6 +25,7 @@ Original author and date, and relevant c :license: GPLv3, see LICENSE.md for more details. """ +import importlib.resources import logging import os import posixpath @@ -33,7 +34,6 @@ import sys import tempfile import traceback -import pkg_resources from tg.i18n import ugettext as _ import kallithea @@ -670,9 +670,8 @@ class ScmModel(object): os.makedirs(hooks_path) tmpl_post = b"#!%s\n" % safe_bytes(self._get_git_hook_interpreter()) - tmpl_post += pkg_resources.resource_string( - 'kallithea', os.path.join('templates', 'py', 'git_post_receive_hook.py') - ) + tmpl_post += importlib.resources.files('kallithea').joinpath( + 'templates', 'py', 'git_post_receive_hook.py').read_bytes() for h_type, tmpl in [('pre-receive', None), ('post-receive', tmpl_post)]: hook_file = os.path.join(hooks_path, h_type) diff --git a/scripts/deps.py b/scripts/deps.py --- a/scripts/deps.py +++ b/scripts/deps.py @@ -63,7 +63,6 @@ paginate_sqlalchemy pam paste pathlib -pkg_resources platform posixpath pprint