| 1 | Patch-Source: https://github.com/tibonihoo/yapsy/commit/29286320673f9e853559cf20aeb3456e541afbd4
|
| 2 | From 29286320673f9e853559cf20aeb3456e541afbd4 Mon Sep 17 00:00:00 2001
|
| 3 | From: Ameya Vikram Singh <[email protected]>
|
| 4 | Date: Mon, 6 Feb 2023 13:31:23 +0530
|
| 5 | Subject: [PATCH] Remove Deprecated API's
|
| 6 |
|
| 7 | * Replaced packaging.version instead of distutils.version
|
| 8 | * Replaced imp module to importlib
|
| 9 |
|
| 10 | **Note:** Probably Deprecates Python 2.7 supports, and maybe some initial versions of Python 3.x.
|
| 11 |
|
| 12 | Signed-off-by: Ameya Vikram Singh <[email protected]>
|
| 13 | ---
|
| 14 | test/test_PluginInfo.py | 3 ++-
|
| 15 | yapsy/PluginInfo.py | 6 +++---
|
| 16 | yapsy/PluginManager.py | 17 ++++++++++-------
|
| 17 | yapsy/VersionedPluginManager.py | 8 ++++----
|
| 18 | 4 files changed, 19 insertions(+), 15 deletions(-)
|
| 19 |
|
| 20 | diff --git a/test/test_PluginInfo.py b/test/test_PluginInfo.py
|
| 21 | index 0863671..745226f 100644
|
| 22 | |
| 23 | |
| 24 | @@ -22,3 +22,3 @@ class PluginInfoTest(unittest.TestCase):
|
| 25 | self.assertEqual(None,pi.error)
|
| 26 | - self.assertEqual("0.0",pi.version)
|
| 27 | + self.assertEqual("0.0",str(pi.version))
|
| 28 | self.assertEqual("Unknown",pi.author)
|
| 29 | diff --git a/yapsy/PluginInfo.py b/yapsy/PluginInfo.py
|
| 30 | index 69d220e..700374e 100644
|
| 31 | |
| 32 | |
| 33 | @@ -14,3 +14,3 @@ API
|
| 34 | from yapsy.compat import ConfigParser
|
| 35 | -from distutils.version import StrictVersion
|
| 36 | +from packaging.version import Version
|
| 37 |
|
| 38 | @@ -107,3 +107,3 @@ class PluginInfo(object):
|
| 39 | def __getVersion(self):
|
| 40 | - return StrictVersion(self.details.get("Documentation","Version"))
|
| 41 | + return Version(self.details.get("Documentation","Version"))
|
| 42 |
|
| 43 | @@ -116,3 +116,3 @@ class PluginInfo(object):
|
| 44 | """
|
| 45 | - if isinstance(vstring,StrictVersion):
|
| 46 | + if isinstance(vstring,Version):
|
| 47 | vstring = str(vstring)
|
| 48 | diff --git a/yapsy/PluginManager.py b/yapsy/PluginManager.py
|
| 49 | index 81a7c2b..b72de93 100644
|
| 50 | |
| 51 | |
| 52 | @@ -130,6 +130,3 @@ import sys
|
| 53 | import os
|
| 54 | -try:
|
| 55 | - import importlib.abc.Loader as imp
|
| 56 | -except ImportError:
|
| 57 | - import imp
|
| 58 | +import importlib
|
| 59 |
|
| 60 | @@ -579,7 +576,13 @@ class PluginManager(object):
|
| 61 | # use imp to correctly load the plugin as a module
|
| 62 | + candidate_module = None
|
| 63 | if os.path.isdir(candidate_filepath):
|
| 64 | - candidate_module = imp.load_module(plugin_module_name,None,candidate_filepath,("py","r",imp.PKG_DIRECTORY))
|
| 65 | + if (spec := importlib.util.spec_from_file_location(candidate_filepath.split('/')[-1], candidate_filepath + "/__init__.py")) is not None:
|
| 66 | + candidate_module = importlib.util.module_from_spec(spec)
|
| 67 | + sys.modules[plugin_module_name] = candidate_module
|
| 68 | + spec.loader.exec_module(candidate_module)
|
| 69 | else:
|
| 70 | - with open(candidate_filepath+".py","r") as plugin_file:
|
| 71 | - candidate_module = imp.load_module(plugin_module_name,plugin_file,candidate_filepath+".py",("py","r",imp.PY_SOURCE))
|
| 72 | + if (spec := importlib.util.spec_from_file_location(candidate_filepath.split('/')[-1], candidate_filepath + ".py")) is not None:
|
| 73 | + candidate_module = importlib.util.module_from_spec(spec)
|
| 74 | + sys.modules[plugin_module_name] = candidate_module
|
| 75 | + spec.loader.exec_module(candidate_module)
|
| 76 | return candidate_module
|
| 77 | diff --git a/yapsy/VersionedPluginManager.py b/yapsy/VersionedPluginManager.py
|
| 78 | index 83ad4fd..686a52a 100644
|
| 79 | |
| 80 | |
| 81 | @@ -14,3 +14,3 @@ API
|
| 82 |
|
| 83 | -from distutils.version import StrictVersion
|
| 84 | +from packaging.version import Version
|
| 85 |
|
| 86 | @@ -29,7 +29,7 @@ class VersionedPluginInfo(PluginInfo):
|
| 87 | PluginInfo.__init__(self, plugin_name, plugin_path)
|
| 88 | - # version number is now required to be a StrictVersion object
|
| 89 | - self.version = StrictVersion("0.0")
|
| 90 | + # version number is now required to be a Version object
|
| 91 | + self.version = Version("0.0")
|
| 92 |
|
| 93 | def setVersion(self, vstring):
|
| 94 | - self.version = StrictVersion(vstring)
|
| 95 | + self.version = Version(vstring)
|
| 96 |
|