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

Replace module imp with importlib #1738

Merged
merged 29 commits into from
Apr 24, 2020
Merged
Show file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
f696540
Release 2.2.37 into the master
vrdmr Mar 26, 2019
bce7de9
Release 2.2.38 into master
vrdmr Mar 26, 2019
5d3757a
Release 2.2.40 (#1518)
pgombar May 2, 2019
0f1f1cf
Version update for release 2.2.41
vrdmr Jun 15, 2019
94e873f
Merging release 2.2.41 into master
vrdmr Jul 16, 2019
bc4b721
Fixing the LaunchCommandTestCase
vrdmr Jul 16, 2019
a0bb361
Merge pull request #1585 from vrdmr/master
vrdmr Jul 17, 2019
aaea41a
Moved code to check if extension processing allowed to a func and run…
larohra Aug 1, 2019
efabc2b
Added a test case to test extension processing allowed
larohra Aug 1, 2019
168fc03
Added a test to check the status of last etag
larohra Aug 2, 2019
54d393a
Modified tests to be stateless
larohra Aug 2, 2019
e111cbf
Removed dead dependency
larohra Aug 2, 2019
378eb03
Renamed the last_etag to last_processed_etag
larohra Aug 5, 2019
f2674dc
Reverted back to last_etag
larohra Aug 5, 2019
4a5db51
Merge pull request #1602 from larohra/PollForArtifactBlob
larohra Aug 5, 2019
f8a718b
Updated version to 2.2.42, added new zip and removed old zips
Aug 5, 2019
77d4ac1
Merge pull request #1603 from larohra/PollForArtifactBlob
larohra Aug 5, 2019
62b7b01
Merge branch 'develop' into hotfix-2.2.42
larohra Aug 5, 2019
09060e1
Revert "Merge branch 'develop' into hotfix-2.2.42"
Aug 5, 2019
2b5ba48
Merge pull request #1611 from Azure/hotfix-2.2.42
larohra Aug 22, 2019
d41a335
Bringing Master to Current Levels (#1721)
vrdmr Nov 27, 2019
3487f3e
Merge pull request #1722 from Azure/release-2.2.44
vrdmr Nov 27, 2019
dcdc331
Merge pull request #1727 from Azure/release-2.2.45
pgombar Dec 5, 2019
1ffad2b
Replace module imp with importlib
johanburati Dec 18, 2019
c23436e
Merge branch 'develop' into issues/1473
pgombar Apr 23, 2020
dcbc96f
keep imp for py2
pgombar Apr 23, 2020
7527afa
Merge branch 'develop' into issues/1473
pgombar Apr 23, 2020
91d0eee
Merge branch 'develop' into issues/1473
pgombar Apr 24, 2020
8461e54
Merge branch 'develop' into issues/1473
pgombar Apr 24, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion bin/waagent
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,13 @@
#

import os
import imp
import sys

if sys.version_info[0] == 2:
import imp
else:
import importlib

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?

Copy link
Contributor

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?

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!

Copy link
Contributor

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.

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!

Copy link
Contributor

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.


if __name__ == '__main__' :
import azurelinuxagent.agent as agent
"""
Expand Down
6 changes: 5 additions & 1 deletion bin/waagent2.0
Original file line number Diff line number Diff line change
Expand Up @@ -1744,7 +1744,11 @@ bsd_activate_resource_disk_txt="""\

import os
import sys
import imp

if sys.version_info[0] == 2:
import imp
else:
import importlib

# waagent has no '.py' therefore create waagent module import manually.
__name__='setupmain' #prevent waagent.__main__ from executing
Expand Down