コード例 #1
0
    def run(self, ctx):
        cmd_args = ctx.command_argv
        p = ctx.options_context.parser
        o, a = p.parse_args(cmd_args)
        if o.help:
            p.print_help()
            return
        if len(a) < 1:
            print((get_simple_usage(ctx)))
            return

        # Parse the options for help command itself
        cmd_name = None
        help_args = []
        if not cmd_args[0].startswith('-'):
            cmd_name = cmd_args[0]
            cmd_args.pop(0)
        else:
            # eat all the help options
            _args = [cmd_args.pop(0)]
            while not _args[0].startswith('-') and len(cmd_args) > 0:
                _args.append(cmd_args.pop(0))
            help_args = _args
            cmd_name = cmd_args[0]

        if ctx.is_options_context_registered(cmd_name):
            options_context = ctx.retrieve_options_context(cmd_name)
            p = options_context.parser
            p.print_help()
        else:
            raise UsageException("error: command %s not recognized" % cmd_name)
コード例 #2
0
def convert(ctx,
            filename,
            setup_args,
            monkey_patch_mode,
            verbose,
            output,
            log,
            show_output=True):
    if monkey_patch_mode == "automatic":
        try:
            if verbose:
                pprint("PINK", "Catching monkey (this may take a while) ...")
            monkey_patch_mode = detect_monkeys(filename, show_output, log)
            if verbose:
                pprint("PINK", "Detected mode: %s" % monkey_patch_mode)
        except ValueError:
            e = extract_exception()
            raise UsageException("Error while detecting setup.py type " \
                                 "(original error: %s)" % str(e))

    monkey_patch(ctx.top_node, monkey_patch_mode, filename)
    dist, package_objects = analyse_setup_py(filename, setup_args)
    pkg, options = build_pkg(dist, package_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()
コード例 #3
0
    def run(self, ctx):
        argv = ctx.command_argv
        p = ctx.options_context.parser
        o, a = p.parse_args(argv)
        if o.help:
            p.print_help()
            return

        if len(a) < 1:
            filename = "bento.info"
        else:
            filename = a[0]

        if not os.path.exists(filename):
            raise UsageException("%s: error: file %s does not exist" %
                                 "bentomaker")

        f = open(filename, "r")
        try:
            data = f.read()
            try:
                parsed = build_ast_from_data(data)
            except ParseError:
                e = extract_exception()
                msg = "Error while parsing file %s\n" % filename
                e.args = (msg, ) + e.args
                raise e
            if o.flags:
                try:
                    flags = parsed["flags"]
                    for flag in flags:
                        print((flags[flag]))
                except KeyError:
                    pass
            elif o.path:
                try:
                    paths = parsed["paths"]
                    for path in paths:
                        print((paths[path]))
                except KeyError:
                    pass
            elif o.meta_field:
                try:
                    print((parsed[o.meta_field]))
                except KeyError:
                    raise ValueError("Field %s not found in metadata" %
                                     o.meta_field)
            else:
                pprint(parsed)
        finally:
            f.close()
コード例 #4
0
ファイル: configure.py プロジェクト: Python3pkg/Bento
def _get_flag_values(flag_names, options):
    """Return flag values as defined by the options."""
    flag_values = {}
    for option_name in flag_names:
        flag_value = getattr(options, option_name, None)
        if flag_value is not None:
            if flag_value.lower() in ["true", "yes"]:
                flag_values[option_name] = True
            elif flag_value.lower() in ["false", "no"]:
                flag_values[option_name] = False
            else:
                msg = """Option %s expects a true or false argument"""
                raise UsageException(msg % "--%s" % option_name)
    return flag_values
コード例 #5
0
    def run(self, ctx):
        argv = ctx.command_argv
        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 op.exists(filename):
            raise ValueError("file %s not found" % filename)

        output = o.output_filename
        if op.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"]

        monkey_patch_mode = o.type

        convert_log = "convert.log"
        log = open(convert_log, "w")
        try:
            try:
                convert(ctx, filename, setup_args, monkey_patch_mode,
                        o.verbose, output, log, show_output)
            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()
コード例 #6
0
ファイル: configure.py プロジェクト: Python3pkg/Bento
def set_scheme_options(scheme, options, package):
    """Set path variables given in options in scheme dictionary."""
    for k in scheme:
        if hasattr(options, k):
            val = getattr(options, k)
            if val:
                if not os.path.isabs(val):
                    msg = "value given for path option '%s' " \
                          "should be an absolute path (value " \
                          "given was '%s')" % (k, val)
                    raise UsageException(msg)
                scheme[k] = val

    if os.name == "posix":
        set_scheme_unix(scheme, options, package)
    elif os.name == "nt":
        set_scheme_win32(scheme, options, package)
    else:
        raise NotImplementedError("OS %s not supported" % os.name)

    # XXX: define default somewhere and stick with it
    if options.prefix is not None and options.eprefix is None:
        scheme["eprefix"] = scheme["prefix"]
コード例 #7
0
from bento.errors \
    import \
        UsageException
from bento._config \
     import \
        SITEDIR

if "WAFDIR" in os.environ:
    WAFDIR = os.path.join(os.environ["WAFDIR"], "waflib")
else:
    WAFDIR = op.abspath(op.join(op.dirname(bento.__file__), os.pardir, "waflib"))
    if not op.exists(WAFDIR):
        WAFDIR = os.path.join(os.getcwd(), "waflib")
if not os.path.exists(WAFDIR):
    raise UsageException("""\
%r not found: required when using waf extras !
    You can set waf location using the WAFDIR environment variable, such as
    $WAFDIR contains the 'waflib' directory""" % WAFDIR)
sys.path.insert(0, os.path.dirname(WAFDIR))

WAF_TOOLDIR = op.join(SITEDIR, "bento", "backends", "waf_tools")

from waflib.Context \
    import \
        create_context
from waflib.Options \
    import \
        OptionsContext
from waflib import Options
from waflib import Context
from waflib import Logs
from waflib import Build
コード例 #8
0
ファイル: core.py プロジェクト: yuhonghong7035/Bento
def monkey_patch(top_node, type, filename):
    supported = [
        "distutils", "numpy_distutils", "setuptools", "setuptools_numpy"
    ]

    if type == "distutils":
        from distutils.core import setup as old_setup
        from distutils.command.build_py import build_py as old_build_py
        from distutils.command.sdist import sdist as old_sdist
        from distutils.dist import Distribution as _Distribution
        from distutils.filelist import FileList
    elif type == "setuptools":
        from setuptools import setup as old_setup
        from setuptools.command.build_py import build_py as old_build_py
        from setuptools.command.sdist import sdist as old_sdist
        from distutils.dist import Distribution as _Distribution
        from distutils.filelist import FileList
    elif type == "numpy_distutils":
        import numpy.distutils
        import distutils.core
        from numpy.distutils.core import setup as old_setup
        from numpy.distutils.command.build_py import build_py as old_build_py
        from numpy.distutils.command.sdist import sdist as old_sdist
        from numpy.distutils.numpy_distribution import NumpyDistribution as _Distribution
        from distutils.filelist import FileList
    elif type == "setuptools_numpy":
        import setuptools
        import numpy.distutils
        import distutils.core
        from numpy.distutils.core import setup as old_setup
        from numpy.distutils.command.build_py import build_py as old_build_py
        from numpy.distutils.command.sdist import sdist as old_sdist
        from numpy.distutils.numpy_distribution import NumpyDistribution as _Distribution
        from distutils.filelist import FileList
    else:
        raise UsageException(
            "Unknown converter: %s (known converters are %s)" %
            (type, ", ".join(supported)))

    def get_extra_source_files():
        """Return the list of files included in the tarball."""
        # FIXME: handle redundancies between data files, package data files
        # (i.e. installed data files) and files included as part of modules,
        # packages, extensions, .... Given the giant mess that distutils makes
        # of things here, it may not be possible to get everything right,
        # though.
        dist = _Distribution()
        sdist = old_sdist(dist)
        sdist.initialize_options()
        sdist.finalize_options()
        sdist.manifest_only = True
        sdist.filelist = FileList()
        sdist.distribution.script_name = filename
        sdist.get_file_list()
        return sdist.filelist.files

    def new_setup(**kw):
        global DIST_GLOBAL, PACKAGE_OBJECTS
        package_objects = _PackageObjects(monkey_patch_mode=type)

        package_dir = kw.get("package_dir", None)
        if package_dir:
            keys = list(package_dir.keys())
            if len(keys) > 1:
                raise ConvertionError("setup call with package_dir=%r argument is not supported !" \
                                      % package_dir)
            elif len(keys) == 1:
                if package_dir.values()[0] != '':
                    raise ConvertionError("setup call with package_dir=%r argument is not supported !" \
                                          % package_dir)

        cmdclass = kw.get("cmdclass", {})
        try:
            _build_py = cmdclass["build_py"]
        except KeyError:
            _build_py = old_build_py

        class build_py_recorder(_build_py):
            def run(self):
                _build_py.run(self)

                package_objects.build_lib = self.build_lib
                package_objects.extra_source_files = get_extra_source_files()

                # This is simply the data_files argument passed to setup
                if self.distribution.data_files is not None:
                    package_objects.dist_data_files.extend(
                        self.distribution.data_files)
                # those are created from package_data stuff (the stuff included
                # if include_package_data=True as well)
                package_objects.data_files = self.data_files

        cmdclass["build_py"] = build_py_recorder
        kw["cmdclass"] = cmdclass

        dist = old_setup(**kw)
        DIST_GLOBAL = dist
        PACKAGE_OBJECTS = package_objects
        return dist

    if type == "distutils":
        import distutils.core
        distutils.core.setup = new_setup
    elif type == "setuptools":
        import distutils.core
        import setuptools
        distutils.core.setup = new_setup
        setuptools.setup = new_setup
    elif type == "setuptools_numpy":
        numpy.distutils.core.setup = new_setup
        setuptools.setup = new_setup
        distutils.core.setup = new_setup
    elif type == "numpy_distutils":
        numpy.distutils.core.setup = new_setup
        distutils.core.setup = new_setup
    else:
        raise UsageException(
            "Unknown converter: %s (known converters are %s)" %
            (type, ", ".join(supported)))