Mcore Linting And Formatting

nvidia/skills/skills/mcore-linting-and-formatting

作者 nvidiacf5224d14250Apache-2.03.5K 個星標收錄於 2026年10月8日更新於 2026年10月8日儲存庫今天更新

Linting and formatting for Megatron-LM. Covers running autoformat.sh, tools (ruff, black, isort, pylint, mypy), and code style rules.

AI 產生的概覽

指導 Megatron-LM 的程式碼檢查與格式化,涵蓋 autoformat.sh、ruff、black、isort、pylint、mypy 及風格規則。

功能
此技能說明如何為 Megatron-LM 程式庫執行程式碼檢查與格式化。它介紹以檢查模式或修正模式呼叫 tools/autoformat.sh、對修改過的檔案執行 isort,以及用 uv sync 安裝 linting 相依群組。它也列出程式碼風格規則,例如型別註解、Google 風格文件字串、命名慣例、119 字元行寬,以及避免裸 except 子句。
適用情境
適用於執行程式碼檢查或自動格式化、在提交拉取請求前修正風格違規,或排查 pre-commit、ruff、isort、mypy、autoformat.sh 錯誤的情況。
執行需求
僅為說明文件,不附帶指令碼。需要 Megatron-LM 程式庫(含 tools/autoformat.sh 與 pyproject.toml),以及 black、isort、pylint、ruff、mypy 等檢查工具,通常透過容器內的 uv sync --locked --only-group linting 安裝。

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 modeBASE_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.

來源與署名

來源:nvidia/skills位於skills/mcore-linting-and-formatting提交cf5224d

授權條款: Apache-2.0

內容歸原作者所有。SourceWeft 從公開儲存庫中收錄這些內容。

檢舉或申請下架