diff --git a/dronecan_gui_tool/main.py b/dronecan_gui_tool/main.py index 611ffc2..433594e 100644 --- a/dronecan_gui_tool/main.py +++ b/dronecan_gui_tool/main.py @@ -60,7 +60,7 @@ # Start method must be configured globally, and only once. Using 'spawn' ensures full compatibility with Windoze. # We need to check first if the start mode is already configured, because this code will be re-run for every child. # -if multiprocessing.get_start_method(True) != 'spawn': +if multiprocessing.get_start_method(allow_none=True) is None: multiprocessing.set_start_method('spawn') # diff --git a/dronecan_gui_tool/widgets/__init__.py b/dronecan_gui_tool/widgets/__init__.py index d93bcd9..ee2b61b 100644 --- a/dronecan_gui_tool/widgets/__init__.py +++ b/dronecan_gui_tool/widgets/__init__.py @@ -8,7 +8,7 @@ import os import re -import pkg_resources +import importlib.resources import queue from PyQt5.QtWidgets import QTableWidget, QTableWidgetItem, QAbstractItemView, QHeaderView, QApplication, QWidget, \ QComboBox, QCompleter, QPushButton, QHBoxLayout, QVBoxLayout, QMessageBox @@ -640,8 +640,9 @@ def get_app_icon(): pass # noinspection PyBroadException try: - fn = pkg_resources.resource_filename('dronecan_gui_tool', os.path.join('icons', 'dronecan_gui_tool.png')) - _APP_ICON_OBJECT = QIcon(fn) + icon_resource = importlib.resources.files('dronecan_gui_tool').joinpath('icons', 'dronecan_gui_tool.png') + with importlib.resources.as_file(icon_resource) as icon_path: + _APP_ICON_OBJECT = QIcon(str(icon_path)) except Exception: logger.error('Could not load icon', exc_info=True) _APP_ICON_OBJECT = QIcon() diff --git a/pip_sizes.py b/pip_sizes.py index e0b5226..8f80347 100644 --- a/pip_sizes.py +++ b/pip_sizes.py @@ -1,7 +1,7 @@ #!/usr/bin/env python import os -import pkg_resources +import importlib.metadata def calc_container(path): total_size = 0 @@ -13,7 +13,7 @@ def calc_container(path): -dists = [d for d in pkg_resources.working_set] +dists = list(importlib.metadata.distributions()) data = {} data2 = [] @@ -21,16 +21,18 @@ def calc_container(path): for dist in dists: try: - path = os.path.join(dist.location, dist.project_name) + dist_name = dist.metadata.get('Name', 'unknown') + path = os.path.join(str(dist.locate_file('')), dist_name) + if not os.path.exists(path): + path = os.path.join(str(dist.locate_file('')), dist_name.replace('-', '_')) size = calc_container(path) if size/1000 > 1.0: - #print (f"{dist}: {size/1000} KB") - data[size] = f"{dist}: {size/1000} KB" - a = f"{dist}" - data2.append(a.split()[0])# first word - data3[a.split()[0]] = f"{dist}: {size/1000} KB" + dist_label = f"{dist_name} {dist.metadata.get('Version', '')}" + data[size] = f"{dist_label}: {size/1000} KB" + data2.append(dist_name) + data3[dist_name] = f"{dist_label}: {size/1000} KB" except OSError: - '{} no longer exists'.format(dist.project_name) + pass sorted_dict = dict(sorted(data.items())) sorted_dict2 = sorted(data2) diff --git a/setup.py b/setup.py index dea9620..1a74f92 100755 --- a/setup.py +++ b/setup.py @@ -10,10 +10,8 @@ import os import sys import shutil -import pkg_resources import glob from setuptools import setup, find_packages -from setuptools.archive_util import unpack_archive PACKAGE_NAME = 'dronecan_gui_tool' HUMAN_FRIENDLY_NAME = 'DroneCAN GUI Tool' @@ -115,6 +113,8 @@ if ('bdist_msi' in sys.argv) or ('build_exe' in sys.argv): import cx_Freeze + import importlib.metadata + from setuptools.archive_util import unpack_archive # cx_Freeze can't handle 3rd-party packages packed in .egg files, so we have to extract them for it dependency_eggs_to_unpack = [ @@ -130,9 +130,13 @@ except Exception: pass for dep in dependency_eggs_to_unpack: - for egg in pkg_resources.require(dep): - if not os.path.isdir(egg.location): - unpack_archive(egg.location, unpacked_eggs_dir) + try: + dist = importlib.metadata.distribution(dep) + except importlib.metadata.PackageNotFoundError: + continue + dist_location = str(dist.locate_file('')) + if not os.path.isdir(dist_location): + unpack_archive(dist_location, unpacked_eggs_dir) import qtawesome import qtconsole @@ -153,7 +157,7 @@ args['options'] = { 'build_exe': { 'packages': [ - 'pkg_resources', + 'importlib.metadata', 'zmq', 'pygments', 'jupyter_client',