Skip to content

Commit 50d07c9

Browse files
committed
Switch to packaging and importlib_metadata (fixes Nuitka build)
1 parent 4e1dfd8 commit 50d07c9

File tree

2 files changed

+24
-20
lines changed

2 files changed

+24
-20
lines changed

emailproxy.py

+22-19
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
__author__ = 'Simon Robinson'
77
__copyright__ = 'Copyright (c) 2024 Simon Robinson'
88
__license__ = 'Apache 2.0'
9-
__version__ = '2024-07-08' # ISO 8601 (YYYY-MM-DD)
9+
__version__ = '2024-07-29' # ISO 8601 (YYYY-MM-DD)
1010
__package_version__ = '.'.join([str(int(i)) for i in __version__.split('-')]) # for pyproject.toml usage only
1111

1212
import abc
@@ -99,14 +99,22 @@ class Icon:
9999
except ImportError as gui_requirement_import_error:
100100
MISSING_GUI_REQUIREMENTS.append(gui_requirement_import_error)
101101

102-
with warnings.catch_warnings():
103-
warnings.simplefilter('ignore', DeprecationWarning)
102+
try:
103+
# pylint: disable-next=ungrouped-imports
104+
import importlib.metadata as importlib_metadata # get package version numbers - available in stdlib from python 3.8
105+
except ImportError:
104106
try:
105-
# noinspection PyDeprecation,PyUnresolvedReferences
106-
import pkg_resources # from setuptools - to change to importlib.metadata and packaging.version once min. is 3.8
107+
# noinspection PyUnresolvedReferences
108+
import importlib_metadata
107109
except ImportError as gui_requirement_import_error:
108110
MISSING_GUI_REQUIREMENTS.append(gui_requirement_import_error)
109111

112+
try:
113+
# noinspection PyUnresolvedReferences
114+
import packaging.version # parse package version numbers - used to work around various GUI-only package issues
115+
except ImportError as gui_requirement_import_error:
116+
MISSING_GUI_REQUIREMENTS.append(gui_requirement_import_error)
117+
110118
# for macOS-specific functionality
111119
if sys.platform == 'darwin':
112120
try:
@@ -2696,13 +2704,12 @@ def macos_nsworkspace_notification_listener_(self, notification):
26962704
# noinspection PyDeprecation
26972705
def create_icon(self):
26982706
# fix pystray <= 0.19.4 incompatibility with PIL 10.0.0+; resolved in 0.19.5 and later via pystray PR #147
2699-
with warnings.catch_warnings():
2700-
warnings.simplefilter('ignore', DeprecationWarning)
2701-
pystray_version = pkg_resources.get_distribution('pystray').version
2702-
pillow_version = pkg_resources.get_distribution('pillow').version
2703-
if pkg_resources.parse_version(pystray_version) <= pkg_resources.parse_version('0.19.4') and \
2704-
pkg_resources.parse_version(pillow_version) >= pkg_resources.parse_version('10.0.0'):
2705-
Image.ANTIALIAS = Image.LANCZOS if hasattr(Image, 'LANCZOS') else Image.Resampling.LANCZOS
2707+
pystray_version = packaging.version.Version(importlib_metadata.version('pystray'))
2708+
pillow_version = packaging.version.Version(importlib_metadata.version('pillow'))
2709+
if pystray_version <= packaging.version.Version('0.19.4') and \
2710+
pillow_version >= packaging.version.Version('10.0.0'):
2711+
Image.ANTIALIAS = Image.LANCZOS if hasattr(Image, 'LANCZOS') else Image.Resampling.LANCZOS
2712+
27062713
icon_class = RetinaIcon if sys.platform == 'darwin' else pystray.Icon
27072714
return icon_class(APP_NAME, App.get_image(), APP_NAME, menu=pystray.Menu(
27082715
pystray.MenuItem('Servers and accounts', pystray.Menu(self.create_config_menu)),
@@ -2763,9 +2770,7 @@ def get_icon_size(text, font_size):
27632770
font = ImageFont.truetype(io.BytesIO(zlib.decompress(base64.b64decode(APP_ICON))), size=font_size)
27642771

27652772
# pillow's getsize method was deprecated in 9.2.0 (see docs for PIL.ImageFont.ImageFont.getsize)
2766-
# noinspection PyDeprecation
2767-
if pkg_resources.parse_version(
2768-
pkg_resources.get_distribution('pillow').version) < pkg_resources.parse_version('9.2.0'):
2773+
if packaging.version.Version(importlib_metadata.version('pillow')) < packaging.version.Version('9.2.0'):
27692774
font_width, font_height = font.getsize(text)
27702775
return font, font_width, font_height
27712776

@@ -2906,11 +2911,9 @@ def create_authorisation_window(self, request):
29062911
setattr(authorisation_window, 'get_title', lambda window: window.title) # add missing get_title method
29072912

29082913
# pywebview 3.6+ moved window events to a separate namespace in a non-backwards-compatible way
2909-
# noinspection PyDeprecation
2910-
pywebview_version = pkg_resources.parse_version(pkg_resources.get_distribution('pywebview').version)
2914+
pywebview_version = packaging.version.Version(importlib_metadata.version('pywebview'))
29112915
# the version zero check is due to a bug in the Ubuntu 24.04 python-pywebview package - see GitHub #242
2912-
# noinspection PyDeprecation
2913-
if pkg_resources.parse_version('0') < pywebview_version < pkg_resources.parse_version('3.6'):
2916+
if packaging.version.Version('0') < pywebview_version < packaging.version.Version('3.6'):
29142917
# noinspection PyUnresolvedReferences
29152918
authorisation_window.loaded += self.authorisation_window_loaded
29162919
else:

requirements-gui.txt

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
# the standard way to install the proxy and dependencies is `python -m pip install emailproxy` (i.e., direct from PyPI)
22
# to install requirements directly, use: `python -m pip install -r requirements-core.txt -r requirements-gui.txt`
33

4+
importlib_metadata; python_version < '3.8' # to get dependency versions (available in stdlib from 3.8 onwards)
5+
packaging # for dependency version comparisons
46
pillow # to create the menu bar icon image from a TTF icon
5-
setuptools # for pkg_resources (checking dependency versions)
67
timeago # for displaying the last authenticated activity hint
78

89
# force pystray version with dummy GUI fix for headless deployments (https://github.com/moses-palmer/pystray/issues/118)

0 commit comments

Comments
 (0)