Skip to content

Commit 9b2c737

Browse files
author
Thomas Desveaux
authored
Merge pull request #106 from dontnod/replace-deprecated-pkg_resources
Replace deprecated pkg resources
2 parents 7f48d95 + cc2fd5c commit 9b2c737

File tree

8 files changed

+83
-24
lines changed

8 files changed

+83
-24
lines changed

.github/workflows/pylint.yml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,16 @@ jobs:
1515
runs-on: ubuntu-latest
1616
strategy:
1717
matrix:
18-
python-version: ["3.7", "3.8", "3.9", "3.10"]
18+
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]
1919
steps:
20-
- uses: actions/checkout@v3
20+
- uses: actions/checkout@v4
2121
- name: Set up Python ${{ matrix.python-version }}
22-
uses: actions/setup-python@v3
22+
uses: actions/setup-python@v5
2323
with:
2424
python-version: ${{ matrix.python-version }}
25+
cache: 'pip'
26+
cache-dependency-path: |
27+
pyproject.toml
2528
- name: Install dependencies
2629
run: |
2730
python -m pip install --upgrade pip

.github/workflows/ruff.yml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,19 @@
11
name: Ruff
2-
on: [ push, pull_request ]
2+
on:
3+
push:
4+
branches:
5+
- master
6+
- dev
7+
pull_request:
8+
branches:
9+
- master
10+
- dev
11+
312
jobs:
413
ruff:
514
runs-on: ubuntu-latest
615
steps:
7-
- uses: actions/checkout@v3
16+
- uses: actions/checkout@v4
817
- uses: chartboost/ruff-action@v1
918
with:
1019
src: "./nimp"

.github/workflows/smoke-test.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: Smoke test
2+
on:
3+
push:
4+
branches:
5+
- master
6+
- dev
7+
pull_request:
8+
branches:
9+
- master
10+
- dev
11+
12+
jobs:
13+
smoke:
14+
name: Smoke test / python ${{ matrix.python-version }}
15+
runs-on: ubuntu-latest
16+
17+
strategy:
18+
fail-fast: false
19+
matrix:
20+
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]
21+
steps:
22+
- uses: actions/checkout@v4
23+
- uses: actions/setup-python@v5
24+
with:
25+
python-version: "${{ matrix.python-version }}"
26+
cache: 'pip'
27+
cache-dependency-path: |
28+
pyproject.toml
29+
- name: Install dependencies
30+
run: |
31+
python -m pip install .
32+
- run: nimp check status

nimp/command.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,16 @@
2323
'''Abstract class for commands'''
2424

2525
import abc
26+
import argparse
2627
import logging
2728
import os
28-
import pkg_resources
2929
import re
3030
import sys
31-
import argparse
3231

3332
import nimp.base_commands
3433
import nimp.command
35-
3634
from nimp.utils.python import get_class_instances
35+
from nimp.utils.python import iter_plugins_entry_points
3736

3837

3938
class Command(metaclass=abc.ABCMeta):
@@ -142,12 +141,12 @@ def discover(env):
142141
pass
143142

144143
# Import commands from plugins
145-
for entry_point in pkg_resources.iter_entry_points('nimp.plugins'):
144+
for entry_point in iter_plugins_entry_points():
146145
try:
147146
module = entry_point.load()
148147
get_class_instances(module, nimp.command.Command, all_commands)
149148
except Exception as exception:
150-
logging.debug("Failed to get platforms from plugin %s", entry_point.module_name, exc_info=exception)
149+
logging.debug("Failed to get platforms from plugin %s", entry_point.module, exc_info=exception)
151150

152151
env.command_list = sorted(
153152
[it for it in all_commands.values() if not it.__class__.__name__.startswith('_')],

nimp/environment.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,21 +24,20 @@
2424
values and command line parameters set for this nimp execution'''
2525

2626
import argparse
27-
import re
2827
import logging
2928
import os
30-
import pkg_resources
29+
import re
3130
import sys
3231
import time
3332

3433
import nimp.command
35-
from nimp.exceptions import NimpCommandFailed
3634
import nimp.summary
3735
import nimp.sys.platform
3836
import nimp.system
3937
import nimp.unreal
4038
import nimp.utils.profiling
41-
39+
from nimp.exceptions import NimpCommandFailed
40+
from nimp.utils.python import iter_plugins_entry_points
4241

4342
_LOG_FORMATS = { # pylint: disable = invalid-name
4443
'standard': '%(asctime)s [%(levelname)s] %(message)s'
@@ -394,8 +393,8 @@ def execute_hook(hook_name, *args):
394393
# Always look for project level hook first
395394
hook_module = nimp.system.try_import('hooks.' + hook_name)
396395
if hook_module is None: # If none found, try plugins level
397-
for entry in pkg_resources.iter_entry_points('nimp.plugins'):
398-
hook_module = nimp.system.try_import(entry.module_name + '.hooks.' + hook_name)
396+
for entry in iter_plugins_entry_points():
397+
hook_module = nimp.system.try_import(entry.module + '.hooks.' + hook_name)
399398
if hook_module:
400399
break
401400
if hook_module is None:

nimp/sys/platform.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,10 @@
33
import abc
44
import logging
55
import platform
6-
import pkg_resources
76

87
import nimp.base_platforms
9-
108
from nimp.utils.python import get_class_instances
9+
from nimp.utils.python import iter_plugins_entry_points
1110

1211
_all_platforms = {}
1312
_all_aliases = {}
@@ -74,12 +73,12 @@ def discover(env):
7473
discovered_platforms = {}
7574
get_class_instances(nimp.base_platforms, Platform, discovered_platforms, instance_args=[env])
7675

77-
for module_entrypoint in pkg_resources.iter_entry_points('nimp.plugins'):
76+
for module_entrypoint in iter_plugins_entry_points():
7877
try:
7978
module = module_entrypoint.load()
8079
get_class_instances(module, Platform, discovered_platforms, instance_args=[env])
8180
except Exception as exception:
82-
logging.debug("Failed to get platforms from plugin %s", module_entrypoint.module_name, exc_info=exception)
81+
logging.debug("Failed to get platforms from plugin %s", module_entrypoint.module, exc_info=exception)
8382

8483
for platform_instance in discovered_platforms.values():
8584
# Set env.is_win32, env.is_linux, etc. to False by default

nimp/system.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,21 +23,21 @@
2323
'''System utilities (paths, processes)'''
2424

2525
import fnmatch
26+
import importlib
2627
import json
2728
import logging
2829
import os
2930
import re
3031
import shutil
3132
import stat
3233
import time
33-
import importlib
34-
import pkg_resources
3534

3635
import glob2
3736

3837
import nimp.environment
3938
import nimp.sys.platform
4039
import nimp.sys.process
40+
from nimp.utils.python import iter_plugins_entry_points
4141

4242

4343
def try_import(module_name):
@@ -329,9 +329,9 @@ def load_set(self, set_name):
329329
try:
330330
set_module = importlib.import_module('filesets.' + set_module_name)
331331
except ModuleNotFoundError:
332-
for entry in pkg_resources.iter_entry_points('nimp.plugins'):
332+
for entry in iter_plugins_entry_points():
333333
try:
334-
set_module = importlib.import_module(entry.module_name + '.filesets.' + set_module_name)
334+
set_module = importlib.import_module(entry.module + '.filesets.' + set_module_name)
335335
break
336336
except ModuleNotFoundError:
337337
pass

nimp/utils/python.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
11
'''Helper functions for module handling'''
22

3+
from __future__ import annotations
4+
35
import inspect
46
import logging
7+
from importlib.metadata import entry_points
8+
from typing import TYPE_CHECKING
9+
10+
if TYPE_CHECKING:
11+
from importlib.metadata import EntryPoint
12+
from typing import Generator
513

614

715
def get_class_instances(module, instance_type, result, instance_args=[], instance_kwargs={}):
@@ -32,3 +40,13 @@ def get_class_instances(module, instance_type, result, instance_args=[], instanc
3240
result[attribute_value.__name__] = attribute_value(*instance_args, **instance_kwargs)
3341
except Exception as ex:
3442
logging.warning('Error creating %s %s: %s', instance_type.__name__, attribute_value.__name__, ex)
43+
44+
45+
def iter_plugins_entry_points() -> Generator[EntryPoint, None, None]:
46+
eps = entry_points()
47+
if hasattr(eps, "select"):
48+
yield from eps.select(group="nimp.plugins")
49+
elif hasattr(eps, "get"):
50+
yield from eps.get("nimp.plugins", [])
51+
else:
52+
raise NotImplementedError(f"unexpected value for importlib.metadata.entry_points ({type(eps)})")

0 commit comments

Comments
 (0)