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
 
@@ -16,16 +16,16 @@ This file was forked by the Kallithea pr
 
Original author and date, and relevant copyright and licensing information is below:
 
:created_on: Mar 6, 2012
 
:author: marcink
 
: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
 

	
 

	
 
@cli_base.register_command(needs_config_file=True)
 
@@ -34,15 +34,14 @@ def extensions_create(config):
 

	
 
    Create a template `extensions.py` file next to the ini file. Local
 
    customizations in that file will survive upgrades. The file contains
 
    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 '
 
               'to overwrite it ? [y/n] ') % ext_file
 
        if not ask_ok(msg):
 
            click.echo('Nothing done, exiting...')
kallithea/model/db.py
Show inline comments
 
@@ -27,14 +27,16 @@ Original author and date, and relevant c
 

	
 
import base64
 
import collections
 
import datetime
 
import functools
 
import hashlib
 
import importlib.metadata
 
import logging
 
import os
 
import platform
 
import time
 
import traceback
 

	
 
import ipaddr
 
import sqlalchemy
 
import urlobject
 
@@ -303,17 +305,14 @@ class Setting(meta.Base, BaseDbModel):
 
            fd.update({key: row.app_settings_value})
 

	
 
        return fd
 

	
 
    @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(),
 
            'platform': platform.platform(),
 
            'kallithea_version': kallithea.__version__,
 
            'git_version': str(check_git_version()),
kallithea/model/scm.py
Show inline comments
 
@@ -22,21 +22,21 @@ Original author and date, and relevant c
 
:created_on: Apr 9, 2010
 
:author: marcink
 
:copyright: (c) 2013 RhodeCode GmbH, and others.
 
:license: GPLv3, see LICENSE.md for more details.
 
"""
 

	
 
import importlib.resources
 
import logging
 
import os
 
import posixpath
 
import re
 
import sys
 
import tempfile
 
import traceback
 

	
 
import pkg_resources
 
from tg.i18n import ugettext as _
 

	
 
import kallithea
 
from kallithea.lib import hooks
 
from kallithea.lib.auth import HasPermissionAny, HasRepoGroupPermissionLevel, HasRepoPermissionLevel, HasUserGroupPermissionLevel
 
from kallithea.lib.exceptions import IMCCommitError, NonRelativePathError
 
@@ -667,15 +667,14 @@ class ScmModel(object):
 
        if not repo.bare:
 
            hooks_path = os.path.join(repo.path, '.git', 'hooks')
 
        if not os.path.isdir(hooks_path):
 
            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)
 
            other_hook = False
 
            log.debug('Installing git hook %s in repo %s', h_type, repo.path)
 
            if os.path.islink(hook_file):
scripts/deps.py
Show inline comments
 
@@ -60,13 +60,12 @@ operator
 
os
 
paginate
 
paginate_sqlalchemy
 
pam
 
paste
 
pathlib
 
pkg_resources
 
platform
 
posixpath
 
pprint
 
pwd
 
pyflakes
 
pytest
0 comments (0 inline, 0 general)