Beispiel #1
0
def combine_groups(data_files):
    """Given a list of tuple (target, files), combine files together per
    target/srcdir.
    
    Example
    -------
    
    data_files = [('foo', ['src/file1', 'src/file2'])]
    
    combine_groups returns:
        {'foo_src': {
            'target': 'foo',
            'srcdir': 'src',
            'files':
                ['file1', 'file2']}
        }.
    """

    ret = {}
    for e in data_files:
        # FIXME: install policies should not be handled here
        # FIXME: find the cases when entries' length are 2 vs 3 vs 4
        if len(e) == 2:
            target = posjoin("$sitedir", e[0])
            sources = e[1]
        elif len(e) == 3:
            target = posjoin("$prefix", e[1])
            sources = e[2]
        else:
            raise NotImplementedError("data files with >3 components not handled yet")

        for s in sources:
            srcdir = os.path.dirname(s)
            name = canonalize_path(os.path.basename(s))

            # Generate a unique key for target/source combination
            key = "%s_%s" % (target.replace(os.path.sep, "_"), srcdir.replace(os.path.sep, "_"))
            if ret.has_key(key):
                if not (ret[key]["srcdir"] == srcdir and ret[key]["target"] == target):
                    raise ValueError("BUG: mismatch for key %s ?" % key)
                ret[key]["files"].append(name)
            else:
                d = {}
                d["srcdir"] = srcdir
                d["target"] = target
                d["files"] = [name]
                ret[key] = d

    return ret
Beispiel #2
0
def canonalize_path(path):
    """Convert a win32 path to unix path."""
    if os.path.sep == "/":
        return path
    head, tail = ntsplit(path)
    lst = [tail]
    while head and tail:
        head, tail = ntsplit(head)
        lst.insert(0, tail)
    lst.insert(0, head)

    return posjoin(*lst)
Beispiel #3
0
def build_pkg(dist, live_objects):
    pkg = distutils_to_package_description(dist)
    modules = []
    for m in pkg.py_modules:
        if isinstance(m, basestring):
            modules.append(m)
        else:
            warnings.warn("The module %s it not understood" % str(m))
    pkg.py_modules = modules

    path_options = []
    pkg.data_files = {}
    if live_objects["package_data"]:
        gendatafiles = {}
        for d in live_objects["package_data"]:
            if len(d["files"]) > 0:
                name = "gendata_%s" % d["target"].replace(os.path.sep, "_")
                gendatafiles[name] = {
                    "srcdir": canonalize_path(d["srcdir"]),
                    "target": posjoin("$gendatadir", canonalize_path(d["target"])),
                    "files": [canonalize_path(f) for f in d["files"]]
                }
        path_options.append(PathOption("gendatadir", "$sitedir",
                "Directory for datafiles obtained from distutils conversion"
                ))
        pkg.data_files.update(gendatafiles)

    extra_source_files = []
    if live_objects["extra_data"]:
        extra_source_files.extend([canonalize_path(f) 
                                  for f in live_objects["extra_data"]])
    pkg.extra_source_files = sorted(prune_extra_files(extra_source_files, pkg))

    if live_objects["data_files"]:
        pkg.data_files = combine_groups(live_objects["data_files"])

    # numpy.distutils bug: packages are appended twice to the Distribution
    # instance, so we prune the list here
    pkg.packages = sorted(list(set(pkg.packages)))
    options = {"path_options": path_options}
    
    return pkg, options