repomatic.file_inventory module¶
What files this repository contains, honoring .gitignore.
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 .gitignore excludes. The results are the lists CI jobs
gate on, so a job that formats Markdown and one that lints it see the same
files.
Split out of 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”, and Metadata keeps the family reachable under its own names for
every existing caller.
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.
- 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 only reads this path.
- 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 gitignore_parser: Parser | None[source]¶
Returns a parser for the
.gitignorefile, if it exists.
- 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
.gitignorefile
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).Todo
Stop excluding Zsh once
shfmtformats those constructs: mvdan/sh#1203.
- 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().