From 904693a496c5371bb8eb2d57698b720770c52f14 Mon Sep 17 00:00:00 2001 From: Mathieu Bridon Date: Mon, 13 Nov 2023 09:33:30 +0100 Subject: [PATCH] Fix the fuck for Python 3.12 The imp module has been long deprecated and has been removed entirely in Python 3.12. This solution is what was suggested in the release notes: https://docs.python.org/3.12/whatsnew/3.12.html#imp --- thefuck/conf.py | 14 ++++++++++++++ thefuck/types.py | 14 ++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/thefuck/conf.py b/thefuck/conf.py index 611ec84..48bcf3b 100644 --- a/thefuck/conf.py +++ b/thefuck/conf.py @@ -4,6 +4,20 @@ from warnings import warn from six import text_type from . import const from .system import Path + +import importlib.util +import importlib.machinery + + +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 try: import importlib.util diff --git a/thefuck/types.py b/thefuck/types.py index b3b64c3..2f6109e 100644 --- a/thefuck/types.py +++ b/thefuck/types.py @@ -8,6 +8,20 @@ from .exceptions import EmptyCommand from .utils import get_alias, format_raw_script from .output_readers import get_output +import importlib.util +import importlib.machinery + + +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 Command(object): """Command that should be fixed."""