mcore-linting-and-formatting
NVIDIA/skills
ruff、black、isort、pylint、mypy を用いて Megatron-LM の Python コードのリンティングとフォーマットを行い、自動フォーマットおよびインポート順序付けのコマンドを提供する。
...すべて拡張しますリンティングとフォーマット
フォーマッターの実行
PR(プルリクエスト)の作成前に実行します:
# チェックモード(変更は適用されない)
BASE_REF=main CHECK_ONLY=true SKIP_DOCS=false bash tools/autoformat.sh
# 修正モード
BASE_REF=main CHECK_ONLY=false bash tools/autoformat.sh
呼び出されるツール:black、isort、pylint、ruff、mypy。
インポートの順序
Python ファイル内のインポートを編集した後、コミットする前に必ずそのファイルに対して uv run isort を実行してください:
uv run isort <file1>.py <file2>.py
</file2></file1>リンティンググループの設定
コンテナ内:
uv sync --locked --only-group linting
これにより、tools/autoformat.sh および CI の linting ジョブで使用されるのと同じツールである ruff、black、isort、pylint がインストールされます。
コードスタイルルール
- 型ヒント:すべての公開 API 関数に必須です。
Optional[X]ではなくX | Noneを使用してください。 - ドキュメント文字列:すべての公開クラスおよび関数に Google スタイルを使用します。
- 命名規則:Python の慣習に従ってください。関数および変数は
snake_case、クラスはPascalCaseとします。 - 行長:119 文字(
pyproject.tomlで設定済み)。 - 裸の
exceptは禁止:必ず特定の例外タイプをキャッチしてください。
---
name: mcore-linting-and-formatting
description: Lint and format Python code for Megatron-LM using ruff, black, isort, pylint, and mypy, with commands for autoformatting and import ordering.
license: Apache-2.0
---
# Linting and Formatting
---
## Running the Formatter
Run before opening a PR:
```bash
# Check mode (no changes applied)
BASE_REF=main CHECK_ONLY=true SKIP_DOCS=false bash tools/autoformat.sh
# Fix mode
BASE_REF=main CHECK_ONLY=false bash tools/autoformat.sh
```
Tools invoked: `black`, `isort`, `pylint`, `ruff`, `mypy`.
---
## Import Ordering
After editing imports in any Python files, always run `uv run isort` on those
files before committing:
```bash
uv run isort <file1>.py <file2>.py
```
---
## Setting Up the Linting Group
Inside the container:
```bash
uv sync --locked --only-group linting
```
This installs `ruff`, `black`, `isort`, `pylint` — the same tools used by
`tools/autoformat.sh` and CI's `linting` job.
---
## Code Style Rules
- **Type hints**: required on all public API functions. Use `X | None`, not `Optional[X]`.
- **Docstrings**: Google-style on all public classes and functions.
- **Naming**: follow Python conventions — `snake_case` for functions and variables, `PascalCase` for classes.
- **Line length**: 119 characters (configured in `pyproject.toml`).
- **No bare `except`**: always catch specific exception types.
mcore-linting-and-formattingをインストール
スキルファイルをダウンロードして .claude/skills/ ディレクトリに展開してください。
ZIPをダウンロードリポジトリをクローンし、スキルファイルをプロジェクトにコピーしてください。
git clone https://github.com/NVIDIA/skills/tree/main/skills/mcore-linting-and-formatting # Copy SKILL.md to your .claude/skills/ directory
コピー





家
