Merge ~cjwatson/launchpad:pythonpath-avoid-imp into launchpad:master

Proposed by Colin Watson
Status: Merged
Approved by: Colin Watson
Approved revision: 94161dfb21b02519d6eb06f5ee786b66c8cde2e2
Merge reported by: Otto Co-Pilot
Merged at revision: not available
Proposed branch: ~cjwatson/launchpad:pythonpath-avoid-imp
Merge into: launchpad:master
Diff against target: 22 lines (+2/-2)
1 file modified
_pythonpath.py (+2/-2)
Reviewer Review Type Date Requested Status
Ioana Lasc (community) Approve
Review via email: mp+409948@code.launchpad.net

Commit message

Use importlib rather than imp in _pythonpath

Description of the change

`imp.find_module` is deprecated, and this change means a little less code to import into every Launchpad process.

To post a comment you must log in.
Revision history for this message
Ioana Lasc (ilasc) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/_pythonpath.py b/_pythonpath.py
2index 0e03ee8..a09cb74 100644
3--- a/_pythonpath.py
4+++ b/_pythonpath.py
5@@ -4,7 +4,7 @@
6 # This file works if the Python has been started with -S, or if bin/py
7 # has been used.
8
9-import imp
10+from importlib.util import find_spec
11 import os.path
12 import sys
13
14@@ -15,7 +15,7 @@ if __name__ == '__main__':
15 else:
16 # If this is an imported module, we want the location of the .py
17 # file, not the .pyc, because the .py file may have been symlinked.
18- filename = imp.find_module(__name__)[1]
19+ filename = find_spec(__name__).origin
20 # Get the full, non-symbolic-link directory for this file. This is the
21 # project root.
22 top = os.path.dirname(os.path.abspath(os.path.realpath(filename)))

Subscribers

People subscribed via source and target branches

to status/vote changes: