mirror of
https://github.com/davidhalter/typeshed.git
synced 2025-12-09 21:46:42 +08:00
check_consistent.py: ignore .gitignored files (#8804)
This commit is contained in:
@@ -6,6 +6,7 @@ from functools import cache
|
||||
from pathlib import Path
|
||||
from typing import NamedTuple
|
||||
|
||||
import pathspec # type: ignore[import]
|
||||
import tomli
|
||||
|
||||
|
||||
@@ -81,3 +82,21 @@ def get_all_testcase_directories() -> list[PackageInfo]:
|
||||
if potential_testcase_dir.is_dir():
|
||||
testcase_directories.append(PackageInfo(package_name, potential_testcase_dir))
|
||||
return sorted(testcase_directories)
|
||||
|
||||
|
||||
# ====================================================================
|
||||
# Parsing .gitignore
|
||||
# ====================================================================
|
||||
|
||||
|
||||
@cache
|
||||
def get_gitignore_spec() -> pathspec.PathSpec:
|
||||
with open(".gitignore") as f:
|
||||
return pathspec.PathSpec.from_lines("gitwildmatch", f.readlines())
|
||||
|
||||
|
||||
def spec_matches_path(spec: pathspec.PathSpec, path: Path) -> bool:
|
||||
normalized_path = path.as_posix()
|
||||
if path.is_dir():
|
||||
normalized_path += "/"
|
||||
return spec.match_file(normalized_path) # type: ignore[no-any-return]
|
||||
|
||||
Reference in New Issue
Block a user