File tree Expand file tree Collapse file tree 4 files changed +30
-1
lines changed
Expand file tree Collapse file tree 4 files changed +30
-1
lines changed Original file line number Diff line number Diff line change @@ -96,6 +96,16 @@ def load(self):
9696 attrs = filter (None , (match .group ('attr' ) or '' ).split ('.' ))
9797 return functools .reduce (getattr , attrs , module )
9898
99+ @property
100+ def module (self ):
101+ match = self .pattern .match (self .value )
102+ return match .group ('module' )
103+
104+ @property
105+ def attr (self ):
106+ match = self .pattern .match (self .value )
107+ return match .group ('attr' )
108+
99109 @property
100110 def extras (self ):
101111 match = self .pattern .match (self .value )
Original file line number Diff line number Diff line change 22 importlib_metadata NEWS
33=========================
44
5+ v1.6.0
6+ ======
7+
8+ * Added ``module `` and ``attr `` attributes to ``EntryPoint ``
9+
510v1.5.2
611======
712
Original file line number Diff line number Diff line change @@ -70,7 +70,9 @@ Entry points
7070The ``entry_points() `` function returns a dictionary of all entry points,
7171keyed by group. Entry points are represented by ``EntryPoint `` instances;
7272each ``EntryPoint `` has a ``.name ``, ``.group ``, and ``.value `` attributes and
73- a ``.load() `` method to resolve the value::
73+ a ``.load() `` method to resolve the value. There are also ``.module ``,
74+ ``.attr ``, and ``.extras `` attributes for getting the components of the
75+ ``.value `` attribute::
7476
7577 >>> eps = entry_points()
7678 >>> list(eps)
@@ -79,6 +81,12 @@ a ``.load()`` method to resolve the value::
7981 >>> wheel = [ep for ep in scripts if ep.name == 'wheel'][0]
8082 >>> wheel
8183 EntryPoint(name='wheel', value='wheel.cli:main', group='console_scripts')
84+ >>> wheel.module
85+ 'wheel.cli'
86+ >>> wheel.attr
87+ 'main'
88+ >>> wheel.extras
89+ []
8290 >>> main = wheel.load()
8391 >>> main
8492 <function main at 0x103528488>
Original file line number Diff line number Diff line change @@ -250,3 +250,9 @@ def test_json_dump(self):
250250 """
251251 with self .assertRaises (Exception ):
252252 json .dumps (self .ep )
253+
254+ def test_module (self ):
255+ assert self .ep .module == 'value'
256+
257+ def test_attr (self ):
258+ assert self .ep .attr is None
You can’t perform that action at this time.
0 commit comments