示例#1
0
def noexc_main(argv=None):
    def _print_debug():
        if BENTOMAKER_DEBUG:
            tb = sys.exc_info()[2]
            traceback.print_tb(tb)
    def _print_error(msg):
        pprint('RED', msg)
        pprint('RED', "(You can see the traceback by setting the " \
                      "BENTOMAKER_DEBUG=1 environment variable)")

    try:
        ret = main(argv)
    except UsageException:
        _print_debug()
        e = extract_exception()
        _print_error(str(e))
        sys.exit(1)
    except ParseError:
        _print_debug()
        e = extract_exception()
        _print_error(str(e))
        sys.exit(2)
    except ConvertionError:
        _print_debug()
        e = extract_exception()
        _print_error("".join(e.args))
        sys.exit(3)
    except CommandExecutionFailure:
        _print_debug()
        e = extract_exception()
        _print_error("".join(e.args))
        sys.exit(4)
    except bento.core.errors.ConfigurationError:
        _print_debug()
        e = extract_exception()
        _print_error(e)
        sys.exit(8)
    except bento.core.errors.BuildError:
        _print_debug()
        e = extract_exception()
        _print_error(e)
        sys.exit(16)
    except bento.core.errors.InvalidPackage:
        _print_debug()
        e = extract_exception()
        _print_error(e)
        sys.exit(32)
    except Exception:
        msg = """\
%s: Error: %s crashed (uncaught exception %s: %s).
Please report this on bento issue tracker:
    http://github.com/cournape/bento/issues"""
        if not BENTOMAKER_DEBUG:
            msg += "\nYou can get a full traceback by setting BENTOMAKER_DEBUG=1"
        else:
            _print_debug()
        e = extract_exception()
        pprint('RED',  msg % (SCRIPT_NAME, SCRIPT_NAME, e.__class__, str(e)))
        sys.exit(1)
    sys.exit(ret)
示例#2
0
def main(argv=None):
    if hasattr(os, "getuid"):
        if os.getuid() == 0:
            pprint("RED", "Using bentomaker under root/sudo is *strongly* discouraged - do you want to continue ? y/N")
            ans = raw_input()
            if not ans.lower() in ["y", "yes"]:
                raise UsageException("bentomaker execution canceld (not using bentomaker with admin privileges)")

    if argv is None:
        argv = sys.argv[1:]
    popts = parse_global_options(argv)
    cmd_name = popts["cmd_name"]

    # FIXME: top_node vs srcnode
    source_root = os.path.join(os.getcwd(), os.path.dirname(popts["bento_info"]))
    build_root = os.path.join(os.getcwd(), popts["build_directory"])

    # FIXME: create_root_with_source_tree should return source node and build
    # node so that we don't have to find them and take the risk of
    # inconsistency
    root = bento.core.node.create_root_with_source_tree(source_root, build_root)
    run_node = root.find_node(os.getcwd())
    top_node = root.find_node(source_root)
    build_node = root.find_node(build_root)
    if run_node != top_node and run_node.is_src():
        raise UsageException("You cannot execute bentomaker in a subdirectory of the source tree !")
    if run_node != build_node and run_node.is_bld():
        raise UsageException("You cannot execute bentomaker in a subdirectory of the build tree !")

    if cmd_name and cmd_name not in ["convert"] or not cmd_name:
        return _wrapped_main(popts, run_node, top_node, build_node)
    else:
        register_stuff()
        return _main(popts, run_node, top_node, build_node)
示例#3
0
文件: build_egg.py 项目: dagss/Bento
def build_egg(ipkg, source_root=".", path=None):
    meta = PackageMetadata.from_ipkg(ipkg)
    egg_info = EggInfo.from_ipkg(ipkg)

    # FIXME: fix egg name
    if path is None:
        egg = egg_filename(os.path.join("dist", meta.fullname))
    else:
        egg = egg_filename(os.path.join(path, meta.fullname))
    ensure_dir(egg)

    egg_info = EggInfo.from_ipkg(ipkg)

    zid = compat.ZipFile(egg, "w", compat.ZIP_DEFLATED)
    try:
        for filename, cnt in egg_info.iter_meta():
            zid.writestr(os.path.join("EGG-INFO", filename), cnt)

        ipkg.path_variables["sitedir"] = "."
        file_sections = ipkg.resolve_paths(source_root)
        for kind, source, target in iter_files(file_sections):
            if not kind in ["executables"]:
                zid.write(source, target)

        pprint("PINK", "Byte-compiling ...")
        for kind, source, target in iter_files(file_sections):
            if kind in ["pythonfiles"]:
                zid.writestr("%sc" % target, bcompile(source))
    finally:
        zid.close()

    return
示例#4
0
def install_inplace(pkg):
    """Install scripts of pkg in the current directory."""
    for basename, executable in pkg.executables.items():
        version_str = ".".join([str(i) for i in sys.version_info[:2]])
        scripts_node = root._ctx.srcnode
        for name in [basename, "%s-%s" % (basename, version_str)]:
            nodes = _create_executable(name, executable, scripts_node)
            installed = ",".join([n.path_from(scripts_node) for n in nodes])
            pprint("GREEN", "installing %s in current directory" % installed)
示例#5
0
文件: bootstrap.py 项目: dagss/Bento
def install_inplace(pkg):
    """Install scripts of pkg in the current directory."""
    for name, executable in pkg.executables.items():
        if sys.platform == "win32":
            section = create_win32_script(name, executable, ".")
        else:
            section = create_posix_script(name, executable, ".")
            for f in section.files:
                os.chmod(f, 0755)
        installed = ",".join(section.files)
        pprint("GREEN", "installing %s in current directory" % installed)
示例#6
0
def noexc_main(argv=None):
    def _print_debug():
        if BENTOMAKER_DEBUG:
            tb = sys.exc_info()[2]
            traceback.print_tb(tb)
    try:
        ret = main(argv)
    except UsageException, e:
        _print_debug()
        pprint('RED', e)
        sys.exit(1)
示例#7
0
文件: install.py 项目: dagss/Bento
def unix_installer(source, target, kind):
    if kind in ["executables"]:
        mode = "755"
    else:
        mode = "644"
    cmd = ["install", "-m", mode, source, target]
    strcmd = "INSTALL %s -> %s" % (source, target)
    pprint('GREEN', strcmd)
    if not os.path.exists(os.path.dirname(target)):
        os.makedirs(os.path.dirname(target))
    subprocess.check_call(cmd)
示例#8
0
def whole_test(setup_py, verbose, log):
    if verbose:
        show_output = True
    else:
        show_output = False

    if not test_can_run(setup_py, show_output, log):
        pass
    pprint("YELLOW", "----------------- Testing distutils ------------------")
    use_distutils = test_distutils(setup_py, show_output, log)
    pprint("YELLOW", "----------------- Testing setuptools -----------------")
    use_setuptools = test_setuptools(setup_py, show_output, log)
    pprint("YELLOW", "------------ Testing numpy.distutils -----------------")
    use_numpy = test_numpy(setup_py, show_output, log)
    pprint("YELLOW", "--- Testing numpy.distutils patched by setuptools ----")
    use_setuptools_numpy = test_setuptools_numpy(setup_py, show_output, log)
    if verbose:
        print("Is distutils ? %d" % use_distutils)
        print("Is setuptools ? %d" % use_setuptools)
        print("Is numpy distutils ? %d" % use_numpy)
        print("Is setuptools numpy ? %d" % use_setuptools_numpy)

    if use_distutils and not (use_setuptools or use_numpy or use_setuptools_numpy):
        return "distutils converter"
    elif use_setuptools and not (use_numpy or use_setuptools_numpy):
        return "setuptools converter"
    elif use_numpy and not use_setuptools_numpy:
        return "numpy.distutils converter"
    elif use_setuptools_numpy:
        return "setuptools + numpy.distutils converter"
    else:
        return "Unsupported converter"
示例#9
0
文件: bentomaker.py 项目: dagss/Bento
def main(argv=None):
    if os.getuid() == 0:
        pprint("RED", "Using bentomaker under root/sudo is *strongly* discouraged - do you want to continue ? y/N")
        ans = raw_input()
        if not ans.lower() in ["y", "yes"]:
            raise UsageException("bentomaker execution canceld (not using bentomaker with admin privileges)")
    if argv is None:
        argv = sys.argv[1:]
    popts = parse_global_options(argv)
    cmd_name = popts["cmd_name"]
    if cmd_name and cmd_name not in ["convert"]:
        _wrapped_main(popts)
    else:
        _main(popts)
示例#10
0
    def run(self, ctx):
        opts = ctx.cmd_opts
        o, a = self.parser.parse_args(opts)
        if o.help:
            self.parser.print_help()
            return

        pprint("PINK",
               "=================================================================")
        pprint("PINK",
               "Detecting used distutils extension(s) ... (This may take a while)")
        type = whole_test(o.setup_file, o.verbose)
        pprint("PINK", "Done !")
        pprint("PINK",
               "=================================================================")
        pprint("GREEN", "Detected type: %s" % type)
示例#11
0
    def run(self, ctx):
        argv = ctx.get_command_arguments()
        p = ctx.options_context.parser
        o, a = p.parse_args(argv)
        if o.help:
            p.print_help()
            return

        log = StringIO.StringIO()
        pprint("PINK",
               "=================================================================")
        pprint("PINK",
               "Detecting used distutils extension(s) ... (This may take a while)")
        type = whole_test(o.setup_file, o.verbose, log)
        pprint("PINK", "Done !")
        pprint("PINK",
               "=================================================================")
        pprint("GREEN", "Detected type: %s" % type)
示例#12
0
def build_egg(ipkg, ctx, source_root, path=None):
    meta = PackageMetadata.from_ipkg(ipkg)
    egg_info = EggInfo.from_ipkg(ipkg, ctx.build_node)

    # FIXME: fix egg name
    if path is None:
        egg = egg_filename(os.path.join("dist", meta.fullname))
    else:
        egg = egg_filename(os.path.join(path, meta.fullname))
    ensure_dir(egg)

    zid = compat.ZipFile(egg, "w", compat.ZIP_DEFLATED)
    try:
        ipkg.update_paths({"prefix": source_root.abspath(),
                           "eprefix": source_root.abspath(),
                           "sitedir": source_root.abspath()})
        for filename, cnt in egg_info.iter_meta(ctx.build_node):
            zid.writestr(os.path.join("EGG-INFO", filename), cnt)

        file_sections = ipkg.resolve_paths(source_root)
        for kind, source, target in iter_files(file_sections):
            if not kind in ["executables"]:
                zid.write(source.abspath(), target.path_from(source_root))

        pprint("PINK", "Byte-compiling ...")
        for kind, source, target in iter_files(file_sections):
            if kind in ["pythonfiles"]:
                try:
                    bytecode = bcompile(source.abspath())
                except PyCompileError:
                    e = extract_exception()
                    warnings.warn("Error byte-compiling %r" % source.abspath())
                else:
                    zid.writestr("%sc" % target.path_from(source_root), bcompile(source.abspath()))
    finally:
        zid.close()

    return
示例#13
0
            if sys.version_info[0] < 3:
                bentomaker_script = _BENTOMAKER_SCRIPT
            else:
                bentomaker_script = [sys.executable, "-m", "bentomakerlib.bentomaker"]

            pprint('PINK', "\t-> Configuring from sdist...")
            _call(bentomaker_script + ["configure", "--prefix=%s" % os.path.abspath("tmp")])

            pprint('PINK', "\t-> Building from sdist...")
            _call(bentomaker_script + ["build", "-i"])

            pprint('PINK', "\t-> Building egg from sdist...")
            _call(bentomaker_script + ["build_egg"])

            if sys.platform == "win32":
                pprint('PINK', "\t-> Building wininst from sdist...")
                _call(bentomaker_script + ["build_wininst"])

            if "test" in COMMANDS_REGISTRY.get_command_names():
                pprint('PINK', "\t-> Testing from sdist...")
                try:
                    _call(bentomaker_script + ["test"])
                except CalledProcessError, e:
                    raise CommandExecutionFailure(
                            "test command failed")
            else:
                pprint('YELLOW', "\t-> No test command defined, no testing")
        finally:
            os.chdir(saved)
示例#14
0
文件: convert.py 项目: pberkes/Bento
 def print_delim(string):
     if show_output:
         pprint("YELLOW", string)
示例#15
0
文件: convert.py 项目: pberkes/Bento
def analyse_setup_py(filename, setup_args):
    pprint('PINK', "======================================================")
    pprint('PINK', " Analysing %s (running %s) .... " % (filename, filename))

    # exec_globals contains the globals used to execute the setup.py
    exec_globals = {}
    exec_globals.update(globals())
    # Some setup.py files call setup from their main, so execute them as if
    # they were the main script
    exec_globals["__name__"] = "__main__"
    exec_globals["__file__"] = os.path.abspath(filename)

    _saved_argv = sys.argv[:]
    _saved_sys_path = sys.path
    try:
        try:
            sys.argv = [filename] + setup_args + ["build_py"]
            # XXX: many packages import themselves to get version at build
            # time, and setuptools screw this up by inserting stuff first. Is
            # there a better way ?
            sys.path.insert(0, os.path.dirname(filename))
            execfile(filename, exec_globals)
            if type == "distutils" and "setuptools" in sys.modules:
                pprint("YELLOW", "Setuptools detected in distutils mode !!!")
        except Exception:
            e = extract_exception()
            pprint('RED', "Got exception: %s" % e)
            raise e
    finally:
        sys.argv = _saved_argv
        sys.path = _saved_sys_path

    if not "dist" in LIVE_OBJECTS:
        raise ValueError("setup monkey-patching failed")
    dist = LIVE_OBJECTS["dist"]

    pprint('PINK', " %s analyse done " % filename)
    pprint('PINK', "======================================================")

    return dist
示例#16
0
文件: convert.py 项目: pberkes/Bento
    def run(self, ctx):
        argv = ctx.get_command_arguments()
        p = ctx.options_context.parser
        o, a = p.parse_args(argv)
        if o.help:
            p.print_help()
            return
        if len(a) < 1:
            filename = "setup.py"
        else:
            filename = a[0]
        if not os.path.exists(filename):
            raise ValueError("file %s not found" % filename)

        output = o.output_filename
        if os.path.exists(output):
            raise UsageException("file %s exists, not overwritten" % output)

        if o.verbose:
            show_output = True
        else:
            show_output = False

        if o.setup_args:
            setup_args = comma_list_split(o.setup_args)
        else:
            setup_args = ["-q", "-n"]

        tp = o.type

        convert_log = "convert.log"
        log = open(convert_log, "w")
        try:
            try:
                if tp == "automatic":
                    try:
                        pprint("PINK",
                               "Catching monkey (this may take a while) ...")
                        tp = detect_monkeys(filename, show_output, log)
                        pprint("PINK", "Detected mode: %s" % tp)
                    except ValueError:
                        e = extract_exception()
                        raise UsageException("Error while detecting setup.py type " \
                                             "(original error: %s)" % str(e))

                monkey_patch(tp, filename)
                # analyse_setup_py put results in LIVE_OBJECTS
                dist = analyse_setup_py(filename, setup_args)
                pkg, options = build_pkg(dist, LIVE_OBJECTS, ctx.top_node)

                out = static_representation(pkg, options)
                if output == '-':
                    for line in out.splitlines():
                        pprint("YELLOW", line)
                else:
                    fid = open(output, "w")
                    try:
                        fid.write(out)
                    finally:
                        fid.close()
            except ConvertionError:
                raise
            except Exception:
                e = extract_exception()
                log.write("Error while converting - traceback:\n")
                tb = sys.exc_info()[2]
                traceback.print_tb(tb, file=log)
                msg = "Error while converting %s - you may look at %s for " \
                      "details (Original exception: %s %s)" 
                raise ConvertionError(msg % (filename, convert_log, type(e), str(e)))
        finally:
            log.flush()
            log.close()
示例#17
0
        ctx.shutdown()

def noexc_main(argv=None):
    def _print_debug():
        if BENTOMAKER_DEBUG:
            tb = sys.exc_info()[2]
            traceback.print_tb(tb)
    try:
        ret = main(argv)
    except UsageException, e:
        _print_debug()
        pprint('RED', e)
        sys.exit(1)
    except ParseError, e:
        _print_debug()
        pprint('RED', str(e))
        sys.exit(2)
    except ConvertionError, e:
        _print_debug()
        pprint('RED', "".join(e.args))
        sys.exit(3)
    except CommandExecutionFailure, e:
        _print_debug()
        pprint('RED', "".join(e.args))
        sys.exit(4)
    except bento.core.errors.ConfigurationError, e:
        _print_debug()
        pprint('RED', e)
        sys.exit(8)
    except bento.core.errors.BuildError, e:
        _print_debug()
示例#18
0
 def _print_error(msg):
     pprint('RED', msg)
     pprint('RED', "(You can see the traceback by setting the " \
                   "BENTOMAKER_DEBUG=1 environment variable)")
示例#19
0
文件: distcheck.py 项目: dagss/Bento
    def run(self, ctx):
        pprint('BLUE', "Distcheck...")
        bentomaker_script = os.path.abspath(sys.argv[0])
        if sys.platform == "win32":
            bentomaker_script = [sys.executable, bentomaker_script]
        else:
            bentomaker_script = [bentomaker_script]

        pprint('PINK', "\t-> Running sdist...")
        sdist = get_command("sdist")()
        sdist.run(ctx)
        tarname = sdist.tarname
        tardir = sdist.topdir

        saved = os.getcwd()
        if os.path.exists(DISTCHECK_DIR):
            shutil.rmtree(DISTCHECK_DIR)
        os.makedirs(DISTCHECK_DIR)
        target = os.path.join(DISTCHECK_DIR,
                              os.path.basename(tarname))
        rename(tarname, target)
        tarname = os.path.basename(target)

        os.chdir(DISTCHECK_DIR)
        try:
            pprint('PINK', "\t-> Extracting sdist...")
            tarball = tarfile.TarFile.gzopen(tarname)
            tarball.extractall()
            os.chdir(tardir)

            pprint('PINK', "\t-> Configuring from sdist...")
            check_call(bentomaker_script + ["configure", "--prefix=%s" % os.path.abspath("tmp")])

            pprint('PINK', "\t-> Building from sdist...")
            check_call(bentomaker_script + ["build", "-i"])

            pprint('PINK', "\t-> Building egg from sdist...")
            check_call(bentomaker_script + ["build_egg"])

            if sys.platform == "win32":
                pprint('PINK', "\t-> Building wininst from sdist...")
                check_call(bentomaker_script + ["build_wininst"])

            if "test" in get_command_names():
                pprint('PINK', "\t-> Testing from sdist...")
                try:
                    check_call(bentomaker_script + ["test"])
                except CalledProcessError, e:
                    raise CommandExecutionFailure(
                            "test command failed")
            else:
示例#20
0
    def run(self, ctx):
        pprint('BLUE', "Distcheck...")
        pprint('PINK', "\t-> Running sdist...")

        sdist = run_sdist(ctx)
        tarname = sdist.tarname
        tardir = sdist.topdir

        saved = os.getcwd()

        distcheck_dir = ctx.build_node.make_node(DISTCHECK_DIR)
        if os.path.exists(distcheck_dir.abspath()):
            shutil.rmtree(distcheck_dir.abspath())
        distcheck_dir.mkdir()
        target = distcheck_dir.make_node(os.path.basename(tarname))
        rename(tarname, target.abspath())
        tarname = os.path.basename(target.abspath())

        os.chdir(distcheck_dir.abspath())
        try:
            pprint('PINK', "\t-> Extracting sdist...")
            tarball = TarFile.gzopen(tarname)
            tarball.extractall()
            os.chdir(tardir)

            def _call(cmd):
                p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
                stdout, stderr = p.communicate()
                stdout = stdout.strip()
                stderr = stderr.strip()
                if stdout:
                    print stdout.decode()
                if stderr:
                    print stderr.decode()
                if p.returncode != 0:
                    raise CalledProcessError(p.returncode, cmd)

            if sys.version_info[0] < 3:
                bentomaker_script = _BENTOMAKER_SCRIPT
            else:
                bentomaker_script = [sys.executable, "-m", "bentomakerlib.bentomaker"]

            pprint('PINK', "\t-> Configuring from sdist...")
            _call(bentomaker_script + ["configure", "--prefix=%s" % os.path.abspath("tmp")])

            pprint('PINK', "\t-> Building from sdist...")
            _call(bentomaker_script + ["build", "-i"])

            pprint('PINK', "\t-> Building egg from sdist...")
            _call(bentomaker_script + ["build_egg"])

            if sys.platform == "win32":
                pprint('PINK', "\t-> Building wininst from sdist...")
                _call(bentomaker_script + ["build_wininst"])

            if "test" in COMMANDS_REGISTRY.get_command_names():
                pprint('PINK', "\t-> Testing from sdist...")
                try:
                    _call(bentomaker_script + ["test"])
                except CalledProcessError, e:
                    raise CommandExecutionFailure(
                            "test command failed")
            else: