Skip to content

Commit daffaba

Browse files
committed
Orange/canvas: Replace use of pkg_resources
1 parent 5a5ebcf commit daffaba

File tree

3 files changed

+26
-21
lines changed

3 files changed

+26
-21
lines changed

Orange/canvas/__main__.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
from collections import defaultdict
1616
from datetime import date
1717
from urllib.request import urlopen, Request
18+
from packaging.version import Version
1819

19-
import pkg_resources
2020
import yaml
2121

2222
from AnyQt.QtGui import QColor, QDesktopServices, QIcon, QPalette
@@ -101,9 +101,8 @@ def run(self):
101101
self.resultReady.emit(contents)
102102

103103
def compare_versions(latest):
104-
version = pkg_resources.parse_version
105104
skipped = settings.value('startup/latest-skipped-version', "", type=str)
106-
if version(latest) <= version(current) or \
105+
if Version(latest) <= Version(current) or \
107106
latest == skipped:
108107
return
109108

@@ -187,8 +186,6 @@ def pull_notifications():
187186
if not check_notifs:
188187
return None
189188

190-
Version = pkg_resources.parse_version
191-
192189
# create settings_dict for notif requirements purposes (read-only)
193190
spec = canvasconfig.spec + config.spec
194191
settings_dict = canvasconfig.Settings(defaults=spec, store=settings)
@@ -198,7 +195,7 @@ def pull_notifications():
198195
if ep.dist is not None]
199196
installed = defaultdict(lambda: "-1")
200197
for addon in installed_list:
201-
installed[addon.project_name] = addon.version
198+
installed[addon.name] = addon.version
202199

203200
# get set of already displayed notification IDs, stored in settings["notifications/displayed"]
204201
displayedIDs = literal_eval(settings.value("notifications/displayed", "set()", str))

Orange/canvas/config.py

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
Orange Canvas Configuration
33
44
"""
5+
import pkgutil
6+
57
import random
68
import uuid
79
import warnings
@@ -11,15 +13,16 @@
1113
from typing import Dict, Any, Optional, Iterable, List
1214

1315
import packaging.version
14-
import pkg_resources
1516
import requests
1617

1718
from AnyQt.QtGui import (
18-
QPainter, QFont, QFontMetrics, QColor, QPixmap, QIcon, QGuiApplication
19+
QPainter, QFont, QFontMetrics, QColor, QImage, QPixmap, QIcon,
20+
QGuiApplication
1921
)
2022
from AnyQt.QtCore import Qt, QPoint, QRect, QSettings
2123

2224
from orangecanvas import config as occonfig
25+
from orangecanvas.config import entry_points, EntryPoint
2326
from orangecanvas.utils.settings import config_slot
2427
from orangewidget.workflow import config
2528
from orangewidget.settings import set_widget_settings_dir_components
@@ -61,6 +64,11 @@
6164
spec = [config_slot(*t) for t in spec]
6265

6366

67+
def _pixmap_from_pkg_data(package, path, format):
68+
contents = pkgutil.get_data(package, path)
69+
return QPixmap.fromImage(QImage.fromData(contents, format))
70+
71+
6472
class Config(config.Config):
6573
"""
6674
Orange application configuration
@@ -96,17 +104,16 @@ def application_icon():
96104
"""
97105
Return the main application icon.
98106
"""
99-
path = pkg_resources.resource_filename(
100-
__name__, "icons/orange-256.png"
107+
return QIcon(
108+
_pixmap_from_pkg_data(__package__, "icons/orange-256.png", "png")
101109
)
102-
return QIcon(path)
103110

104111
@staticmethod
105112
def splash_screen():
106113
splash_n = random.randint(1, 3)
107-
path = pkg_resources.resource_filename(
108-
__name__, f"icons/orange-splash-screen-{splash_n:02}.png")
109-
pm = QPixmap(path)
114+
pm = _pixmap_from_pkg_data(
115+
__name__, f"icons/orange-splash-screen-{splash_n:02}.png", "png"
116+
)
110117

111118
version = Config.ApplicationVersion
112119
if version:
@@ -138,9 +145,9 @@ def widgets_entry_points():
138145
# Ensure the 'this' distribution's ep is the first. iter_entry_points
139146
# yields them in unspecified order.
140147
all_eps = sorted(
141-
pkg_resources.iter_entry_points(WIDGETS_ENTRY),
148+
entry_points(group=WIDGETS_ENTRY),
142149
key=lambda ep:
143-
0 if ep.dist.project_name.lower() == "orange3" else 1
150+
0 if ep.dist.name.lower() == "orange3" else 1
144151
)
145152
return iter(all_eps)
146153

@@ -173,18 +180,18 @@ def core_packages():
173180

174181
@staticmethod
175182
def examples_entry_points():
176-
# type: () -> Iterable[pkg_resources.EntryPoint]
183+
# type: () -> Iterable[EntryPoint]
177184
"""
178185
Return an iterator over the entry points yielding 'Example Workflows'
179186
"""
180187
# `iter_entry_points` yields them in unspecified order, so we order
181188
# them by name. The default is at the beginning, unless another
182189
# entrypoint precedes it alphabetically (e.g. starting with '!').
183-
default_ep = pkg_resources.EntryPoint(
184-
"000-Orange3", "Orange.canvas.workflows",
185-
dist=pkg_resources.get_distribution("Orange3"))
190+
default_ep = EntryPoint(
191+
"000-Orange3", "Orange.canvas.workflows", "orange.widgets.tutorials",
192+
)
186193

187-
all_ep = list(pkg_resources.iter_entry_points("orange.widgets.tutorials"))
194+
all_ep = list(entry_points(group="orange.widgets.tutorials"))
188195
all_ep.append(default_ep)
189196
all_ep.sort(key=lambda x: x.name)
190197
return iter(all_ep)

requirements-core.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ networkx
1212
numpy>=1.20.0
1313
openpyxl
1414
openTSNE>=0.6.1,!=0.7.0 # 0.7.0 segfaults
15+
packaging
1516
pandas>=1.4.0,!=1.5.0,!=2.0.0
1617
pip>=18.0
1718
python-louvain>=0.13

0 commit comments

Comments
 (0)