def build_pkg(dist, package_objects, top_node): 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 = [] data_sections = {} extra_source_files = [] if package_objects.extra_source_files: extra_source_files.extend( [canonalize_path(f) for f in package_objects.extra_source_files]) for pkg_name, source_dir, target_dir, files in package_objects.iter_data_files( top_node): if len(files) > 0: if len(pkg_name) > 0: name = "%s_data" % pkg_name.replace(".", "_") else: name = "dist_data" source_dir = canonalize_path(source_dir) target_dir = canonalize_path(target_dir) files = [canonalize_path(f) for f in files] data_sections[name] = DataFiles(name, files, target_dir, source_dir) pkg.data_files.update(data_sections) if dist.scripts: name = "%s_scripts" % pkg.name target_dir = "$bindir" pkg.data_files[name] = DataFiles(name, dist.scripts, target_dir, ".") # 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} pkg.extra_source_files = sorted( prune_extra_files(extra_source_files, pkg, top_node)) return pkg, options
def _assert_archive_equality(self, archive, r_archive_list): r_archive_list = set(canonalize_path(f) for f in r_archive_list) archive = self.run_node.find_node(archive) z = zipfile.ZipFile(archive.abspath(), "r") try: archive_list = set(z.namelist()) self.assertEqual(archive_list, r_archive_list) finally: z.close()
def build_pkg(dist, package_objects, top_node): 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 = [] data_sections = {} extra_source_files = [] if package_objects.extra_source_files: extra_source_files.extend([canonalize_path(f) for f in package_objects.extra_source_files]) for pkg_name, source_dir, target_dir, files in package_objects.iter_data_files(top_node): if len(files) > 0: if len(pkg_name) > 0: name = "%s_data" % pkg_name.replace(".", "_") else: name = "dist_data" source_dir = canonalize_path(source_dir) target_dir = canonalize_path(target_dir) files = [canonalize_path(f) for f in files] data_sections[name] = DataFiles(name, files, target_dir, source_dir) pkg.data_files.update(data_sections) if dist.scripts: name = "%s_scripts" % pkg.name target_dir = "$bindir" pkg.data_files[name] = DataFiles(name, dist.scripts, target_dir, ".") # 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} pkg.extra_source_files = sorted(prune_extra_files(extra_source_files, pkg, top_node)) return pkg, options
def prune_extra_files(files, pkg, top_node): package_files = [] for p in pkg.packages: package_files.extend(find_package(p, top_node)) package_files = [canonalize_path(f) for f in package_files] data_files = [] for data_section in pkg.data_files.values(): data_files.extend([posixpath.join(data_section.source_dir, f) for f in data_section.files]) redundant = package_files + data_files + pkg.py_modules return prune_file_list(files, redundant)
def prune_extra_files(files, pkg, top_node): package_files = [] for p in pkg.packages: package_files.extend(find_package(p, top_node)) package_files = [canonalize_path(f) for f in package_files] data_files = [] for data_section in pkg.data_files.values(): data_files.extend([ posixpath.join(data_section.source_dir, f) for f in data_section.files ]) redundant = package_files + data_files + pkg.py_modules return prune_file_list(files, redundant)
def _convert_numpy_data_files(top_node, source_dir, files): """Convert data_files pairs to the common format we use. numpy.distutils internally keeps data as a pair (package_path, files_list), where files_list is relative to the top source path. We convert this Parameters ---------- top_node: node top directory of the source tree (as a node). source_dir: str the source directory (as a path string, relative to top node). files: seq list of files (relative to top source) Returns ------- pkg_name: str name of the package source_dir: str source directory target_dir: str target directory files: seq list of files (relative to source directory) """ source_node = top_node.find_node(source_dir) if source_node is None: raise ConvertionError("directory %r not found" % source_dir) nodes = [] for f in files: node = top_node.find_node(f) if node is None: raise ConvertionError("file %s refered in data_files not found" % f) nodes.append(node) pkg_name = canonalized_path_to_package(source_dir) target_dir = canonalize_path(op.join("$sitedir", source_dir)) return pkg_name, source_dir, target_dir, [ node.path_from(source_node) for node in nodes ]
def _convert_numpy_data_files(top_node, source_dir, files): """Convert data_files pairs to the common format we use. numpy.distutils internally keeps data as a pair (package_path, files_list), where files_list is relative to the top source path. We convert this Parameters ---------- top_node: node top directory of the source tree (as a node). source_dir: str the source directory (as a path string, relative to top node). files: seq list of files (relative to top source) Returns ------- pkg_name: str name of the package source_dir: str source directory target_dir: str target directory files: seq list of files (relative to source directory) """ source_node = top_node.find_node(source_dir) if source_node is None: raise ConvertionError("directory %r not found" % source_dir) nodes = [] for f in files: node = top_node.find_node(f) if node is None: raise ConvertionError("file %s refered in data_files not found" % f) nodes.append(node) pkg_name = canonalized_path_to_package(source_dir) target_dir = canonalize_path(op.join("$sitedir", source_dir)) return pkg_name, source_dir, target_dir, [node.path_from(source_node) for node in nodes]
def test_simple(self): self.assertEqual(canonalize_path(r"foo\bar"), "foo/bar")