-
-
Notifications
You must be signed in to change notification settings - Fork 144
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Replace deprecated imp module with importlib #358
Comments
31 tasks
Ping. This is now blocking Python 3.12 support. |
I'm going to give it a shot. |
Ok, I give up. This is the closest I've been able to come up with: diff --git a/configurations/importer.py b/configurations/importer.py
index e3573f4..00e7728 100644
--- a/configurations/importer.py
+++ b/configurations/importer.py
@@ -1,4 +1,6 @@
import imp
+from importlib.machinery import PathFinder
+import importlib.util
import logging
import os
import sys
@@ -126,25 +128,31 @@ class ConfigurationImporter:
self.name))
self.logger.debug(stylize(message))
- def find_module(self, fullname, path=None):
+ def find_spec(self, fullname, path=None, target=None):
if fullname is not None and fullname == self.module:
module = fullname.rsplit('.', 1)[-1]
- return ConfigurationLoader(self.name,
- imp.find_module(module, path))
+ spec = PathFinder.find_spec(module, path, target)
+ assert spec is not None
+ return importlib.machinery.ModuleSpec(
+ spec.name,
+ ConfigurationLoader(self.name, spec),
+ origin=spec.origin)
return None
class ConfigurationLoader:
- def __init__(self, name, location):
+ def __init__(self, name, spec):
self.name = name
- self.location = location
+ self.spec = spec
def load_module(self, fullname):
if fullname in sys.modules:
mod = sys.modules[fullname] # pragma: no cover
else:
- mod = imp.load_module(fullname, *self.location)
+ mod = importlib.util.module_from_spec(self.spec)
+ sys.modules[fullname] = mod
+ self.spec.loader.exec_module(mod)
cls_path = '{0}.{1}'.format(mod.__name__, self.name)
try: However, it fails a bunch of test cases:
|
gump
added a commit
to octoenergy/django-configurations
that referenced
this issue
Sep 8, 2023
This project uses the imp module which has been deprecated since Python 3.4 and set for removal in 3.12: • Raised PendingDeprecationWarning since 3.4 (2014) • Raised DeprecationWarning since 3.5 (2015) • Updated DeprecationWarning to say removal in 3.12 since 3.10 (2021) • Removal planned for 3.12 (2023) This change removes the dependency on imp in favour of importlib. Co-authored-by: @jbkkd Inspired by: @mgorny jazzband#358
gump
added a commit
to octoenergy/django-configurations
that referenced
this issue
Sep 8, 2023
This project uses the imp module which has been deprecated since Python 3.4 and set for removal in 3.12: • Raised PendingDeprecationWarning since 3.4 (2014) • Raised DeprecationWarning since 3.5 (2015) • Updated DeprecationWarning to say removal in 3.12 since 3.10 (2021) • Removal planned for 3.12 (2023) This change removes the dependency on imp in favour of importlib. Co-authored-by: @jbkkd Inspired by: @mgorny jazzband#358
jbkkd
pushed a commit
that referenced
this issue
Sep 27, 2023
This project uses the imp module which has been deprecated since Python 3.4 and set for removal in 3.12: • Raised PendingDeprecationWarning since 3.4 (2014) • Raised DeprecationWarning since 3.5 (2015) • Updated DeprecationWarning to say removal in 3.12 since 3.10 (2021) • Removal planned for 3.12 (2023) This change removes the dependency on imp in favour of importlib. Co-authored-by: @jbkkd Inspired by: @mgorny #358
This has been resolved in #365 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This project uses the
imp
module which has been deprecated since Python 3.4 and set for removal in 3.12:PendingDeprecationWarning
since 3.4 (2014)DeprecationWarning
since 3.5 (2015)DeprecationWarning
to say removal in 3.12 since 3.10 (2021)Python 3.12 is set for release on 2023-10-02 and this library is one of the top 5,000 most-downloaded from PyPI.
Please could you upgrade to use
importlib
? Theimp
docs have suggestions on what to use to replace each function and constant.The text was updated successfully, but these errors were encountered: