mirror of
https://github.com/kennethreitz-archive/pyinstaller.git
synced 2026-06-05 15:40:17 +00:00
Extract a helper function to spawn an external interpreter; useful for hooks that need to know informations about packages/modules without importing them from within the main running interpreter.
git-svn-id: http://svn.pyinstaller.org/trunk@588 8dd32b29-ccff-0310-8a9a-9233e24343b1
This commit is contained in:
+3
-11
@@ -20,20 +20,12 @@ hiddenimports = ['xml.sax.xmlreader','xml.sax.expatreader']
|
||||
def hook(mod):
|
||||
# This hook checks for the infamous _xmlcore hack
|
||||
# http://www.amk.ca/diary/2003/03/pythons__xmlplus_hack.html
|
||||
import os, tempfile, sys, string, marshal
|
||||
fnm = tempfile.mktemp()
|
||||
|
||||
exe = sys.executable
|
||||
from hookutils import exec_statement
|
||||
import string, marshal
|
||||
|
||||
# Using "echo on" as a workaround for a bug in NT4 shell
|
||||
if os.name == "nt":
|
||||
cmd = '"echo on && "%s" -c "import xml;print xml.__file__" > "%s""' % (exe, fnm)
|
||||
else:
|
||||
cmd = '"%s" -c "import xml;print xml.__file__" > "%s"' % (exe, fnm)
|
||||
os.system(cmd)
|
||||
txt = exec_statement("import xml;print xml.__file__")
|
||||
|
||||
txt = open(fnm, 'r').read()[:-1]
|
||||
os.remove(fnm)
|
||||
if string.find(txt, '_xmlplus') > -1:
|
||||
if txt[:-3] == ".py":
|
||||
txt = txt + 'c'
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
def exec_statement(stat):
|
||||
"""Executes a Python statement in an externally spawned interpreter, and
|
||||
returns anything that was emitted in the standard output as a single string.
|
||||
"""
|
||||
|
||||
import os, tempfile, sys
|
||||
|
||||
fnm = tempfile.mktemp()
|
||||
exe = sys.executable
|
||||
|
||||
# Using "echo on" as a workaround for a bug in NT4 shell
|
||||
if os.name == "nt":
|
||||
cmd = '"echo on && "%s" -c "%s" > "%s""' % (exe, stat, fnm)
|
||||
else:
|
||||
cmd = '"%s" -c "%s" > "%s"' % (exe, stat, fnm)
|
||||
os.system(cmd)
|
||||
|
||||
txt = open(fnm, 'r').read()[:-1]
|
||||
os.remove(fnm)
|
||||
return txt
|
||||
Reference in New Issue
Block a user