repomatic.file_inventory module¶
What files this repository contains, honoring .gitignore and .git/info/exclude.
One question, asked in one place: every “which files are the Python sources /
the workflows / the images” lookup routes through FileInventory, whose
glob_files() resolves symlinks, drops broken ones and
filters out anything those two files exclude. The results are the lists CI jobs
gate on, so a job that formats Markdown and one that lints it see the same
files.
Kept apart from repomatic.metadata.core.Metadata, which reaches CI
context, git history and pyproject.toml: none of that is needed to answer
“what is on disk here”.
Todo
Drop the py-walk dependency and parse .gitignore with wcmatch, already
imported here for globbing, once it reads gitignore files natively:
facelessuser/wcmatch#226.
Pick another parser first if
pacha/py-walk#11 ends with
py-walk retired: sly, its only dependency, already is.
- repomatic.file_inventory.EXCLUDE_GIT_PATH = PosixPath('info/exclude')¶
Path of the repository’s exclude file, inside its git directory.
Git reads its rules beside those of
.gitignore, but no commit carries the file: it holds the ignore rules of one checkout. A.claude/worktrees/entry there keeps the files of an agent’s worktree out of the inventory of the checkout that holds it.FileInventory.exclude_pathfinds the file in a linked worktree too, where git keeps it in the main checkout.The inventory reads no other ignore file. It skips the
.gitignoreof each subdirectory. It also skips the user’score.excludesFile, which applies to every repository of the user. A rule there can match a file that one repository tracks: git keeps a tracked file, but the inventory would drop it.
- repomatic.file_inventory.GITIGNORE_PATH = PosixPath('.gitignore')¶
Path of the
.gitignorefile whose rules filter every inventory lookup.Fixed at the repository root, unlike the configurable
[tool.repomatic.gitignore] locationthatsync-gitignorewrites: the glob filter has to match what git itself honors, and git reads the root.gitignorefrom this path alone.
- class repomatic.file_inventory.FileInventory[source]¶
Bases:
objectThe repository’s files, grouped by what a job needs to act on them.
Each group is a cached property, so a command asking for the Markdown files twice walks the tree once. Instantiate per working directory: the lookups resolve against the current directory at call time.
- property exclude_path: Path | None[source]¶
Returns the path of the repository’s exclude file, read off the disk.
.gitis a directory in a plain checkout. In a linked worktree,.gitis a file that names the git directory of the worktree, and thecommondirfile there points to the git directory of the main checkout, which holds the exclude file of every worktree.The property reads the layout instead of running git rev-parse –git-path: a lookup then works without git, and starts no process.
- property gitignore_parser: Parser | None[source]¶
Returns a parser for the rules of
.gitignoreand the exclude file.The exclude rules go first. Git lets a
.gitignorerule override an exclude rule, and the parser lets a later rule override an earlier one, so this order keeps the precedence of git. SeeEXCLUDE_GIT_PATH.Each file is decoded here, as UTF-8.
get_parser_from_fileof py-walk decodes it with the locale encoding, so a pattern with a non-ASCII character misses its path on a machine whose locale is not UTF-8.
- glob_files(*patterns)[source]¶
Return all file path matching the
patterns.Patterns are glob patterns supporting
**for recursive search, and!for negation, resolved against the current working directory: they select from one shared walk of it (see_all_files), so an absolute pattern matches nothing.All directories are traversed, whether they are hidden (i.e. starting with a dot
.) or not, including symlinks.Skips:
files which does not exists
directories
broken symlinks
files matching patterns specified by
.gitignoreor the exclude file
Returns both hidden and non-hidden files.
All files are normalized to their absolute path, so that duplicates produced by symlinks are ignored.
File path are returned as relative to the current working directory if possible, or as absolute path otherwise.
The resulting list of file paths is sorted.
- property json_files: list[Path][source]¶
Returns a list of JSON files.
Note
JSON5 files are excluded because Biome doesn’t support them.
- property image_files: list[Path][source]¶
Returns a list of image files.
Covers the formats handled by
repomatic format-images: JPEG, PNG, WebP, and AVIF. Seerepomatic.imagesfor the optimization tools.
- shebang_names_zsh(path)[source]¶
Whether path opens with a shebang line naming zsh.
The
.shextension is ambiguous: it says POSIX shell while the shebang picks the actual interpreter. Reading that first line is what keepsshfmt_filesandzsh_filesdisjoint, so a bash script is never handed to the Zsh linter and a zsh script is never handed toshfmt. Verdicts are memoized per inventory (see_zsh_shebangs).
- property shfmt_files: list[Path][source]¶
Returns a list of shell files that
shfmtcan reliably format.shfmtsupports the following dialects (-lnflag):bash: GNU Bourne Again Shell.
posix: POSIX Shell (
/bin/sh).mksh: MirBSD Korn Shell.
bats: Bash Automated Testing System.
Zsh is excluded.
shfmtadded experimental Zsh support in v3.13.0 but it fails on common constructs:for var (list)short-form loops andfor ... { }brace-delimited loops.Files are excluded by extension (
.zsh,.zshrc, etc.) and by shebang (any.shfile whose first line referenceszsh).ShellCheck lints the same list: it does not support Zsh either.
Todo
Stop excluding Zsh once
shfmtformats those constructs: mvdan/sh#1203. Give theshellcheckregistry entry a file list of its own in the same change, which keeps the Zsh files out.
- property zsh_files: list[Path][source]¶
Returns a list of Zsh files.
The
.zshextension and the zsh dotfiles are unambiguous. A.shfile joins the list only when its shebang names zsh: matching the extension alone would claim every bash script in the repository, and the Zsh lint job would then runzsh --no-execover scriptsshfmtis formatting as bash. Seeshebang_names_zsh().