Merge ~cjwatson/launchpad:fix-py3-execfile into launchpad:master

Proposed by Colin Watson
Status: Merged
Approved by: Colin Watson
Approved revision: 8cea96837cd6ceac0c171f5e5b615f54d14d199d
Merge reported by: Otto Co-Pilot
Merged at revision: not available
Proposed branch: ~cjwatson/launchpad:fix-py3-execfile
Merge into: launchpad:master
Diff against target: 13 lines (+1/-1)
1 file modified
lib/lp/scripts/harness.py (+1/-1)
Reviewer Review Type Date Requested Status
Ioana Lasc (community) Approve
Review via email: mp+403804@code.launchpad.net

Commit message

lp.scripts.harness: Fix exec() for Python 2

Description of the change

https://code.launchpad.net/~cjwatson/launchpad/+git/launchpad/+merge/402638 switched `lp.scripts.harness` from `execfile()` to `exec()`, but there's a subtlety on Python 2 due to the use of a nested function here. As a result, `bin/harness` failed as follows on Python 2:

    Traceback (most recent call last):
      File "bin/harness", line 5, in <module>
        import lp.scripts.harness
      File ".../lib/lp/scripts/harness.py", line 66
        exec(f.read())
    SyntaxError: unqualified exec is not allowed in function '_get_locals' because it contains a nested function with free variables

Explicitly passing `globals()` avoids this.

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/lib/lp/scripts/harness.py b/lib/lp/scripts/harness.py
2index ab3a5c7..12f5b8d 100644
3--- a/lib/lp/scripts/harness.py
4+++ b/lib/lp/scripts/harness.py
5@@ -63,7 +63,7 @@ def _get_locals():
6 startup = os.environ.get('PYTHONSTARTUP')
7 if startup:
8 with open(startup) as f:
9- exec(f.read())
10+ exec(f.read(), globals())
11 store = IMasterStore(Person)
12
13 if dbuser == 'launchpad':

Subscribers

People subscribed via source and target branches

to status/vote changes: