示例#1
0
def filter_paths(ctx, raw_paths, path_type="repo", **kwds):
    """Filter ``paths``.

    ``path_type`` is ``repo`` or ``file``.
    """
    cwd = os.getcwd()

    filter_kwds = copy.deepcopy(kwds)
    changed_in_commit_range = kwds.get("changed_in_commit_range", None)
    diff_paths = None
    if changed_in_commit_range is not None:
        diff_files = git.diff(ctx, cwd, changed_in_commit_range)
        if path_type == "repo":
            diff_dirs = set(os.path.dirname(p) for p in diff_files)
            diff_paths = set()
            for diff_dir in diff_dirs:
                while diff_dir:
                    if os.path.isfile(os.path.join(diff_dir,
                                                   SHED_CONFIG_NAME)):
                        diff_paths.add(diff_dir)
                        break
                    diff_dir = os.path.dirname(diff_dir)
        else:
            diff_paths = diff_files

    unique_paths = set(os.path.relpath(p, cwd) for p in raw_paths)
    if diff_paths is not None:
        new_unique_paths = []
        for path in unique_paths:
            if path in diff_paths:
                new_unique_paths.append(path)
        unique_paths = new_unique_paths
    filtered_paths = sorted(
        io.filter_paths(unique_paths, cwd=cwd, **filter_kwds))
    excluded_paths = sorted(set(unique_paths) - set(filtered_paths))
    if excluded_paths:
        ctx.log("List of excluded paths: %s" % excluded_paths)

    path_count = len(filtered_paths)
    chunk_size = ((1.0 * path_count) / kwds["chunk_count"])
    chunk = kwds["chunk"]

    chunked_paths = []
    for i, path in enumerate(filtered_paths):
        if int(math.floor(i / chunk_size)) == chunk:
            chunked_paths.append(path)

    return chunked_paths
示例#2
0
def filter_paths(ctx, raw_paths, path_type="repo", **kwds):
    """Filter ``paths``.

    ``path_type`` is ``repo`` or ``file``.
    """
    cwd = os.getcwd()

    filter_kwds = copy.deepcopy(kwds)
    changed_in_commit_range = kwds.get("changed_in_commit_range", None)
    diff_paths = None
    if changed_in_commit_range is not None:
        diff_files = git.diff(ctx, cwd, changed_in_commit_range)
        if path_type == "repo":
            diff_dirs = set(os.path.dirname(p) for p in diff_files)
            diff_paths = set()
            for diff_dir in diff_dirs:
                while diff_dir:
                    if os.path.isfile(os.path.join(diff_dir, SHED_CONFIG_NAME)):
                        diff_paths.add(diff_dir)
                        break
                    diff_dir = os.path.dirname(diff_dir)
        else:
            diff_paths = diff_files

    unique_paths = set(os.path.relpath(p, cwd) for p in raw_paths)
    if diff_paths is not None:
        new_unique_paths = []
        for path in unique_paths:
            if path in diff_paths:
                new_unique_paths.append(path)
        unique_paths = new_unique_paths
    filtered_paths = sorted(io.filter_paths(unique_paths, cwd=cwd, **filter_kwds))
    excluded_paths = sorted(set(unique_paths) - set(filtered_paths))
    if excluded_paths:
        ctx.log("List of excluded paths: %s" % excluded_paths)

    path_count = len(filtered_paths)
    chunk_size = ((1.0 * path_count) / kwds["chunk_count"])
    chunk = kwds["chunk"]

    chunked_paths = []
    for i, path in enumerate(filtered_paths):
        if int(math.floor(i / chunk_size)) == chunk:
            chunked_paths.append(path)

    return chunked_paths
示例#3
0
def filter_paths(ctx, raw_paths, path_type="dir", **kwds):
    """Filter ``paths``.

    ``path_type`` is ``dir`` or ``file``.
    """
    cwd = os.getcwd()

    filter_kwds = copy.deepcopy(kwds)
    changed_in_commit_range = kwds.get("changed_in_commit_range", None)
    diff_paths = None
    if changed_in_commit_range is not None:
        diff_files = git.diff(ctx, cwd, changed_in_commit_range)
        if path_type == "dir":
            diff_paths = [os.path.dirname(p) for p in diff_files]
        else:
            diff_paths = diff_files
        diff_paths = sorted(set(diff_paths))

    unique_paths = sorted(
        set(map(lambda p: os.path.relpath(p, cwd), raw_paths)))
    filtered_paths = io.filter_paths(unique_paths, cwd=cwd, **filter_kwds)
    if diff_paths is not None:
        new_filtered_paths = []
        for path in filtered_paths:
            if path in diff_paths:
                new_filtered_paths.append(path)

        filtered_paths = new_filtered_paths

    path_count = len(filtered_paths)
    chunk_size = ((1.0 * path_count) / kwds["chunk_count"])
    chunk = kwds["chunk"]

    chunked_paths = []
    for i, path in enumerate(filtered_paths):
        if int(math.floor(i / chunk_size)) == chunk:
            chunked_paths.append(path)

    return chunked_paths
示例#4
0
 def assert_filtered_is(paths, expected, **kwds):
     result = io.filter_paths(paths, cwd=test_cwd, **kwds)
     assert result == expected, "paths [%s] arent't expected [%s]" % (
         result, expected)
示例#5
0
 def assert_filtered_is(paths, expected, **kwds):
     result = io.filter_paths(paths, cwd=test_cwd, **kwds)
     assert result == expected, "paths [%s] arent't expected [%s]" % (result, expected)