Exemple #1
0
 def extension_from(self, from_node=None):
     if len(self.nodes) < 1:
         return Extension(self.name, [])
     else:
         if from_node is None:
             from_node = self.nodes[0].srcnode
         if not from_node.is_src():
             raise ValueError("node %s is not a source directory !" % from_node.abspath())
         if not self.ref_node.is_child_of(from_node):
             raise ValueError("from_node should be a parent of %s, but is %s" % \
                              (self.ref_node.abspath(), from_node.abspath()))
         else:
             def translate_full_name(full_name):
                 parent_pkg = from_node.path_from(self.top_node)
                 if parent_pkg == ".":
                     parent_components = []
                 else:
                     parent_components = split_path(parent_pkg)
                 full_name_components = self.full_name.split(".")
                 if not full_name_components[:len(parent_components)] == parent_components:
                     raise ValueError("Internal bug: unexpected parent/name components: %s %s" % \
                                      (parent_components, full_name_components))
                 else:
                     return ".".join(full_name_components[len(parent_components):])
             relative_name = translate_full_name(self.full_name)
             return Extension(relative_name, sources=[n.path_from(from_node) for n in self.nodes])
Exemple #2
0
    def test_multiple_extensions(self):
        self.top_node.make_node("foo.c").write(DUMMY_C % {"name": "foo"})
        self.top_node.make_node("bar.c").write(DUMMY_C % {"name": "bar"})

        builder = DistutilsBuilder()

        extensions = [Extension("bar", ["bar.c"]), Extension("foo", ["foo.c"])]
        for extension in extensions:
            builder.build_extension(extension)
Exemple #3
0
def flatten_extensions(top_node, subpackage):
    ret = []

    d = top_node.find_dir(subpackage.rdir)
    root_name = ".".join(subpackage.rdir.split("/"))
    for extension in list(subpackage.extensions.values()):
        sources = [
            d.make_node(s).path_from(top_node) for s in extension.sources
        ]
        full_name = root_name + ".%s" % extension.name
        ret.append(Extension(full_name, sources))
    return ret
Exemple #4
0
def flatten_subpackage_extensions(spkg, top_node):
    """Translate the extensions from a subpackage relatively to the
    given top node.

    Extension name, source files and include directories paths are all
    translated relatively to the top node.

    Returns
    -------
    d : dict
        {ext_name: ext} dictionary

    Example
    -------
    Defining in /foo/bar the extension::

        Extension("_hello", sources=["src/hellomodule.c"])

    and top_node corresponding to /foo, the
    extension would be translated as::

        Extension("bar._hello", sources=["bar/src/hellomodule.c"])
    """
    local_node = top_node.find_dir(spkg.rdir)
    if local_node is None:
        raise IOError("Path %s not found" % \
                      os.path.join(top_node.abspath(), spkg.rdir))
    elif local_node == top_node:
        raise ValueError("Subpackage in top directory ??")

    ret = {}
    for name, extension in list(spkg.extensions.items()):
        parent_pkg = spkg.rdir.replace(os.sep, ".")
        full_name = parent_pkg + ".%s" % name
        sources = []
        for s in extension.sources:
            node = local_node.find_node(s)
            if node is None:
                raise IOError("File %s not found" % s)
            sources.append(node.path_from(top_node))
        include_dirs = [
                local_node.find_node(d).path_from(top_node) \
                for d in extension.include_dirs]
        ret[full_name] = Extension(full_name, sources, include_dirs)
    return ret
Exemple #5
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)
Exemple #6
0
def _parse_libraries(libraries):
    ret = {}
    if len(libraries) > 0:
        if not list(libraries.keys()) == ["default"]:
            raise NotImplementedError(
                    "Non default library not yet supported")

        default = libraries["default"]
        for k in ["packages", "py_modules", "install_requires", "sub_directory"]:
            if k in default:
                ret[k] = default[k]

        ret["extensions"] = {}
        for k, v in default.get("extensions", {}).items():
            ret["extensions"][k] = Extension.from_parse_dict(v)

        ret["compiled_libraries"] = {}
        for k, v in default.get("compiled_libraries", {}).items():
            ret["compiled_libraries"][k] = \
                    CompiledLibrary.from_parse_dict(v)
    return ret
Exemple #7
0
    def test_extension_simple(self):
        self.top_node.make_node("foo.c").write(DUMMY_C % {"name": "foo"})

        builder = DistutilsBuilder()
        extension = Extension("foo", ["foo.c"])
        builder.build_extension(extension)
Exemple #8
0
        sources: src/dog.c
"""

PKG = PackageDescription(
    name="Sphinx",
    version="0.6.3",
    summary="Python documentation generator",
    url="http://sphinx.pocoo.org/",
    download_url="http://pypi.python.org/pypi/Sphinx",
    description="Some long description.",
    author="Georg Brandl",
    author_email="*****@*****.**",
    maintainer="Georg Brandl",
    maintainer_email="*****@*****.**",
    license="BSD",
    platforms=["any"],
    classifiers=[
        "Development Status :: 4 - Beta",
        "Environment :: Console",
        "Environment :: Web Environment",
        "Intended Audience :: Developers",
        "License :: OSI Approved :: BSD License",
        "Operating System :: OS Independent",
        "Programming Language :: Python",
        "Topic :: Documentation",
        "Topic :: Utilities",],
    py_modules=["cat.py"],
    packages=["sphinx", "sphinx.builders"],
    extensions={"_dog": Extension(name="_dog", sources=["src/dog.c"])},
)