Lint modeling, modular, and configuration files for Hugging Face Transformers structural conventions.
Project description
mlinter
A standalone linter for Hugging Face Transformers modeling files. It enforces structural conventions on every modeling_*.py, modular_*.py, and configuration_*.py file under src/transformers/models.
Installation
pip install git+https://github.com/huggingface/transformers-mlinter@main
When working on the transformers repo, mlinter is included in the quality extras:
pip install -e ".[quality]"
How rule registration works
- Rule metadata lives in
mlinter/rules.toml. - Executable TRF rules are auto-discovered from
trf*.pymodules in themlinter/package. - Each module must define a
check(tree, file_path, source_lines) -> list[Violation]function. - The module name determines the rule id:
trf003.py→TRF003. - A
RULE_IDmodule-level constant is set automatically by the discovery mechanism. - Every discovered rule must have a matching entry in the TOML file, and every TOML rule must have a matching module. Import-time validation fails if either side is missing.
- Suppressions use
# trf-ignore: TRFXXXon the same line or the line immediately above the flagged construct.
How to add a new TRF rule
- Add a
[rules.TRFXXX]entry tomlinter/rules.toml. - Fill in
description,default_enabled,explanation.what_it_does,explanation.why_bad, andexplanation.diff. Optional model-level exceptions go inallowlist_models. - Create a new module
mlinter/trfXXX.pywith acheck(tree, file_path, source_lines) -> list[Violation]function. - Use the
RULE_IDmodule constant instead of hardcoding"TRFXXX"inside the check. - Add or update focused tests in
tests/.
CLI usage
Run from the root of a transformers checkout:
# Check all modeling, modular, and configuration files
mlinter
# Only check files changed against a git base ref
mlinter --changed-only --base-ref origin/main
# List all available TRF rules and their default state
mlinter --list-rules
# Show the installed mlinter version
mlinter --version
# Show detailed documentation for one rule
mlinter --rule TRF001
# Enable additional rules on top of the defaults
mlinter --enable-rules TRF003
# Enable every TRF rule, including ones disabled by default
mlinter --enable-all-trf-rules
# Emit GitHub Actions error annotations
mlinter --github-annotations
When installed from a git checkout or a git+https://... URL, mlinter --version includes a short commit hash suffix such as 0.1.0+gabcdef1.
You can also invoke it as a Python module:
python -m mlinter
The lint cache is stored in the user cache directory instead of next to the installed package:
$XDG_CACHE_HOME/mlinter/.mlinter_cache.json on Linux, ~/Library/Caches/mlinter/.mlinter_cache.json on macOS, and %LOCALAPPDATA%\mlinter\.mlinter_cache.json on Windows.
Python API
Import the supported Python API from the package root:
from mlinter import TRF001, analyze_file, model_dir_name, render_rules_reference
mlinter.mlinter and mlinter._helpers are implementation modules and may change without a compatibility promise.
Development
git clone https://github.com/huggingface/transformers-mlinter
cd transformers-mlinter
pip install -e ".[dev]"
Run the tests:
pytest tests/
Releasing
See docs/release.md for the current release process.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file transformers_mlinter-0.1.0.tar.gz.
File metadata
- Download URL: transformers_mlinter-0.1.0.tar.gz
- Upload date:
- Size: 32.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b61594631584807299574434f75c5dfe5a8822057c3a425789a8c3466ceaaa5e
|
|
| MD5 |
99e4f5dcd5fb894fbeba498185cd09d7
|
|
| BLAKE2b-256 |
d8981eb2a13613ab3315dabe8870998c7f5815c5c7d19c59ad43d20db3972e3b
|
Provenance
The following attestation bundles were made for transformers_mlinter-0.1.0.tar.gz:
Publisher:
release.yml on huggingface/transformers-mlinter
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
transformers_mlinter-0.1.0.tar.gz -
Subject digest:
b61594631584807299574434f75c5dfe5a8822057c3a425789a8c3466ceaaa5e - Sigstore transparency entry: 1347936574
- Sigstore integration time:
-
Permalink:
huggingface/transformers-mlinter@6b66890cb322073515a98ec01e91a6533566bb06 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/huggingface
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@6b66890cb322073515a98ec01e91a6533566bb06 -
Trigger Event:
push
-
Statement type:
File details
Details for the file transformers_mlinter-0.1.0-py3-none-any.whl.
File metadata
- Download URL: transformers_mlinter-0.1.0-py3-none-any.whl
- Upload date:
- Size: 41.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
269a44c7122114640a52bb324aed909bc8333a77351be4e552b6dcc4f2e80266
|
|
| MD5 |
401e046c57b05cb4a74f188e62cabd76
|
|
| BLAKE2b-256 |
3390f991faaf451508bb648d0e0338cbb36bca720dec32a675540703cca12058
|
Provenance
The following attestation bundles were made for transformers_mlinter-0.1.0-py3-none-any.whl:
Publisher:
release.yml on huggingface/transformers-mlinter
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
transformers_mlinter-0.1.0-py3-none-any.whl -
Subject digest:
269a44c7122114640a52bb324aed909bc8333a77351be4e552b6dcc4f2e80266 - Sigstore transparency entry: 1347936585
- Sigstore integration time:
-
Permalink:
huggingface/transformers-mlinter@6b66890cb322073515a98ec01e91a6533566bb06 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/huggingface
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@6b66890cb322073515a98ec01e91a6533566bb06 -
Trigger Event:
push
-
Statement type: