Skip to content
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

DeprecationWarning: the imp module is deprecated in favour of importlib #1819

Closed
noelleleigh opened this issue Nov 19, 2020 · 1 comment · Fixed by #1823
Closed

DeprecationWarning: the imp module is deprecated in favour of importlib #1819

noelleleigh opened this issue Nov 19, 2020 · 1 comment · Fixed by #1823
Milestone

Comments

@noelleleigh
Copy link
Contributor

When running a Django project using ddtrace with warnings enabled, this warning is emitted:

Issue

/usr/local/lib/python3.7/dist-packages/ddtrace/bootstrap/sitecustomize.py:7: DeprecationWarning: the imp module is deprecated in favour of importlib; see the module's documentation for alternative uses

Details

The line in question:

How it's used:

# Ensure sitecustomize.py is properly called if available in application directories:
# * exclude `bootstrap_dir` from the search
# * find a user `sitecustomize.py` module
# * import that module via `imp`
bootstrap_dir = os.path.dirname(__file__)
path = list(sys.path)
if bootstrap_dir in path:
path.remove(bootstrap_dir)
try:
(f, path, description) = imp.find_module("sitecustomize", path)
except ImportError:
pass
else:
# `sitecustomize.py` found, load it
log.debug("sitecustomize from user found in: %s", path)
imp.load_module("sitecustomize", f, path, description)

Documentation note for imp.find_module():

Deprecated since version 3.3: Use importlib.util.find_spec() instead unless Python 3.3 compatibility is required, in which case use importlib.find_loader(). For example usage of the former case, see the Examples section of the importlib documentation.

Documentation note for imp.load_module():

Deprecated since version 3.3: If previously used in conjunction with imp.find_module() then consider using importlib.import_module(), otherwise use the loader returned by the replacement you chose for imp.find_module(). If you called imp.load_module() and related functions directly with file path arguments then use a combination of importlib.util.spec_from_file_location() and importlib.util.module_from_spec(). See the Examples section of the importlib documentation for details of the various approaches.

Resolution

I suspect this example could be worth building off of to do the necessary path customization.

@Kyle-Verhoog Kyle-Verhoog added this to the 0.45.0 milestone Nov 19, 2020
@Kyle-Verhoog
Copy link
Member

Thanks for the report @noelleleigh! We'll target upgrading to importlib for version 0.45.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants