$ show pre-commit/identify
identify is a Python library for file identification that returns standardized tags based on file type, executability, content, extension, filename, or shebang. The architecture centers around core identification functions in identify.py, supported by extension and interpreter mappings in extensions.py and interpreters.py. Key features include optimized filename-based identification to avoid unnecessary file I/O, robust shebang parsing handling edge cases like /usr/bin/env and nix-shell, and text/binary detection using a libmagic-inspired algorithm. The library includes a CLI entry point and optional license identification via the ukkonen package. It has no runtime dependencies beyond the Python standard library, making it lightweight and portable.
The LLM identified 2 files worth highlighting for reuse:
The is_text function detects whether a file is text or binary by examining the first 1024 bytes for non-text characters, based on libmagic's algorithm. It is self-contained, requires only the standard library, and can be reused in any project needing to distinguish text from binary files without external dependencies.
The parse_shebang function (with helpers _shebang_split and _parse_nix_shebang) robustly extracts interpreters from shebang lines, handling edge cases like quoted paths, /usr/bin/env with -S flag, and nix-shell shebangs. It is self-contained, relies only on standard library modules, and can be extracted for use in any project that needs to interpret shebangs from executable files.