From ada873dc7723fa55243cb1a5aa59cb70c5859a95 Mon Sep 17 00:00:00 2001 From: janezd Date: Fri, 5 Feb 2021 12:03:55 +0100 Subject: [PATCH] Add Orange.util.get_entry_point --- Orange/tests/test_util.py | 8 +++++++- Orange/util.py | 13 +++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/Orange/tests/test_util.py b/Orange/tests/test_util.py index 8ef8df58deb..7ea7482e904 100644 --- a/Orange/tests/test_util.py +++ b/Orange/tests/test_util.py @@ -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']) diff --git a/Orange/util.py b/Orange/util.py index efb9c7da51e..ea67b27c715 100644 --- a/Orange/util.py +++ b/Orange/util.py @@ -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.