Make our virtualenv source py3 safe

execfile() has gone in python3, and if you google various
stackoverflow results, python-dev mailing list threads and other
projects it seems runpy is considered one of the better solutions.
This should be py2.7 safe too.

Change-Id: I18077ba9d603752492cc81f260e12710981f4dff
This commit is contained in:
Ian Wienand 2017-03-13 15:57:00 +11:00
parent b04c58eca4
commit 85985cdadc

View File

@ -14,6 +14,7 @@
import os import os
import os.path import os.path
import runpy
import sys import sys
import diskimage_builder.paths import diskimage_builder.paths
@ -32,7 +33,9 @@ def running_under_virtualenv():
def activate_venv(): def activate_venv():
if running_under_virtualenv(): if running_under_virtualenv():
activate_this = os.path.join(sys.prefix, "bin", "activate_this.py") activate_this = os.path.join(sys.prefix, "bin", "activate_this.py")
execfile(activate_this, dict(__file__=activate_this)) globs = runpy.run_path(activate_this, globals())
globals().update(globs)
del globs
def main(): def main():