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

fix(linux): Replace deprecated pkg_resources module with packaging.version #10860

Merged
merged 4 commits into from
Mar 20, 2024
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
4 changes: 3 additions & 1 deletion linux/debian/control
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ Build-Depends:
python3-lxml,
python3-magic,
python3-numpy,
python3-packaging,
python3-pil,
python3-pip,
python3-qrcode,
Expand Down Expand Up @@ -83,13 +84,14 @@ Package: python3-keyman-config
Section: python
Architecture: all
Depends:
dbus-x11,
dconf-cli,
gir1.2-webkit2-4.1 | gir1.2-webkit2-4.0,
keyman-engine,
python3-bs4,
python3-gi,
python3-packaging,
python3-sentry-sdk (>= 1.1),
dbus-x11,
${misc:Depends},
${python3:Depends},
Description: Keyman for Linux configuration
Expand Down
4 changes: 2 additions & 2 deletions linux/keyman-config/keyman_config/install_kmp.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import json
import logging
import os
import packaging.version
import zipfile
from pkg_resources import parse_version
from enum import Enum
from shutil import rmtree

Expand Down Expand Up @@ -149,7 +149,7 @@ def _check_version(self, inputfile, system):
fileVersion = secure_lookup(system, 'fileVersion')
if not fileVersion:
fileVersion = '7.0'
if parse_version(fileVersion) > parse_version(__version__):
if packaging.version.parse(fileVersion) > packaging.version.parse(__version__):
logging.error("install_kmp.py: error: %s requires a newer version of Keyman (%s)",
inputfile, fileVersion)
rmtree(self.packageDir)
Expand Down
10 changes: 5 additions & 5 deletions linux/keyman-config/keyman_config/install_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import sys
import tempfile
import webbrowser
import packaging.version

import gi

Expand All @@ -20,8 +21,6 @@
# TODO: Remove once we drop support for Ubuntu 20.04 Focal
gi.require_version('WebKit2', '4.0')

from pkg_resources import parse_version

from gi.repository import Gtk, WebKit2

from keyman_config import _, secure_lookup
Expand Down Expand Up @@ -134,11 +133,12 @@ def _show_no_pkg_error(self, kmpfile, viewkmp):
self.checkcontinue = False

def _uninstall_prev_version_if_necessary(self, keyboardid, viewkmp, installed_kmp_ver, info):
if not installed_kmp_ver or not secure_lookup(info, 'version', 'description'):
new_kmp_version = secure_lookup(info, 'version', 'description')
if not installed_kmp_ver or not new_kmp_version:
return True
logging.info("package version %s", secure_lookup(info, 'version', 'description'))
logging.info("package version %s", new_kmp_version)
logging.info("installed kmp version %s", installed_kmp_ver)
if parse_version(secure_lookup(info, 'version', 'description')) >= parse_version(installed_kmp_ver):
if packaging.version.parse(new_kmp_version) >= packaging.version.parse(installed_kmp_ver):
return True
response = self._show_version_message_dlg(
viewkmp,
Expand Down
4 changes: 2 additions & 2 deletions linux/keyman-config/keyman_config/list_installed_kmp.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import json
import logging
import os
from pkg_resources import parse_version
import packaging.version

from keyman_config import secure_lookup
from keyman_config.deprecated_decorator import deprecated
Expand Down Expand Up @@ -133,7 +133,7 @@ def _get_kmp_version_internal(packageId, location, previousVersion):
kmp = get_installed_kmp(location)
if packageId in kmp:
version = kmp[packageId]['kmpversion']
if not previousVersion or parse_version(previousVersion) < parse_version(version):
if not previousVersion or packaging.version.parse(previousVersion) < packaging.version.parse(version):
previousVersion = version
return previousVersion

Expand Down
8 changes: 4 additions & 4 deletions linux/keyman-config/km-package-install
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import argparse
import datetime
import logging
import os
import requests
import requests_cache
import sys
import time
from pkg_resources import parse_version
from zipfile import is_zipfile
import packaging.version
import requests
import requests_cache

from keyman_config import KeymanApiUrl, add_standard_arguments, initialize_logging, initialize_sentry, secure_lookup
from keyman_config.get_kmp import get_keyboard_data, get_kmp, keyman_cache_dir
Expand Down Expand Up @@ -175,7 +175,7 @@ def main():
sys.exit(3)
pkg_version = secure_lookup(pkgdata, 'version')
if installed_kmp_ver and pkg_version:
if parse_version(installed_kmp_ver) > parse_version(pkg_version):
if packaging.version.parse(installed_kmp_ver) > packaging.version.parse(pkg_version):
if args.force:
logging.warning(f'km-package-install: warning: The {args.package} keyboard ' +
f'is already installed with a newer version {installed_kmp_ver}. ' +
Expand Down
13 changes: 11 additions & 2 deletions linux/keyman-config/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,17 @@
zip_safe=False, # don't install a zip

install_requires=[
'lxml', 'numpy', 'Pillow', 'requests', 'requests-cache',
'python-magic', 'qrcode', 'sentry-sdk'
'dbus-python',
'lxml',
'numpy',
'packaging',
'pillow',
'PyGObject',
'python-magic',
'qrcode',
'requests-cache',
'requests',
'sentry-sdk',
],

# metadata to display on PyPI
Expand Down
Loading