Skip to content

Commit

Permalink
replace use of imp with importlib
Browse files Browse the repository at this point in the history
The imp module has been deprecated since Python 3.4 and was removed in
Python 3.12. Use importlib, the recommended replacement, instead. Code
based on the recipe for importing a source file directly in the official
docs:
https://docs.python.org/3.12/library/importlib.html#importing-a-source-file-directly.
  • Loading branch information
jonahbull committed Nov 10, 2023
1 parent 8b5d026 commit 453d92a
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions ledgerautosync/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@


import argparse
import imp
import importlib.util
import logging
import os
import os.path
Expand Down Expand Up @@ -233,10 +233,12 @@ def load_plugins(config_dir):
# Quiet loader
import ledgerautosync.plugins # noqa: F401

path = os.path.join(plugin_dir, plugin)
imp.load_source(
"ledgerautosync.plugins.%s" % (os.path.splitext(plugin)[0]), path
)
file_path = os.path.join(plugin_dir, plugin)
module_name = f"ledgerautosync.plugins.{os.path.splitext(plugin)[0]}"
spec = importlib.util.spec_from_file_location(module_name, file_path)
module = importlib.util.module_from_spec(spec)
sys.modules[module_name] = module
spec.loader.exec_module(module)


def run(args=None, config=None):
Expand Down

0 comments on commit 453d92a

Please sign in to comment.