# Path: pyxc/util.py
# def usingPython3():
#     return sys.version_info[0] == 3
# 
# def parentOf(path):
#     return '/'.join(path.rstrip('/').split('/')[:-1])
# 
# Path: pyxc/pyxc_exceptions.py
# class PyxcError(Exception): pass
# class NoTransformationForNode(PyxcError): pass


import subprocess, os, json
        import pj.api_internal
from pyxc.util import usingPython3, parentOf
from pyxc import pyxc_exceptions
        args.append('--create-source-map')
    
    return _runViaSubprocessIfNeeded(
                    # name, args, kwargs &mdash; if we're running Python 3
                    'buildBundle',
                    [mainModule],
                    kwargs,
                    # input, args &mdash; for the Python 3 subprocess
                    None,
                    args,
                    parseJson=True)


def _runViaSubprocessIfNeeded(name, args, kwargs, input, subprocessArgs, parseJson=False):
    
    if usingPython3():
        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',

# Path: pyxc/util.py
# def usingPython3():
#     return sys.version_info[0] == 3
# 
# def parentOf(path):
#     return '/'.join(path.rstrip('/').split('/')[:-1])
# 
# Path: pyxc/pyxc_exceptions.py
# class PyxcError(Exception): pass
# class NoTransformationForNode(PyxcError): pass


# Path: pj/api.py
import subprocess, os, json
        import pj.api_internal
from pyxc.util import usingPython3, parentOf
from pyxc import pyxc_exceptions

        args.append('--create-source-map')
    
    return _runViaSubprocessIfNeeded(
                    # name, args, kwargs &mdash; if we're running Python 3
                    'buildBundle',
                    [mainModule],
                    kwargs,
                    # input, args &mdash; for the Python 3 subprocess
                    None,
                    args,
                    parseJson=True)


def _runViaSubprocessIfNeeded(name, args, kwargs, input, subprocessArgs, parseJson=False):
    
    if usingPython3():
        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',