Skip to content

Commit 284e337

Browse files
committed
Use 'importlib' to load extra configuration
Rather than the deprecated 'imp' module.
1 parent 506e20e commit 284e337

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

django_lightweight_queue/utils.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import imp
21
import time
32
import datetime
43
import warnings
54
import importlib
5+
import importlib.util
66
from typing import (
77
Any,
88
Set,
@@ -33,7 +33,10 @@
3333

3434

3535
def load_extra_config(file_path: str) -> None:
36-
extra_settings = imp.load_source('extra_settings', file_path)
36+
# Based on https://docs.python.org/3/library/importlib.html#importing-a-source-file-directly
37+
spec = importlib.util.spec_from_file_location('extra_settings', file_path)
38+
extra_settings = importlib.util.module_from_spec(spec) # type: ignore[arg-type]
39+
spec.loader.exec_module(extra_settings) # type: ignore[union-attr]
3740

3841
def get_setting_names(module: object) -> Set[str]:
3942
return set(name for name in dir(module) if name.isupper())

0 commit comments

Comments
 (0)