-
Notifications
You must be signed in to change notification settings - Fork 371
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 module imp with importlib #1738
Conversation
Merge pull request #1492 from Azure/release-2.2.37
Merge pull request #1493 from Azure/release-2.2.38
* Use 1804-style deprovisioning for all versions >= 18.04 (#1483) 18.04 changed the method of managing resolv.conf vs. 16.04; the new method involves letting systemd-networkd manage that file. A previous fix corrected waagent behavior for 18.04 but did not do so for subsequent releases. Now that Ubuntu's direction is clear, this commit makes the correction in all versions of Ubuntu from 18.04 onwards. Other distros are unaffected by this bug and by this fix. * Updating Travis settings * Added description for Extension Error Codes (#1482) * Added description for Extension Error Codes * Correcting the test - to send the correct CRP Extension Error code * Adding docstring to describe ExtensionErrorCodes * Make launch_command resilient to cgroups failures (#1484) * WireServer Certificates parser gracefully exits if format of package is not Pkcs7BlobWithPfxContents (#1474) * Certificates parser gracefully exits if format of package is not Pkcs7BlobWithPfxContents * Add missing files * change message to warning * Removing the requirement of passing cipher-name. Default is more secure (#1481) * Fix PID tracking for cgroups (#1489) * add fixes for cgroup setup and PID tracking * cleanup code comments * disable cgroups test if not supported by environment * remove wrapper cgroup tracking and other nits * fix whitespace * nit fixes; addressing CR comments * Release 2.2.39 (#1494) * Fix header * Update agent version to 2.2.40
Merging release 2.2.41 into master
…ning ext handler only if allowed
Poll for artifact blob
Updated version to 2.2.42, added new zip and removed old zips
Merging Hotfix 2.2.42 into master
Merging Release 2.2.44 into Master
Merge release 2.2.45 into master
Codecov Report
@@ Coverage Diff @@
## develop #1738 +/- ##
===========================================
+ Coverage 69.12% 69.45% +0.33%
===========================================
Files 82 82
Lines 11511 11469 -42
Branches 1619 1619
===========================================
+ Hits 7957 7966 +9
+ Misses 3217 3166 -51
Partials 337 337
Continue to review full report at Codecov.
|
if sys.version_info[0] == 2: | ||
import imp | ||
else: | ||
import importlib |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does importlib do anything or potentially going to do anything here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
importlib
is the preferred module since imp
is deprecated. We define it here, the same way like imp
was defined here so far. Does that answer your question?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, i understand that imp is deprecated for python3, and importlib is the succeeder. But i don't see any usage of importlib in this file, and the code snippet where was using 'imp' is never supposed to be executed with python3, so i think it would be the same if we just remove the else part. Please correct me if i'm wrong, thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rainer37 I see your point now. You are right, since we have:
if sys.version_info[0] == 3:
raise ImportError("waagent2.0 doesn't support python3")
imp
would never be executed with python3.
However, the imports will always be evaluated, which means that today, in an image that runs the agent with Python3, we would see this:
root@ubuntu2004:~# waagent --version
/usr/sbin/waagent:27: DeprecationWarning: the imp module is deprecated in favour of importlib; see the module's documentation for alternative uses
import imp
WALinuxAgent-2.2.46 running on ubuntu 20.04
Python: 3.8.2
Goal state agent: 2.2.46
The purpose of this change is to get rid of this warning.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pgombar thanks for the info! but sorry i think
if sys.version_info[0] == 2:
import imp
is enough to silence the DeprecationWarning for os with /usr/bin/env python as python3* since python3 wouldn't take this branch, and python3 is not going to do any module load using 'importlib'. S adding
else:
import importlib
does not seem to help in any cases but only import a module that is not used. Any further explanation would be much appreciated, thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking only at this file's contents, you are right and there is no need for importlib
since it is not called anywhere in this copy of bin/waagent
. However, there are certain implicit dependencies between bin/waagent
and VM extensions. In case the extensions need to load modules from the agent, and are using Python3, we are enabling them to do so with importlib
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@johanburati thanks for your contribution! |
Description
Issue #1473
https://www.python-future.org/_modules/imp.html
PR information
Quality of Code and Contribution Guidelines
This change is