Skip to content

Commit

Permalink
Merge pull request #5600 from mw25/sorting-example-workflows
Browse files Browse the repository at this point in the history
[ENH] config: sort example workflows
  • Loading branch information
ales-erjavec authored Sep 24, 2021
2 parents fde224f + f71c93e commit 03e8ada
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
15 changes: 8 additions & 7 deletions Orange/canvas/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,16 +176,17 @@ def examples_entry_points():
"""
Return an iterator over the entry points yielding 'Example Workflows'
"""
# `iter_entry_points` yields them in unspecified order, so we insert
# our first
# `iter_entry_points` yields them in unspecified order, so we order
# them by name. The default is at the beginning, unless another
# entrypoint precedes it alphabetically (e.g. starting with '!').
default_ep = pkg_resources.EntryPoint(
"Orange3", "Orange.canvas.workflows",
"000-Orange3", "Orange.canvas.workflows",
dist=pkg_resources.get_distribution("Orange3"))

return itertools.chain(
(default_ep,),
pkg_resources.iter_entry_points("orange.widgets.tutorials")
)
all_ep = list(pkg_resources.iter_entry_points("orange.widgets.tutorials"))
all_ep.append(default_ep)
all_ep.sort(key=lambda x: x.name)
return iter(all_ep)

APPLICATION_URLS = {
#: Submit a bug report action in the Help menu
Expand Down
17 changes: 17 additions & 0 deletions Orange/widgets/tests/test_workflows.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from os import listdir, environ
from os.path import isfile, join, dirname
import unittest
import pkg_resources

from orangecanvas.registry import WidgetRegistry
from orangewidget.workflow import widgetsscheme
Expand Down Expand Up @@ -54,3 +55,19 @@ def test_scheme_examples(self):
format(ows_file, str(e)))
finally:
new_scheme.clear()

def test_examples_order(self):
# register test entrypoints
dist_orange = pkg_resources.working_set.by_key['orange3']
ep_map = dist_orange.get_entry_map()
ep_first = pkg_resources.EntryPoint('!Testname', 'orangecontrib.any_addon.tutorials')
ep_last = pkg_resources.EntryPoint('exampletutorials', 'orangecontrib.other_addon.tutorials')
ep_map['orange.widgets.tutorials'] = {ep_first.name: ep_first, ep_last.name: ep_last}

entry_points = list(Config.examples_entry_points())

self.assertEqual(entry_points[0].name, ep_first.name)
self.assertEqual(entry_points[1].name, '000-Orange3')
self.assertEqual(entry_points[2].name, ep_last.name)

del ep_map['orange.widgets.tutorials']

0 comments on commit 03e8ada

Please sign in to comment.