Changeset - 3dabbbc9da89
[Not reviewed]
stable
0 4 0
Mads Kiilerich (mads) - 5 months ago 2025-10-05 13:32:36
mads@kiilerich.com
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
4 files changed with 10 insertions and 14 deletions:
0 comments (0 inline, 0 general)
kallithea/bin/kallithea_cli_extensions.py
Show inline comments
 
@@ -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 '
kallithea/model/db.py
Show inline comments
 
@@ -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(),
kallithea/model/scm.py
Show inline comments
 
@@ -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)
scripts/deps.py
Show inline comments
 
@@ -63,7 +63,6 @@ paginate_sqlalchemy
 
pam
 
paste
 
pathlib
 
pkg_resources
 
platform
 
posixpath
 
pprint
0 comments (0 inline, 0 general)