diff options
author | Takashi Kajinami <tkajinam@redhat.com> | 2021-12-28 09:11:00 +0900 |
---|---|---|
committer | Takashi Kajinami <tkajinam@redhat.com> | 2022-02-08 13:15:19 +0000 |
commit | 5d0b2b74d4fb62049ddcc2e4000c7771e0749165 (patch) | |
tree | 8a6137b4b505000eb9db0bde4f8da1361d2d11c1 /openstack_dashboard/management | |
parent | 12bb9fe5184c9dd3329ba17b3d03c90887dbcc3d (diff) | |
download | horizon-5d0b2b74d4fb62049ddcc2e4000c7771e0749165.tar.gz |
Replace deprecated imp module
The imp module is deprecated since Python 3.4[1] in favor of the new
importlib module. This change replaces usage of that deprecated module.
[1] https://docs.python.org/3/library/imp.html
NOTES:
- This change simplifies the logic, assuming the DJANGO_SETTINGS_MODULE
environment should be a module name. (The previous implementation
eventually raises an exception if the name is not a module name but
anything else like a class name.)
- The imp.find_module method raises ImportError when the module is not
found. This means the previous implementation never returns
sys.path[0]. If the module is found the value is replaced and if it
is not found then the method doesn't return any value but raises
an exception.
Change-Id: I798f345e729ae974917872ba1f2e43205a660c45
Diffstat (limited to 'openstack_dashboard/management')
-rw-r--r-- | openstack_dashboard/management/commands/migrate_settings.py | 13 |
1 files changed, 3 insertions, 10 deletions
diff --git a/openstack_dashboard/management/commands/migrate_settings.py b/openstack_dashboard/management/commands/migrate_settings.py index b3ee87e9f..bae688154 100644 --- a/openstack_dashboard/management/commands/migrate_settings.py +++ b/openstack_dashboard/management/commands/migrate_settings.py @@ -11,7 +11,7 @@ # under the License. import difflib -import imp +import importlib import os import shlex import subprocess @@ -30,16 +30,9 @@ def get_module_path(module_name): """Gets the module path without importing anything. Avoids conflicts with package dependencies. - (taken from http://github.com/sitkatech/pypatch) """ - path = sys.path - for name in module_name.split('.'): - file_pointer, path, desc = imp.find_module(name, path) - path = [path, ] - if file_pointer is not None: - file_pointer.close() - - return path[0] + spec = importlib.util.find_spec(module_name) + return spec.origin class DirContext(object): |