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 从公开仓库中收录这些内容。

举报或申请下架