Ejemplo n.º 1
0
    def _static_representation(self, bento_info):
        r_pkg = PackageDescription.from_string(bento_info)
        # We recompute pkg to avoid dealing with stylistic difference between
        # original and static_representation
        pkg = PackageDescription.from_string(static_representation(r_pkg))

        self.assertEqual(static_representation(pkg), static_representation(r_pkg))
Ejemplo n.º 2
0
    def _static_representation(self, bento_info):
        r_pkg = PackageDescription.from_string(bento_info)
        # We recompute pkg to avoid dealing with stylistic difference between
        # original and static_representation
        pkg = PackageDescription.from_string(static_representation(r_pkg))

        self.assertEqual(static_representation(pkg),
                         static_representation(r_pkg))
Ejemplo n.º 3
0
    def test_error_string(self):
        f = self.f
        f.write("NName: foo")
        f.flush()
        try:
            PackageDescription.from_file(f.name)
            raise AssertionError("Should raise here !")
        except ParseError:
            e = extract_exception()
            self.assertEqual(str(e), """\
  File "%s", line 1
NName: foo
^
Syntax error""" % f.name)
Ejemplo n.º 4
0
    def test_error_string(self):
        f = self.f
        f.write("NName: foo")
        f.flush()
        try:
            PackageDescription.from_file(f.name)
            raise AssertionError("Should raise here !")
        except ParseError:
            e = extract_exception()
            self.assertEqual(
                str(e), """\
  File "%s", line 1
NName: foo
^
Syntax error""" % f.name)
Ejemplo n.º 5
0
    def test_simple(self):
        text = """\
NName: foo
"""
        error_msg = "Unrecognized keyword: 'NName'"
        self.assertRaisesRegex(ParseError, error_msg,
                               lambda: PackageDescription.from_string(text))
Ejemplo n.º 6
0
    def test_template_filling(self):
        bento_info = """\
Name: foo
Version: 1.0

MetaTemplateFile: release.py.in

Library:
    Modules: fubar
"""
        archive_list = [op.join("foo-1.0", f) for f in ["fubar.py", "release.py.in", "release.py"]]

        template = self.top_node.make_node("release.py.in")
        template.write("""\
NAME = $NAME
VERSION = $VERSION
""")

        create_fake_package_from_bento_info(self.top_node, bento_info)
        package = PackageDescription.from_string(bento_info)

        sdist = SdistCommand()
        opts = OptionsContext.from_command(sdist)
        cmd_argv = ["--output-file=foo.zip", "--format=zip"]

        context = SdistContext(None, cmd_argv, opts, package, self.run_node)
        run_command_in_context(context, sdist)

        self._assert_archive_equality(op.join("dist", "foo.zip"), archive_list)
    def test_iter_source_nodes(self):
        r_files = set([
            op.join("src", "foo.c"),
            op.join("src", "bar.c"),
            op.join("src", "fubar.c"),
            op.join("foo", "__init__.py"),
            op.join("foo", "bar", "__init__.py"), "fu.py", "foo.1"
        ])

        bento_info = """\
Name: foo

DataFiles: foo
    TargetDir: $sharedir
    Files: foo.1

Library:
    Extension: _foo
        Sources: src/foo.c, src/bar.c
    CompiledLibrary: fubar
        Sources: src/fubar.c
    Packages: foo, foo.bar
    Modules: fu
"""
        create_fake_package_from_bento_info(self.top_node, bento_info)

        package = PackageDescription.from_string(bento_info)
        node_package = NodeRepresentation(self.top_node, self.top_node)
        node_package.update_package(package)

        files = set(
            n.path_from(self.top_node)
            for n in node_package.iter_source_nodes())
        self.assertEqual(files, r_files)
Ejemplo n.º 8
0
    def test_simple_package(self):
        bento_info = """\
Name: foo
Version: 1.0

ExtraSourceFiles: yeah.info

Library:
    Packages: foo, foo.bar
    Modules: fubar
"""
        archive_list = [op.join("foo-1.0", f) for f in ["yeah.info",
                                                        op.join("foo", "__init__.py"),
                                                        op.join("foo", "bar", "__init__.py"),
                                                        "fubar.py"]]

        create_fake_package_from_bento_info(self.top_node, bento_info)
        package = PackageDescription.from_string(bento_info)

        sdist = SdistCommand()
        opts = OptionsContext.from_command(sdist)
        cmd_argv = ["--output-file=foo.zip", "--format=zip"]

        context = SdistContext(None, cmd_argv, opts, package, self.run_node)
        run_command_in_context(context, sdist)

        self._assert_archive_equality(op.join("dist", "foo.zip"), archive_list)
Ejemplo n.º 9
0
    def test_compiled_library(self):
        from bento.backends.distutils_backend import DistutilsBuildContext

        r_full_name = "lib/_foo"

        bento_info = """\
Name: foo

Library:
    CompiledLibrary: lib/_foo
        Sources: foo.c
"""
        package = PackageDescription.from_string(bento_info)
        create_fake_package_from_bento_info(self.top_node, bento_info)

        options = OptionsContext.from_command(BuildCommand())
        context = DistutilsBuildContext(None, [], options, package, self.run_node)
        context.pre_recurse(self.top_node)
        try:
            def builder(a):
                self.assertEqual(a.name, r_full_name)
                builder.is_called = True
            builder.is_called = False
            context.register_compiled_library_builder("lib/_foo", builder)
        finally:
            context.post_recurse()
        context.compile()

        self.assertTrue(builder.is_called, "registered builder not called")
Ejemplo n.º 10
0
    def test_extra_source_registration(self):
        bento_info = """\
Name: foo
Version: 1.0

Library:
    Modules: fubar
"""
        archive_list = [op.join("foo-1.0", f) for f in ["fubar.py", "yeah.info"]]

        extra_node = self.top_node.make_node("yeah.info")
        extra_node.write("")

        create_fake_package_from_bento_info(self.top_node, bento_info)
        package = PackageDescription.from_string(bento_info)

        sdist = SdistCommand()
        opts = OptionsContext.from_command(sdist)
        cmd_argv = ["--output-file=foo.zip", "--format=zip"]

        context = SdistContext(None, cmd_argv, opts, package, self.run_node)
        context.register_source_node(self.top_node.find_node("yeah.info"))
        run_command_in_context(context, sdist)

        self._assert_archive_equality(op.join("dist", "foo.zip"), archive_list)
Ejemplo n.º 11
0
    def test_iter_source_nodes(self):
        r_files = set([op.join("src", "foo.c"),
            op.join("src", "bar.c"),
            op.join("src", "fubar.c"),
            op.join("foo", "__init__.py"),
            op.join("foo", "bar", "__init__.py"),
            "fu.py", "foo.1"])

        bento_info = """\
Name: foo

DataFiles: foo
    TargetDir: $sharedir
    Files: foo.1

Library:
    Extension: _foo
        Sources: src/foo.c, src/bar.c
    CompiledLibrary: fubar
        Sources: src/fubar.c
    Packages: foo, foo.bar
    Modules: fu
"""
        create_fake_package_from_bento_info(self.top_node, bento_info)

        package = PackageDescription.from_string(bento_info)
        node_package = NodeRepresentation(self.top_node, self.top_node)
        node_package.update_package(package)

        files = set(n.path_from(self.top_node) for n in node_package.iter_source_nodes())
        self.assertEqual(files, r_files)
Ejemplo n.º 12
0
    def test_template_filling(self):
        bento_info = """\
Name: foo
Version: 1.0

MetaTemplateFiles: release.py.in

Library:
    Modules: fubar
"""
        archive_list = [
            op.join("foo-1.0", f)
            for f in ["fubar.py", "release.py.in", "release.py", "PKG_INFO"]
        ]

        template = self.top_node.make_node("release.py.in")
        template.write("""\
NAME = $NAME
VERSION = $VERSION
""")

        create_fake_package_from_bento_info(self.top_node, bento_info)
        package = PackageDescription.from_string(bento_info)

        sdist = SdistCommand()
        opts = OptionsContext.from_command(sdist)
        cmd_argv = ["--output-file=foo.zip", "--format=zip"]

        context = SdistContext(None, cmd_argv, opts, package, self.run_node)
        run_command_in_context(context, sdist)

        self._assert_archive_equality(op.join("dist", "foo.zip"), archive_list)
Ejemplo n.º 13
0
    def test_simple_package(self):
        bento_info = """\
Name: foo
Version: 1.0

ExtraSourceFiles: yeah.info

Library:
    Packages: foo, foo.bar
    Modules: fubar
"""
        archive_list = [
            op.join("foo-1.0", f) for f in [
                "yeah.info", "PKG_INFO",
                op.join("foo", "__init__.py"),
                op.join("foo", "bar", "__init__.py"), "fubar.py"
            ]
        ]

        create_fake_package_from_bento_info(self.top_node, bento_info)
        package = PackageDescription.from_string(bento_info)

        sdist = SdistCommand()
        opts = OptionsContext.from_command(sdist)
        cmd_argv = ["--output-file=foo.zip", "--format=zip"]

        context = SdistContext(None, cmd_argv, opts, package, self.run_node)
        run_command_in_context(context, sdist)

        self._assert_archive_equality(op.join("dist", "foo.zip"), archive_list)
Ejemplo n.º 14
0
    def test_extra_source_registration(self):
        bento_info = """\
Name: foo
Version: 1.0

Library:
    Modules: fubar
"""
        archive_list = [
            op.join("foo-1.0", f)
            for f in ["fubar.py", "yeah.info", "PKG_INFO"]
        ]

        extra_node = self.top_node.make_node("yeah.info")
        extra_node.write("")

        create_fake_package_from_bento_info(self.top_node, bento_info)
        package = PackageDescription.from_string(bento_info)

        sdist = SdistCommand()
        opts = OptionsContext.from_command(sdist)
        cmd_argv = ["--output-file=foo.zip", "--format=zip"]

        context = SdistContext(None, cmd_argv, opts, package, self.run_node)
        context.register_source_node(self.top_node.find_node("yeah.info"))
        run_command_in_context(context, sdist)

        self._assert_archive_equality(op.join("dist", "foo.zip"), archive_list)
Ejemplo n.º 15
0
    def _run_configure(self,
                       bentos,
                       bscripts=None,
                       configure_argv=None,
                       build_argv=None):
        from bento.backends.waf_backend import make_stream_logger
        from bento.backends.waf_backend import WafBackend

        top_node = self.top_node

        bento_info = bentos["bento.info"]
        package = PackageDescription.from_string(bento_info)
        package_options = PackageOptions.from_string(bento_info)

        create_fake_package_from_bento_info(top_node, bento_info)
        top_node.make_node("bento.info").safe_write(bento_info)

        global_context = create_global_context(package, package_options,
                                               WafBackend())
        conf, configure = prepare_command(global_context, "configure",
                                          configure_argv, package, top_node)
        run_command_in_context(conf, configure)

        bld, build = prepare_command(global_context, "build", build_argv,
                                     package, top_node)
        bld.waf_context.logger = make_stream_logger("build", cStringIO())
        return conf, configure, bld, build
Ejemplo n.º 16
0
    def test_template_filling(self):
        bento_info = """\
Name: foo
Version: 1.0

MetaTemplateFile: release.py.in

Library:
    Modules: fubar
"""
        archive_list = [op.join("foo-1.0", f) for f in ["fubar.py", "release.py.in", "release.py"]]

        template = self.top_node.make_node("release.py.in")
        template.write("""\
NAME = $NAME
VERSION = $VERSION
""")

        create_fake_package_from_bento_info(self.top_node, bento_info)
        package = PackageDescription.from_string(bento_info)

        sdist = SdistCommand()
        opts = OptionsContext.from_command(sdist)
        cmd_argv = ["--output-file=foo.zip", "--format=zip"]

        context = SdistContext(None, cmd_argv, opts, package, self.run_node)
        sdist.run(context)
        sdist.shutdown(context)
        context.shutdown()

        archive = self.run_node.find_node(op.join("dist", "foo.zip"))
        z = zipfile.ZipFile(archive.abspath(), "r")
        for f in archive_list:
            if not f in z.namelist():
                self.fail("File %s not found in archive" % (f,))
Ejemplo n.º 17
0
    def test_simple_package(self):
        bento_info = """\
Name: foo
Version: 1.0

ExtraSourceFiles: yeah.info

Library:
    Packages: foo, foo.bar
    Modules: fubar
"""
        archive_list = [op.join("foo-1.0", f) for f in ["yeah.info",
                                                        op.join("foo", "__init__.py"),
                                                        op.join("foo", "bar", "__init__.py"),
                                                        "fubar.py"]]

        create_fake_package_from_bento_info(self.top_node, bento_info)
        package = PackageDescription.from_string(bento_info)

        sdist = SdistCommand()
        opts = OptionsContext.from_command(sdist)
        cmd_argv = ["--output-file=foo.zip", "--format=zip"]

        context = SdistContext(None, cmd_argv, opts, package, self.run_node)
        sdist.run(context)
        sdist.shutdown(context)
        context.shutdown()

        archive = self.run_node.find_node(op.join("dist", "foo.zip"))
        z = zipfile.ZipFile(archive.abspath(), "r")
        for f in archive_list:
            if not f in z.namelist():
                self.failUnless(op.join("foo-1.0", f) in files)
Ejemplo n.º 18
0
    def test_compiled_library(self):
        from bento.backends.distutils_backend import DistutilsBuildContext

        r_full_name = "lib/_foo"

        bento_info = """\
Name: foo

Library:
    CompiledLibrary: lib/_foo
        Sources: foo.c
"""
        package = PackageDescription.from_string(bento_info)
        create_fake_package_from_bento_info(self.top_node, bento_info)

        options = OptionsContext.from_command(BuildCommand())
        context = DistutilsBuildContext(None, [], options, package,
                                        self.run_node)
        context.pre_recurse(self.top_node)
        try:

            def builder(a):
                self.assertEqual(a.name, r_full_name)
                builder.is_called = True

            builder.is_called = False
            context.register_compiled_library_builder("lib/_foo", builder)
        finally:
            context.post_recurse()
        context.compile()

        self.assertTrue(builder.is_called, "registered builder not called")
Ejemplo n.º 19
0
    def test_extra_source_registration(self):
        bento_info = """\
Name: foo
Version: 1.0

Library:
    Modules: fubar
"""
        archive_list = [op.join("foo-1.0", f) for f in ["fubar.py", "yeah.info"]]

        extra_node = self.top_node.make_node("yeah.info")
        extra_node.write("")

        create_fake_package_from_bento_info(self.top_node, bento_info)
        package = PackageDescription.from_string(bento_info)

        sdist = SdistCommand()
        opts = OptionsContext.from_command(sdist)
        cmd_argv = ["--output-file=foo.zip", "--format=zip"]

        context = SdistContext(None, cmd_argv, opts, package, self.run_node)
        context.register_source_node(self.top_node.find_node("yeah.info"))
        sdist.run(context)
        sdist.shutdown(context)
        context.shutdown()

        archive = self.run_node.find_node(op.join("dist", "foo.zip"))
        z = zipfile.ZipFile(archive.abspath(), "r")
        for f in archive_list:
            if not f in z.namelist():
                self.failUnless(op.join("foo-1.0", f) in files)
Ejemplo n.º 20
0
    def test_simple(self):
        text = """\
NName: foo
"""
        error_msg = """\
yacc: Syntax error at line 1, Token\(WORD, 'NName'\)
\t'NName: foo'"""
        self.assertRaisesRegexp(ParseError, error_msg, lambda : PackageDescription.from_string(text))
Ejemplo n.º 21
0
    def test_simple(self):
        text = """\
NName: foo
"""
        error_msg = """\
yacc: Syntax error at line 1, Token\(WORD, 'NName'\)
\t'NName: foo'"""
        self.assertRaisesRegexp(ParseError, error_msg,
                                lambda: PackageDescription.from_string(text))
Ejemplo n.º 22
0
    def _run_build_with_pre_hook(self, hook_func):
        package = PackageDescription.from_string(BENTO_INFO)
        global_context = prepare_package(self.top_node, BENTO_INFO)

        conf, configure = prepare_command(global_context, "configure", [], package, self.top_node)
        run_command_in_context(conf, configure)

        pre_hook = PreHookWrapper(hook_func, self.build_node.path_from(self.top_node), self.top_node.abspath())
        bld, build = prepare_command(global_context, "build", [], package, self.top_node)
        run_command_in_context(bld, build, pre_hooks=[pre_hook])

        return bld
Ejemplo n.º 23
0
    def _run_build_with_pre_hook(self, hook_func):
        package = PackageDescription.from_string(BENTO_INFO)
        global_context = prepare_package(self.top_node, BENTO_INFO)

        conf, configure = prepare_command(global_context, "configure", [], package, self.top_node)
        run_command_in_context(conf, configure)

        pre_hook = PreHookWrapper(hook_func, self.build_node.path_from(self.top_node), self.top_node.abspath())
        bld, build = prepare_command(global_context, "build", [], package, self.top_node)
        run_command_in_context(bld, build, pre_hooks=[pre_hook])

        return bld
Ejemplo n.º 24
0
    def test_simple(self):
        text = """\
Name: foo

DataFiles: data
    TargetDir: $datadir
    Files:
        foo.data
"""
        r_data = DataFiles("data", files=["foo.data"], target_dir="$datadir")
        pkg = PackageDescription.from_string(text)
        self.failUnless("data" in pkg.data_files)
        self.assertEqual(pkg.data_files["data"].__dict__, r_data.__dict__)
Ejemplo n.º 25
0
    def test_simple(self):
        text = """\
Name: foo

DataFiles: data
    TargetDir: $datadir
    Files:
        foo.data
"""
        r_data = DataFiles("data", files=["foo.data"], target_dir="$datadir")
        pkg = PackageDescription.from_string(text)
        self.assertTrue("data" in pkg.data_files)
        self.assertEqual(pkg.data_files["data"].__dict__, r_data.__dict__)
Ejemplo n.º 26
0
    def _run_command(self):
        setup_node = self.top_node.make_node("setup.py")
        setup_node.safe_write("")

        create_fake_package_from_bento_info(self.top_node, "")
        package = PackageDescription.from_string("")

        cmd = DetectTypeCommand()
        opts = OptionsContext.from_command(cmd)

        context = CmdContext(None, [], opts, package, self.run_node)
        cmd.run(context)
        cmd.finish(context)
        context.finish()
Ejemplo n.º 27
0
def _run_convert_command(top_node, run_node, setup_py, bento_info, cmd_argv):
    setup_node = top_node.make_node("setup.py")
    setup_node.safe_write(setup_py)

    create_fake_package_from_bento_info(top_node, bento_info)
    package = PackageDescription.from_string(bento_info)

    cmd = ConvertCommand()
    opts = OptionsContext.from_command(cmd)

    context = CmdContext(None, cmd_argv, opts, package, run_node)
    cmd.run(context)
    cmd.finish(context)
    context.finish()
Ejemplo n.º 28
0
def _run_convert_command(top_node, run_node, setup_py, bento_info, cmd_argv):
    setup_node = top_node.make_node("setup.py")
    setup_node.safe_write(setup_py)

    create_fake_package_from_bento_info(top_node, bento_info)
    package = PackageDescription.from_string(bento_info)

    cmd = ConvertCommand()
    opts = OptionsContext.from_command(cmd)

    context = CmdContext(None, cmd_argv, opts, package, run_node)
    cmd.run(context)
    cmd.finish(context)
    context.finish()
Ejemplo n.º 29
0
    def _run_command(self):
        setup_node = self.top_node.make_node("setup.py")
        setup_node.safe_write("")

        create_fake_package_from_bento_info(self.top_node, "")
        package = PackageDescription.from_string("")

        cmd = DetectTypeCommand()
        opts = OptionsContext.from_command(cmd)

        context = CmdContext(None, [], opts, package, self.run_node)
        cmd.run(context)
        cmd.finish(context)
        context.finish()
Ejemplo n.º 30
0
    def test_simple(self):
        n = self.top_node.make_node("doc/conf.py")
        n.parent.mkdir()
        n.write("")

        n = self.top_node.make_node("doc/contents.rst")
        n.write("")

        bento_info = "Name: foo"
        package = PackageDescription.from_string(bento_info)

        sphinx = SphinxCommand()
        opts = OptionsContext.from_command(sphinx)
        context = ContextWithBuildDirectory(None, [], opts, package, self.run_node)

        run_command_in_context(context, sphinx)
Ejemplo n.º 31
0
Archivo: sdist.py Proyecto: dagss/Bento
    def run(self, ctx):
        o, a = self.parser.parse_args(ctx.cmd_opts)
        if o.help:
            self.parser.print_help()
            return

        filename = BENTO_SCRIPT
        if not len(a) > 0:
            if not os.path.exists(filename):
                raise UsageException("Missing %s file" % BENTO_SCRIPT)

        pkg = PackageDescription.from_file(filename)
        tarname = tarball_basename(pkg.name, pkg.version) + ".tar.gz"
        self.tarname = os.path.abspath(os.path.join("dist", tarname))
        self.topdir = "%s-%s" % (pkg.name, pkg.version)
        create_tarball(pkg, ctx.top_node, self.tarname, self.topdir)
Ejemplo n.º 32
0
    def _execute_build(self, bento_info):
        create_fake_package_from_bento_info(self.top_node, bento_info)
        # FIXME: this should be done automatically in create_fake_package_from_bento_info
        self.top_node.make_node("bento.info").safe_write(bento_info)

        package = PackageDescription.from_string(bento_info)
        package_options = PackageOptions.from_string(bento_info)

        global_context = create_global_context(package, package_options, YakuBackend())
        conf, configure = prepare_command(global_context, "configure", [], package, self.run_node)
        run_command_in_context(conf, configure)

        bld, build = prepare_command(global_context, "build", [], package, self.run_node)
        run_command_in_context(bld, build)

        return bld
Ejemplo n.º 33
0
    def test_simple(self):
        n = self.top_node.make_node("doc/conf.py")
        n.parent.mkdir()
        n.write("")

        n = self.top_node.make_node("doc/contents.rst")
        n.write("")

        bento_info = "Name: foo"
        package = PackageDescription.from_string(bento_info)

        sphinx = SphinxCommand()
        opts = OptionsContext.from_command(sphinx)
        context = ContextWithBuildDirectory(None, [], opts, package, self.run_node)

        run_command_in_context(context, sphinx)
Ejemplo n.º 34
0
    def _execute_build(self, bento_info):
        create_fake_package_from_bento_info(self.top_node, bento_info)
        # FIXME: this should be done automatically in create_fake_package_from_bento_info
        self.top_node.make_node("bento.info").safe_write(bento_info)

        package = PackageDescription.from_string(bento_info)
        package_options = PackageOptions.from_string(bento_info)

        global_context = create_global_context(package, package_options, YakuBackend())
        conf, configure = prepare_command(global_context, "configure", [], package, self.run_node)
        run_command_in_context(conf, configure)

        bld, build = prepare_command(global_context, "build", [], package, self.run_node)
        run_command_in_context(bld, build)

        return bld
Ejemplo n.º 35
0
    def _prepare_egg_info(self):
        create_fake_package(self.top_node, ["sphinx", "sphinx.builders"],
                            ["cat.py"], [Extension("_dog", [os.path.join("src", "dog.c")])])
        build_manifest_file = self.build_node.make_node(BUILD_MANIFEST_PATH)
        build_manifest_file.parent.mkdir()
        build_manifest_file.write("")

        files = [os.path.join("sphinx", "builders", "__init__.py"),
                 os.path.join("sphinx", "__init__.py"),
                 os.path.join("src", "dog.c"),
                 os.path.join("cat.py")]

        pkg = PackageDescription.from_string(DESCR)
        meta = PackageMetadata.from_package(pkg)
        executables = pkg.executables

        return EggInfo(meta, executables, files)
Ejemplo n.º 36
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

        filename = BENTO_SCRIPT
        if not len(a) > 0:
            if not os.path.exists(filename):
                raise UsageException("Missing %s file" % BENTO_SCRIPT)

        pkg = PackageDescription.from_file(filename)
        tarname = tarball_basename(pkg.name, pkg.version) + ".tar.gz"
        self.tarname = os.path.abspath(os.path.join(o.output_dir, tarname))
        self.topdir = "%s-%s" % (pkg.name, pkg.version)
        create_tarball(pkg, ctx.top_node, self.tarname, self.topdir)
Ejemplo n.º 37
0
    def setUp(self):
        self.package = PackageDescription.from_string("""\
Name: foo
""")
        self.cwd = tempfile.mkdtemp()
        try:
            self.old_cwd = os.getcwd()
            os.chdir(self.cwd)

            filename = op.join(self.cwd, "foo.bin")
            fp = open(filename, "wb")
            try:
                fp.write(six.b("garbage"))
            finally:
                fp.close()

        except:
            shutil.rmtree(self.cwd)
            raise
Ejemplo n.º 38
0
    def setUp(self):
        self.package = PackageDescription.from_string("""\
Name: foo
""")
        self.cwd = tempfile.mkdtemp()
        try:
            self.old_cwd = os.getcwd()
            os.chdir(self.cwd)

            filename = op.join(self.cwd, "foo.bin")
            fp = open(filename, "wb")
            try:
                fp.write(six.b("garbage"))
            finally:
                fp.close()

        except:
            shutil.rmtree(self.cwd)
            raise
Ejemplo n.º 39
0
    def test_simple_waf(self):
        from bento.backends.waf_backend import make_stream_logger
        from bento.backends.waf_backend import WafBackend

        top_node = self.top_node

        package = PackageDescription.from_string(BENTO_INFO_WITH_EXT)
        package_options = PackageOptions.from_string(BENTO_INFO_WITH_EXT)

        create_fake_package_from_bento_info(top_node, BENTO_INFO_WITH_EXT)
        top_node.make_node("bento.info").safe_write(BENTO_INFO_WITH_EXT)

        global_context = create_global_context(package, package_options, WafBackend())
        conf, configure = prepare_command(global_context, "configure", [], package, top_node)
        run_command_in_context(conf, configure)

        bld, build = prepare_command(global_context, "build", [], package, top_node)
        bld.waf_context.logger = make_stream_logger("build", cStringIO())
        run_command_in_context(bld, build)
Ejemplo n.º 40
0
    def test_simple_waf(self):
        from bento.backends.waf_backend import make_stream_logger
        from bento.backends.waf_backend import WafBackend

        top_node = self.top_node

        package = PackageDescription.from_string(BENTO_INFO_WITH_EXT)
        package_options = PackageOptions.from_string(BENTO_INFO_WITH_EXT)

        create_fake_package_from_bento_info(top_node, BENTO_INFO_WITH_EXT)
        top_node.make_node("bento.info").safe_write(BENTO_INFO_WITH_EXT)

        global_context = create_global_context(package, package_options, WafBackend())
        conf, configure = prepare_command(global_context, "configure", [], package, top_node)
        run_command_in_context(conf, configure)

        bld, build = prepare_command(global_context, "build", [], package, top_node)
        bld.waf_context.logger = make_stream_logger("build", cStringIO())
        run_command_in_context(bld, build)
Ejemplo n.º 41
0
    def _prepare_egg_info(self):
        create_fake_package(
            self.top_node, ["sphinx", "sphinx.builders"], ["cat.py"],
            [Extension("_dog", [os.path.join("src", "dog.c")])])
        build_manifest_file = self.build_node.make_node(BUILD_MANIFEST_PATH)
        build_manifest_file.parent.mkdir()
        build_manifest_file.write("")

        files = [
            os.path.join("sphinx", "builders", "__init__.py"),
            os.path.join("sphinx", "__init__.py"),
            os.path.join("src", "dog.c"),
            os.path.join("cat.py")
        ]

        pkg = PackageDescription.from_string(DESCR)
        meta = PackageMetadata.from_package(pkg)
        executables = pkg.executables

        return EggInfo(meta, executables, files)
Ejemplo n.º 42
0
    def __init__(self, attrs=None):
        if attrs is None:
            attrs = {}

        if not "bento_info" in attrs:
            bento_info = "bento.info"
        else:
            bento_info = attrs["bento.info"]
        self.pkg = PackageDescription.from_file(bento_info)
        package_options = PackageOptions.from_file(bento_info)

        attrs = _setup_cmd_classes(attrs)

        d = pkg_to_distutils_meta(self.pkg)
        attrs.update(d)

        Distribution.__init__(self, attrs)

        self.packages = self.pkg.packages
        self.py_modules = self.pkg.py_modules
        if hasattr(self, "entry_points"):
            if self.entry_points is None:
                self.entry_points = {}
            console_scripts = [
                e.full_representation() for e in self.pkg.executables.values()
            ]
            if "console_scripts" in self.entry_points:
                self.entry_points["console_scripts"].extend(console_scripts)
            else:
                self.entry_points["console_scripts"] = console_scripts

        source_root = os.getcwd()
        build_root = os.path.join(source_root, "build")
        root = create_root_with_source_tree(source_root, build_root)
        self.top_node = root._ctx.srcnode
        self.build_node = root._ctx.bldnode
        self.run_node = root._ctx.srcnode

        self.global_context = global_context_factory(package_options)
        mods = set_main(self.pkg, self.top_node, self.build_node)
        self._setup_hooks(self.pkg, self.global_context, mods)
Ejemplo n.º 43
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
        bento_script = ctx.top_node.find_node(BENTO_SCRIPT)

        if not o.output:
            pkg_info = "PKG-INFO"
        else:
            pkg_info = o.output

        pkg = PackageDescription.from_file(bento_script.abspath())

        fid = open(pkg_info, "w")
        try:
            write_pkg_info(pkg, fid)
        finally:
            fid.close()
Ejemplo n.º 44
0
    def _run_configure(self, bentos, bscripts=None, configure_argv=None, build_argv=None):
        from bento.backends.waf_backend import make_stream_logger
        from bento.backends.waf_backend import WafBackend

        top_node = self.top_node

        bento_info = bentos["bento.info"]
        package = PackageDescription.from_string(bento_info)
        package_options = PackageOptions.from_string(bento_info)

        create_fake_package_from_bento_info(top_node, bento_info)
        top_node.make_node("bento.info").safe_write(bento_info)

        global_context = create_global_context(package, package_options, WafBackend())
        conf, configure = prepare_command(global_context, "configure",
                configure_argv, package, top_node)
        run_command_in_context(conf, configure)

        bld, build = prepare_command(global_context, "build", build_argv, package, top_node)
        bld.waf_context.logger = make_stream_logger("build", cStringIO())
        return conf, configure, bld, build
Ejemplo n.º 45
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
        bento_script = ctx.top_node.find_node(BENTO_SCRIPT)

        if not o.output:
            pkg_info = "PKG-INFO"
        else:
            pkg_info = o.output

        pkg = PackageDescription.from_file(bento_script.abspath())

        fid = open(pkg_info, "w")
        try:
            write_pkg_info(pkg, fid)
        finally:
            fid.close()
Ejemplo n.º 46
0
    def __init__(self, attrs=None):
        if attrs is None:
            attrs = {}

        if not "bento_info" in attrs:
            bento_info = "bento.info"
        else:
            bento_info = attrs["bento.info"]
        self.pkg = PackageDescription.from_file(bento_info)
        self.package_options = PackageOptions.from_file(bento_info)


        attrs = _setup_cmd_classes(attrs)

        d = pkg_to_distutils_meta(self.pkg)
        attrs.update(d)

        Distribution.__init__(self, attrs)

        self.packages = self.pkg.packages
        self.py_modules = self.pkg.py_modules
        if hasattr(self, "entry_points"):
            if self.entry_points is None:
                self.entry_points = {}
            console_scripts = [e.full_representation() for e in self.pkg.executables.values()]
            if "console_scripts" in self.entry_points:
                self.entry_points["console_scripts"].extend(console_scripts)
            else:
                self.entry_points["console_scripts"] = console_scripts

        source_root = os.getcwd()
        build_root = os.path.join(source_root, "build")
        root = create_root_with_source_tree(source_root, build_root)
        self.top_node = root._ctx.srcnode
        self.build_node = root._ctx.bldnode
        self.run_node = root._ctx.srcnode

        self.global_context = global_context_factory(self.package_options)
        modules = set_main(self.top_node, self.build_node, self.pkg)
Ejemplo n.º 47
0
    def test_prune_extra_files(self):
        files = ["doc/foo.info", "yeah.txt", "foo/__init__.py"]
        for f in files:
            n = self.top_node.make_node(f)
            n.parent.mkdir()
            n.write("")

        bento_info = """\
Name: foo

ExtraSourceFiles: yeah.txt

DataFiles: doc
    SourceDir: .
    TargetDir: $sitedir
    Files: doc/foo.info

Library:
    Packages: foo
"""
        pkg = PackageDescription.from_string(bento_info)
        files = prune_extra_files(files, pkg, self.top_node)
        self.assertEqual(files, ["yeah.txt"])
Ejemplo n.º 48
0
    def test_sources_glob(self):
        bento_info = """\
Name: foo

Library:
    Extension: _foo
        Sources: src/foo.c, src/bar.c
"""
        create_fake_package_from_bento_info(self.top_node, bento_info)

        bento_info = """\
Name: foo

Library:
    Extension: _foo
        Sources: src/*.c
"""
        pkg = PackageDescription.from_string(bento_info)
        node_pkg = NodeRepresentation(self.top_node, self.top_node)
        node_pkg.update_package(pkg)

        extensions = dict(node_pkg.iter_category("extensions"))
        self.assertEqual(len(extensions), 1)
        self.assertEqual(len(extensions["_foo"].nodes), 2)
Ejemplo n.º 49
0
    def run(self, ctx):
        o, a = self.parser.parse_args(ctx.cmd_opts)
        if o.help:
            self.parser.print_help()
            return

        if len(a) < 1:
            raise UsageException("%s: error: %s subcommand require an argument" \
                    % (SCRIPT_NAME, "parse"))
        else:
            filename = a[0]

        if not o.output:
            pkg_info = "PKG-INFO"
        else:
            pkg_info = o.output

        pkg = PackageDescription.from_file(filename)

        fid = open(pkg_info, "w")
        try:
            write_pkg_info(pkg, fid)
        finally:
            fid.close()
    def test_sources_glob(self):
        bento_info = """\
Name: foo

Library:
    Extension: _foo
        Sources: src/foo.c, src/bar.c
"""
        create_fake_package_from_bento_info(self.top_node, bento_info)

        bento_info = """\
Name: foo

Library:
    Extension: _foo
        Sources: src/*.c
"""
        pkg = PackageDescription.from_string(bento_info)
        node_pkg = NodeRepresentation(self.top_node, self.top_node)
        node_pkg.update_package(pkg)

        extensions = dict(node_pkg.iter_category("extensions"))
        self.assertEqual(len(extensions), 1)
        self.assertEqual(len(extensions["_foo"].nodes), 2)
Ejemplo n.º 51
0
def _raw_to_pkg(raw, user_flags, bento_info):
    kw, files = raw_to_pkg_kw(raw, user_flags, bento_info)
    pkg = PackageDescription(**kw)
    return pkg, files
Ejemplo n.º 52
0
 def test_simple_filename(self):
     f = self.f
     f.write("NName: foo")
     f.flush()
     self.assertRaises(ParseError, lambda : PackageDescription.from_file(f.name))
Ejemplo n.º 53
0
 def test_simple_filename(self):
     f = self.f
     f.write("NName: foo")
     f.flush()
     self.assertRaises(ParseError,
                       lambda: PackageDescription.from_file(f.name))
Ejemplo n.º 54
0
    import \
        PackageDescription
from bento.core.utils \
    import \
        subst_vars
from bento.installed_package_description \
    import \
        InstalledPkgDescription, InstalledSection, ipkg_meta_from_pkg, iter_files

import bento.tests.bentos

# FIXME: use correct install path instead of python package hack
BENTOS_DIR = os.path.dirname(bento.tests.bentos.__file__)
SPHINX_META = os.path.join(BENTOS_DIR, "sphinx_meta.info")

SPHINX_META_PKG = PackageDescription.from_file(SPHINX_META)

class TestInstalledSection(unittest.TestCase):
    def test_simple(self):
        files = [("scripts/foo.py", "scripts/foo"),
                 ("scripts/bar.py", "scripts/bar.py")]
        section = InstalledSection("pythonfiles", "section1", "source", "target", files)

    def test_from_source_target(self):
        files = [("scripts/foo.py", "scripts/foo.py"),
                 ("scripts/bar.py", "scripts/bar.py")]
        r_section = InstalledSection("pythonfiles", "section1", "source", "target", files)

        files = ["scripts/foo.py", "scripts/bar.py"]
        section = InstalledSection.from_source_target_directories("pythonfiles",
                        "section1", "source", "target", files)
Ejemplo n.º 55
0
import os

import bento.testing.bentos

from bento.core.package \
    import \
        PackageDescription
from bento.installed_package_description \
    import \
        InstalledSection, build_manifest_meta_from_pkg

# FIXME: use correct install path instead of python package hack
BENTOS_DIR = os.path.dirname(bento.testing.bentos.__file__)
SPHINX_META = os.path.join(BENTOS_DIR, "sphinx_meta.info")

SPHINX_META_PKG = PackageDescription.from_file(SPHINX_META)


def create_simple_build_manifest_args(top_node):
    files = ["scripts/foo.py", "scripts/bar.py"]
    srcdir = "source"

    nodes = [top_node.make_node(os.path.join(srcdir, f)) for f in files]
    for n in nodes:
        n.parent.mkdir()
        n.write("")
    section = InstalledSection.from_source_target_directories(
        "pythonfiles", "section1", os.path.join("$_srcrootdir", srcdir),
        "$prefix/target", files)
    sections = {"pythonfiles": {"section1": section}}