diff --git a/.github/workflows/check-code-and-run-tests.yml b/.github/workflows/check-code-and-run-tests.yml index 9b3d1d7b..2d45d6f5 100644 --- a/.github/workflows/check-code-and-run-tests.yml +++ b/.github/workflows/check-code-and-run-tests.yml @@ -30,7 +30,7 @@ jobs: strategy: fail-fast: false matrix: - python-version: ["3.10"] # ["2.7", "3.6", "3.10"] + python-version: ["3.10", "3.13"] # ["2.7", "3.6", "3.10"] steps: - name: Checkout uses: actions/checkout@v4 diff --git a/bin/monkeylord.py b/bin/monkeylord.py index 984f14e7..cc1481d0 100644 --- a/bin/monkeylord.py +++ b/bin/monkeylord.py @@ -32,7 +32,7 @@ def save_config(path): def load_config(path): """load the config from path""" - with open(path, "rU") as f: + with open(path, "r") as f: tl = json.load(f) patches.PATCHES["ALL"].disable() for k in sorted(tl): # sort is important to load groups first diff --git a/core.py b/core.py index bc5db216..d5d2f327 100644 --- a/core.py +++ b/core.py @@ -7,7 +7,7 @@ __version__ = "0.7.5" -import imp as pyimp # rename to avoid name conflict with objc_util +import importlib import logging import logging.handlers import os @@ -101,6 +101,17 @@ pass +def load_source(modname, filename): + loader = importlib.machinery.SourceFileLoader(modname, filename) + spec = importlib.util.spec_from_file_location(modname, filename, loader=loader) + module = importlib.util.module_from_spec(spec) + # The module is always executed and not cached in sys.modules. + # Uncomment the following line to cache the module. + # sys.modules[module.__name__] = module + loader.exec_module(module) + return module + + class StaSh(object): """ Main application class. It initialize and wires the components and provide @@ -292,7 +303,7 @@ def _load_lib(self): "Attempting to load library '{}'...".format(name) ) try: - self.__dict__[name] = pyimp.load_source(name, fp) + self.__dict__[name] = load_source(name, fp) except Exception as e: self.write_message( "%s: failed to load library file (%s)" % (f, repr(e)), diff --git a/getstash.py b/getstash.py index 104acd94..59e5e0f7 100644 --- a/getstash.py +++ b/getstash.py @@ -270,7 +270,7 @@ def setup_install( "__name__": "__main__", "__file__": fp, } - with open(fp, "rU") as fin: + with open(fp, "r") as fin: content = fin.read() code = compile(content, fp, "exec", dont_inherit=True) exec(code, ns, ns) diff --git a/lib/mlpatches/base.py b/lib/mlpatches/base.py index f9dc77cb..ac05095e 100644 --- a/lib/mlpatches/base.py +++ b/lib/mlpatches/base.py @@ -1,10 +1,11 @@ # -*- coding: utf-8 -*- """This module contains the base class for patches.""" -import sys -import imp +import importlib import os +import sys +from stash.core import load_source from stashutils.core import get_stash SKIP = "' # indicate that this patch should be skipped.'" @@ -98,9 +99,9 @@ def do_enable(self): ): raise ValueError("Invalid Patch definition!") if self.module not in sys.modules: - fin, path, description = imp.find_module(self.module) + fin, path, description = importlib.find_module(self.module) try: - module = imp.load_module(self.module, fin, path, description) + module = importlib.load_module(self.module, fin, path, description) finally: fin.close() else: @@ -139,7 +140,7 @@ def do_enable(self): if self.name in sys.modules: del sys.modules[self.name] with open(self.path, "r") as f: - nmod = imp.load_source(self.name, self.path, f) + nmod = load_source(self.name, self.path, f) sys.modules[self.name] = nmod def do_disable(self): diff --git a/lib/mlpatches/modules/subprocess.py b/lib/mlpatches/modules/subprocess.py index 1e273a5d..3100fd40 100644 --- a/lib/mlpatches/modules/subprocess.py +++ b/lib/mlpatches/modules/subprocess.py @@ -122,7 +122,7 @@ def __init__( self.cmd = l2c.list2cmdline(args) # === setup std* === - rfm = "rU" if universal_newlines else "rb" + rfm = "r" if universal_newlines else "rb" # setup stdout if stdout is None: # use own stdout diff --git a/lib/stashutils/core.py b/lib/stashutils/core.py index d41ee607..049cf16f 100644 --- a/lib/stashutils/core.py +++ b/lib/stashutils/core.py @@ -2,9 +2,9 @@ """core utilities for StaSh-scripts""" import threading -import imp import os +from stash.core import load_source from stash.system import shthreads @@ -37,7 +37,7 @@ def load_from_dir(dirpath, varname): if not os.path.isfile(fp): continue with open(fp, "r") as fin: - mod = imp.load_source(fn[: fn.index(".")], fp, fin) + mod = load_source(fn[: fn.index(".")], fp, fin) if not hasattr(mod, varname): continue else: diff --git a/lib/stashutils/fsi/DropBox.py b/lib/stashutils/fsi/DropBox.py index aad3fb03..91b4d043 100644 --- a/lib/stashutils/fsi/DropBox.py +++ b/lib/stashutils/fsi/DropBox.py @@ -146,7 +146,7 @@ def isfile(self, name): def open(self, name, mode="rb", buffering=0): mode = mode.replace("+", "") ap = self.abspath(name) - if mode in ("r", "rb", "rU"): + if mode in ("r", "rb"): try: response = self.client.files_download(ap)[1] # unfortunaly, we cant return response.raw because it does not diff --git a/setup.py b/setup.py index f46c0244..988a7b98 100644 --- a/setup.py +++ b/setup.py @@ -65,6 +65,7 @@ "requests", "pycrypto", "pyte", + "standard-imghdr", ], ) TEST_REQUIREMENTS = [ diff --git a/tests/stashtest.py b/tests/stashtest.py index 94b60eeb..e58849f6 100644 --- a/tests/stashtest.py +++ b/tests/stashtest.py @@ -18,7 +18,7 @@ from stash.system.shcommon import _STASH_ROOT, PY3 -ON_TRAVIS = "TRAVIS" in os.environ +ON_TRAVIS = "CI" in os.environ def network_is_available():