MCPcopy
hub / github.com/python/mypy / find_gitignores

Function find_gitignores

mypy/modulefinder.py:727–751  ·  view source on GitHub ↗
(dir: str)

Source from the content-addressed store, hash-verified

725
726@functools.lru_cache
727def find_gitignores(dir: str) -> list[tuple[str, GitIgnoreSpec]]:
728 parent_dir = os.path.dirname(dir)
729 if parent_dir == dir or os.path.exists(os.path.join(dir, ".git")):
730 parent_gitignores = []
731 git_info_exclude = os.path.join(dir, ".git", "info", "exclude")
732 if os.path.isfile(git_info_exclude):
733 with open(git_info_exclude) as f:
734 exclude_lines = f.readlines()
735 try:
736 parent_gitignores = [(dir, GitIgnoreSpec.from_lines("gitignore", exclude_lines))]
737 except GitIgnorePatternError:
738 print(f"error: could not parse {git_info_exclude}", file=sys.stderr)
739 else:
740 parent_gitignores = find_gitignores(parent_dir)
741
742 gitignore = os.path.join(dir, ".gitignore")
743 if os.path.isfile(gitignore):
744 with open(gitignore) as f:
745 lines = f.readlines()
746 try:
747 return parent_gitignores + [(dir, GitIgnoreSpec.from_lines("gitignore", lines))]
748 except GitIgnorePatternError:
749 print(f"error: could not parse {gitignore}", file=sys.stderr)
750 return parent_gitignores
751 return parent_gitignores
752
753
754def is_init_file(path: str) -> bool:

Callers 1

matches_gitignoreFunction · 0.85

Calls 5

printFunction · 0.85
existsMethod · 0.80
readlinesMethod · 0.80
joinMethod · 0.45
isfileMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…