Skip to content

Commit 052a442

Browse files
committed
change pkg_resources to importlib_metadata
1 parent db5ff4b commit 052a442

File tree

2 files changed

+18
-16
lines changed

2 files changed

+18
-16
lines changed

mlblocks/discovery.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
import re
1515
import sys
1616

17-
import pkg_resources
17+
import importlib.metadata
1818

1919
LOGGER = logging.getLogger(__name__)
2020

@@ -131,7 +131,7 @@ def _load_entry_points(entry_point_name, entry_point_group='mlblocks'):
131131
The list of folders.
132132
"""
133133
lookup_paths = list()
134-
entry_points = pkg_resources.iter_entry_points(entry_point_group)
134+
entry_points = importlib.metadata.entry_points(group=entry_point_group)
135135
for entry_point in entry_points:
136136
if entry_point.name == entry_point_name:
137137
paths = entry_point.load()

tests/test_discovery.py

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from unittest.mock import Mock, call, patch
88

99
import pytest
10-
from pkg_resources import Distribution, EntryPoint
10+
from importlib.metadata import Distribution, EntryPoint
1111

1212
from mlblocks import discovery
1313

@@ -59,7 +59,7 @@ def test_add_pipelines_path():
5959

6060

6161
@patch('mlblocks.discovery._PRIMITIVES_PATHS', new=['a', 'b'])
62-
@patch('mlblocks.discovery.pkg_resources.iter_entry_points')
62+
@patch('mlblocks.discovery.importlib.metadata.entry_points')
6363
def test__load_entry_points_no_entry_points(iep_mock):
6464
# setup
6565
iep_mock.return_value == []
@@ -70,26 +70,28 @@ def test__load_entry_points_no_entry_points(iep_mock):
7070
# assert
7171
assert paths == []
7272
expected_calls = [
73-
call('mlprimitives'),
73+
call(group='mlprimitives'),
7474
]
7575
assert iep_mock.call_args_list == expected_calls
7676

7777

78-
@patch('mlblocks.discovery.pkg_resources.iter_entry_points')
78+
@patch('mlblocks.discovery.importlib.metadata.entry_points')
7979
def test__load_entry_points_entry_points(iep_mock):
8080
# setup
81-
something_else_ep = EntryPoint('something_else', 'mlblocks.__version__')
81+
something_else_ep = EntryPoint(
82+
name='something_else',
83+
value='mlblocks.__version__',
84+
group='mlblocks'
85+
)
8286
primitives_ep = EntryPoint(
83-
'primitives',
84-
'tests.test_discovery',
85-
attrs=['FAKE_PRIMITIVES_PATH'],
86-
dist=Distribution()
87+
name='primitives',
88+
value='tests.test_discovery:FAKE_PRIMITIVES_PATH',
89+
group='mlblocks'
8790
)
8891
another_primitives_ep = EntryPoint(
89-
'primitives',
90-
'tests.test_discovery',
91-
attrs=['FAKE_PRIMITIVES_PATHS'],
92-
dist=Distribution()
92+
name='primitives',
93+
value='tests.test_discovery:FAKE_PRIMITIVES_PATHS',
94+
group='mlblocks'
9395
)
9496
iep_mock.return_value = [
9597
something_else_ep,
@@ -109,7 +111,7 @@ def test__load_entry_points_entry_points(iep_mock):
109111
assert paths == expected
110112

111113
expected_calls = [
112-
call('mlblocks'),
114+
call(group='mlblocks'),
113115
]
114116
assert iep_mock.call_args_list == expected_calls
115117

0 commit comments

Comments
 (0)