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 #44

Closed
sbraz opened this issue Nov 1, 2022 · 2 comments
Closed
Labels
code quality Improvement of code quality
Milestone

Comments

@sbraz
Copy link
Contributor

sbraz commented Nov 1, 2022

HI,
running tests, I noticed this warning:

cfv/test/cfvtest.py:26: DeprecationWarning: the imp module is deprecated in favour of importlib and slated for removal in Python 3.12; see the module's documentation for alternative uses
    import imp

I didn't file a PR as I'm not exactly sure what

imp.load_source('cfvwrapper', cfvfn, f)
is used for.

@lxp
Copy link
Member

lxp commented Nov 1, 2022

From what I can tell it is used by the old test harness. It can run all tests inside one Python process or spawn a new Python processes for each test.
Whenever cfv needs to be called it uses this wrapper script: https://github.com/cfv-project/cfv/blob/779d30f3aa0c6f4cb77b694823db64a0a89200af/test/cfv
It modifies the sys.path variable, so that it executes the cfv version from the directory instead of running a system-wide installation:

cfv/test/cfv

Line 6 in 779d30f

sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(os.path.realpath(__file__)), os.pardir, 'lib')))

According to the comment above the line you mentioned, imp.load_source is only used to ensue that sys.path is modified:
# This is so that the sys.path modification of the wrapper (if it has one) will be executed..

I am not really sure myself if this is still needed or was only required in older Python versions. At least the comment was added in 2006: 4cf1b20

@lxp lxp added the code quality Improvement of code quality label Nov 8, 2022
sbraz added a commit to sbraz/cfv that referenced this issue May 12, 2024
sbraz added a commit to sbraz/cfv that referenced this issue May 12, 2024
@lxp lxp added this to the 3.1 milestone May 16, 2024
lxp added a commit that referenced this issue May 18, 2024
Fix tests for Python 3.12: remove "imp", fixes #21, #44
@lxp
Copy link
Member

lxp commented May 18, 2024

Fixed by #53

@lxp lxp closed this as completed May 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
code quality Improvement of code quality
Projects
None yet
Development

No branches or pull requests

2 participants