Replace pkg_resources by importlib
pkg_resources is deprecated in favor of importlib.resources, importlib.metadata.
This commit is contained in:
1 parent
17ed7b32e6
commit
2d599f67cf
7 files changed
+42
-39
No files matched your search
+17
-6
@@ -227,14 +227,25 @@ if not isinstance(CURRENT_DIR, str):
|
||||
|
||||
PIXMAPS_DIR = os.path.join(CURRENT_DIR, 'data', 'pixmaps', 'tryton')
|
||||
if not os.path.isdir(PIXMAPS_DIR):
|
||||
# do not import when frozen
|
||||
import pkg_resources
|
||||
PIXMAPS_DIR = pkg_resources.resource_filename(
|
||||
'tryton', 'data/pixmaps/tryton')
|
||||
try:
|
||||
import importlib.resources
|
||||
ref = importlib.resources.files('tryton') / 'data/pixmaps/tryton'
|
||||
with importlib.resources.as_file(ref) as path:
|
||||
PIXMAPS_DIR = path
|
||||
except ImportError:
|
||||
import pkg_resources
|
||||
PIXMAPS_DIR = pkg_resources.resource_filename(
|
||||
'tryton', 'data/pixmaps/tryton')
|
||||
SOUNDS_DIR = os.path.join(CURRENT_DIR, 'data', 'sounds')
|
||||
if not os.path.isdir(SOUNDS_DIR):
|
||||
import pkg_resources
|
||||
SOUNDS_DIR = pkg_resources.resource_filename('tryton', 'data/sounds')
|
||||
try:
|
||||
import importlib.resources
|
||||
ref = importlib.resources.files('tryton') / 'data/sounds'
|
||||
with importlib.resources.as_file(ref) as path:
|
||||
SOUNDS_DIR = path
|
||||
except ImportError:
|
||||
import pkg_resources
|
||||
SOUNDS_DIR = pkg_resources.resource_filename('tryton', 'data/sounds')
|
||||
|
||||
TRYTON_ICON = GdkPixbuf.Pixbuf.new_from_file(
|
||||
os.path.join(PIXMAPS_DIR, 'tryton-icon.png'))
|
||||
@@ -154,10 +154,15 @@ def setlang(lang=None, locale_dict=None):
|
||||
"Set language"
|
||||
locale_dir = os.path.join(CURRENT_DIR, 'data/locale')
|
||||
if not os.path.isdir(locale_dir):
|
||||
# do not import when frozen
|
||||
import pkg_resources
|
||||
locale_dir = pkg_resources.resource_filename(
|
||||
'tryton', 'data/locale')
|
||||
try:
|
||||
import importlib.resources
|
||||
ref = importlib.files('tryton') / 'data/locale'
|
||||
with importlib.resources.as_file(ref) as path:
|
||||
locale_dir = path
|
||||
except ImportError:
|
||||
import pkg_resources
|
||||
locale_dir = pkg_resources.resource_filename(
|
||||
'tryton', 'data/locale')
|
||||
if lang:
|
||||
encoding = locale.getdefaultlocale()[1]
|
||||
if not encoding:
|
||||
|
||||
@@ -143,6 +143,7 @@ setup(name=name,
|
||||
'werkzeug >= 0.12',
|
||||
'passlib >= 1.7.0',
|
||||
'pytz;python_version<"3.9"',
|
||||
'backports.entry-points-selectable;python_version<"3.10"',
|
||||
],
|
||||
extras_require={
|
||||
'test': tests_require,
|
||||
|
||||
@@ -4,9 +4,9 @@ import importlib
|
||||
import urllib.parse
|
||||
|
||||
try:
|
||||
import pkg_resources
|
||||
from backports.entry_points_selectable import entry_points
|
||||
except ImportError:
|
||||
pkg_resources = None
|
||||
from importlib.metadata import entry_points
|
||||
|
||||
from trytond.config import config
|
||||
|
||||
@@ -21,9 +21,7 @@ _modname = 'trytond.backend.%s' % name
|
||||
try:
|
||||
_module = importlib.import_module(_modname)
|
||||
except ImportError:
|
||||
if not pkg_resources:
|
||||
raise
|
||||
for ep in pkg_resources.iter_entry_points('trytond.backend', name):
|
||||
for ep in entry_points().select(group='trytond.backend', name=name):
|
||||
try:
|
||||
_module = ep.load()
|
||||
break
|
||||
|
||||
@@ -9,9 +9,9 @@ from collections import defaultdict
|
||||
from glob import iglob
|
||||
|
||||
try:
|
||||
import pkg_resources
|
||||
from backports.entry_points_selectable import entry_points
|
||||
except ImportError:
|
||||
pkg_resources = None
|
||||
from importlib.metadata import entry_points
|
||||
|
||||
from sql import Table
|
||||
from sql.functions import CurrentTimestamp
|
||||
@@ -37,12 +37,8 @@ EGG_MODULES = {}
|
||||
|
||||
def update_egg_modules():
|
||||
global EGG_MODULES
|
||||
try:
|
||||
import pkg_resources
|
||||
for ep in pkg_resources.iter_entry_points('trytond.modules'):
|
||||
EGG_MODULES[ep.name] = ep
|
||||
except ImportError:
|
||||
pass
|
||||
for ep in entry_points().select(group='trytond.modules'):
|
||||
EGG_MODULES[ep.name] = ep
|
||||
|
||||
|
||||
update_egg_modules()
|
||||
@@ -301,9 +297,8 @@ def get_modules(with_test=False):
|
||||
continue
|
||||
if os.path.isdir(OPJ(MODULES_PATH, file)):
|
||||
modules.add(file)
|
||||
if pkg_resources:
|
||||
for ep in pkg_resources.iter_entry_points('trytond.modules'):
|
||||
modules.add(ep.name)
|
||||
for ep in entry_points().select(group='trytond.modules'):
|
||||
modules.add(ep.name)
|
||||
if with_test:
|
||||
modules.add('tests')
|
||||
return modules
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
# this repository contains the full copyright notices and license terms.
|
||||
|
||||
try:
|
||||
import pkg_resources
|
||||
from backports.entry_points_selectable import entry_points
|
||||
except ImportError:
|
||||
pkg_resources = None
|
||||
from importlib.metadata import entry_points
|
||||
|
||||
|
||||
def register():
|
||||
@@ -60,9 +60,7 @@ def register():
|
||||
wizard.register('tests')
|
||||
workflow.register('tests')
|
||||
|
||||
if pkg_resources is not None:
|
||||
entry_points = pkg_resources.iter_entry_points('trytond.tests')
|
||||
for test_ep in entry_points:
|
||||
test_module = test_ep.load()
|
||||
if hasattr(test_module, 'register'):
|
||||
test_module.register('tests')
|
||||
for test_ep in entry_points().select(group='trytond.tests'):
|
||||
test_module = test_ep.load()
|
||||
if hasattr(test_module, 'register'):
|
||||
test_module.register('tests')
|
||||
@@ -20,11 +20,6 @@ from fnmatch import fnmatchcase
|
||||
from functools import reduce, wraps
|
||||
from itertools import chain
|
||||
|
||||
try:
|
||||
import pkg_resources
|
||||
except ImportError:
|
||||
pkg_resources = None
|
||||
|
||||
from lxml import etree
|
||||
from sql import Table
|
||||
from werkzeug.test import Client
|
||||
|
||||
Reference in new issue
Block a user