launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #27187
[Merge] ~cjwatson/launchpad:fix-py3-execfile into launchpad:master
Colin Watson has proposed merging ~cjwatson/launchpad:fix-py3-execfile into launchpad:master.
Commit message:
lp.scripts.harness: Fix exec() for Python 3
Requested reviews:
Launchpad code reviewers (launchpad-reviewers)
For more details, see:
https://code.launchpad.net/~cjwatson/launchpad/+git/launchpad/+merge/403804
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.
--
Your team Launchpad code reviewers is requested to review the proposed merge of ~cjwatson/launchpad:fix-py3-execfile into launchpad:master.
diff --git a/lib/lp/scripts/harness.py b/lib/lp/scripts/harness.py
index ab3a5c7..12f5b8d 100644
--- a/lib/lp/scripts/harness.py
+++ b/lib/lp/scripts/harness.py
@@ -63,7 +63,7 @@ def _get_locals():
startup = os.environ.get('PYTHONSTARTUP')
if startup:
with open(startup) as f:
- exec(f.read())
+ exec(f.read(), globals())
store = IMasterStore(Person)
if dbuser == 'launchpad':
Follow ups