def _runViaSubprocessIfNeeded(name, args, kwargs, input, subprocessArgs, parseJson=False): if usingPython3(): import pj.api_internal f = getattr(pj.api_internal, name) return f(*args, **kwargs) else: if isinstance(input, unicode): input = input.encode('utf-8') pythonPath = parentOf(parentOf(os.path.abspath(__file__))) if os.environ.get('PYTHONPATH'): pythonPath += ':' + os.environ.get('PYTHONPATH') subprocessArgs = [ '/usr/bin/env', 'PYTHONPATH=%s' % pythonPath, 'python3.1', parentOf(os.path.abspath(__file__)) + '/pj', ] + subprocessArgs if input is None: p = subprocess.Popen(subprocessArgs, stdout=subprocess.PIPE, stderr=subprocess.PIPE) out, err = p.communicate() else: p = subprocess.Popen(subprocessArgs, stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE) out, err = p.communicate(input=input) if p.returncode == 0: result = unicode(out, 'utf-8') if parseJson: result = json.loads(result) return result else: try: errInfo = json.loads(err) except ValueError: errInfo = { 'name': 'Exception', 'message': unicode(err, 'utf-8'), } if hasattr(pyxc_exceptions, errInfo['name']): exceptionClass = getattr(pyxc_exceptions, errInfo['name']) raise exceptionClass(errInfo['message']) else: raise Exception('%s\n--------\n%s' % (errInfo['name'], errInfo['message']))
def _runViaSubprocessIfNeeded(name, args, kwargs, input, subprocessArgs, parseJson=False): if usingPython3(): import pj.api_internal f = getattr(pj.api_internal, name) return f(*args, **kwargs) else: if isinstance(input, unicode): input = input.encode('utf-8') pythonPath = parentOf(parentOf(os.path.abspath(__file__))) if os.environ.get('PYTHONPATH'): pythonPath += ':' + os.environ.get('PYTHONPATH') subprocessArgs = ['/usr/bin/env', 'PYTHONPATH=%s' % pythonPath, 'python3.1', parentOf(os.path.abspath(__file__)) + '/pj', ] + subprocessArgs if input is None: p = subprocess.Popen(subprocessArgs, stdout=subprocess.PIPE, stderr=subprocess.PIPE) out, err = p.communicate() else: p = subprocess.Popen(subprocessArgs, stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE) out, err = p.communicate(input=input) if p.returncode == 0: result = unicode(out, 'utf-8') if parseJson: result = json.loads(result) return result else: try: errInfo = json.loads(err) except ValueError: errInfo = { 'name': 'Exception', 'message': unicode(err, 'utf-8'), } if hasattr(pyxc_exceptions, errInfo['name']): exceptionClass = getattr(pyxc_exceptions, errInfo['name']) raise exceptionClass(errInfo['message']) else: raise Exception('%s\n--------\n%s' % (errInfo['name'], errInfo['message']))
#!/usr/bin/env python3.1 import optparse, sys, os, json # Require Python 3 from pyxc.util import usingPython3, writeExceptionJsonAndDie, TempDir, parentOf if not usingPython3(): sys.stderr.write('Python 3 required.') sys.exit(1) import pj.api_internal from pj.nodejs import runViaNode #### Main def main(): parser = optparse.OptionParser() parser.add_option('-p', '--path', dest='path', default=None) parser.add_option('-M', '--create-source-map', dest='createSourceMap', default=False, action='store_true') parser.add_option('-C', '--code-to-code', dest='codeToCode', default=False, action='store_true')
from pyxc.util import usingPython3 assert usingPython3() import sys, os, ast, json, hashlib from pyxc.util import rfilter, parentOf, randomToken from pyxc.pyxc_exceptions import NoTransformationForNode #### TargetNode class TargetNode: def __init__(self, *args): self.args = args def __str__(self): return ''.join( str(x) for x in self.emit(*self.transformedArgs)) #### SourceMap class SourceMap: def __init__(self, fileString, nextMappingId=0): self.fileString = fileString self.nextMappingId = nextMappingId
from pyxc.util import usingPython3 assert usingPython3() import sys, os, ast, json, hashlib from pyxc.util import rfilter, parentOf, randomToken from pyxc.pyxc_exceptions import NoTransformationForNode #### TargetNode class TargetNode: def __init__(self, *args): self.args = args def __str__(self): return ''.join(str(x) for x in self.emit(*self.transformedArgs)) #### SourceMap class SourceMap: def __init__(self, fileString, nextMappingId=0): self.fileString = fileString self.nextMappingId = nextMappingId self.node_mappingId_map = {} self.mappings = []
#!/usr/bin/env python3.1 import optparse, sys, os, json # Require Python 3 from pyxc.util import usingPython3, writeExceptionJsonAndDie, TempDir, parentOf if not usingPython3(): sys.stderr.write('Python 3 required.') sys.exit(1) import pj.api_internal from pj.nodejs import runViaNode #### Main def main(): parser = optparse.OptionParser() parser.add_option('-p', '--path', dest='path', default=None) parser.add_option('-M', '--create-source-map', dest='createSourceMap', default=False, action='store_true') parser.add_option('-C', '--code-to-code', dest='codeToCode', default=False, action='store_true') parser.add_option('-B', '--build-bundle', dest='buildBundle', default=False, action='store_true') parser.add_option('-E', '--run-exception-server', dest='runExceptionServer', default=False, action='store_true') parser.add_option('-U', '--use-exception-server', dest='useExceptionServer', default=None) options, args = parser.parse_args()