Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ENH] config: sort example workflows #5600

Merged
merged 1 commit into from
Sep 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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']