Skip to content

Commit

Permalink
Add Orange.util.get_entry_point
Browse files Browse the repository at this point in the history
  • Loading branch information
janezd committed Feb 5, 2021
1 parent 5cda891 commit ada873d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
8 changes: 7 additions & 1 deletion Orange/tests/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,18 @@
from Orange.data.util import vstack, hstack, array_equal
from Orange.statistics.util import stats
from Orange.tests.test_statistics import dense_sparse
from Orange.util import wrap_callback
from Orange.util import wrap_callback, get_entry_point

SOMETHING = 0xf00babe


class TestUtil(unittest.TestCase):
def test_get_entry_point(self):
# pylint: disable=import-outside-toplevel
from Orange.canvas.__main__ import main as real_main
main = get_entry_point("Orange3", "gui_scripts", "orange-canvas")
self.assertIs(main, real_main)

def test_export_globals(self):
self.assertEqual(sorted(export_globals(globals(), __name__)),
['SOMETHING', 'TestUtil'])
Expand Down
13 changes: 13 additions & 0 deletions Orange/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,19 @@ def resource_filename(path):
return pkg_resources.resource_filename("Orange", path)


def get_entry_point(dist, group, name):
"""
Load and return the entry point from the distribution.
Unlike `pkg_resources.load_entry_point`, this function does not check
for requirements. Calling this function is preferred because of developers
who experiment with different versions and have inconsistent configurations.
"""
dist = pkg_resources.get_distribution(dist)
ep = dist.get_entry_info(group, name)
return ep.resolve()


def deprecated(obj):
"""
Decorator. Mark called object deprecated.
Expand Down

0 comments on commit ada873d

Please sign in to comment.