How to use the pathspec.patterns function in pathspec

To help you get started, we’ve selected a few pathspec examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github khalim19 / gimp-plugin-export-layers / utils / View on Github external
def _get_filtered_filepaths(dirpath, pattern_filepath):
  with, "r", encoding=pg.TEXT_FILE_ENCODING) as file_:
    spec_obj = pathspec.PathSpec.from_lines(
      pathspec.patterns.gitwildmatch.GitWildMatchPattern, file_)
  return [os.path.join(dirpath, match) for match in spec_obj.match_tree(dirpath)]
github catalyst-team / mlcomp / mlcomp / utils / View on Github external
def find_imports(
    path: str,
    files: List[str] = None,
    exclude_patterns: List[str] = None,
    res = []
    raw_imports = []
    files = files if files is not None \
        else glob(os.path.join(path, '**', '*.py'), recursive=True)

    exclude_patterns = exclude_patterns \
        if exclude_patterns is not None else []
    spec = pathspec.PathSpec.from_lines(
        pathspec.patterns.GitWildMatchPattern, exclude_patterns

    for file in files:
        if not file.endswith('.py'):
        file_rel = os.path.relpath(file, path)
        if spec.match_file(file_rel):

        with open(file, 'r', encoding=encoding) as f:
            content =
                tree = ast.parse(content)
                for node in ast.walk(tree):
                    if isinstance(node, ast.Import):
                        for subnode in node.names:
github catalyst-team / mlcomp / mlcomp / worker / View on Github external
def _build_spec(self, folder: str):
        ignore_file = os.path.join(folder, 'file.ignore.txt')
        if not os.path.exists(ignore_file):
            ignore_patterns = []
            ignore_patterns = read_lines(ignore_file)
        ignore_patterns.extend(['log', 'data', 'models', '__pycache__'])

        return pathspec.PathSpec.from_lines(
            pathspec.patterns.GitWildMatchPattern, ignore_patterns
github dryan / d3ploy / d3ploy / View on Github external
def determine_files_to_sync(
    local_path, excludes=[], gitignore=False,
    if isinstance(excludes, str):
        excludes = [excludes]
    gitignore_patterns = list(map(pathspec.patterns.GitWildMatchPattern, excludes))
    svc_directories = [".git", ".svn"]
    if gitignore:
        gitignores = []
        if os.path.exists(".gitignore"):
        for root, dir_names, file_names in os.walk(local_path):
            for dir_name in dir_names:
                if dir_name in svc_directories:
                dir_name = os.path.join(root, dir_name)
                gitignore_path = os.path.join(dir_name, ".gitignore")
                if os.path.exists(gitignore_path):
            for file_name in file_names:
                if file_name == ".gitignore":
                    gitignore_path = os.path.join(root, file_name)
github MichaelAquilina / S4 / s4 / clients / View on Github external
def traverse(path, ignore_files=None):
    if not os.path.exists(path):
    if ignore_files is None:
        ignore_files = []

    for item in scandir(path):
        full_path = os.path.join(path,
        spec = pathspec.PathSpec.from_lines(
            pathspec.patterns.GitWildMatchPattern, ignore_files
        if spec.match_file(full_path):
            logger.debug("Ignoring %s", item)

        if item.is_dir():
            for result in traverse(item.path, ignore_files):
                yield os.path.join(, result)