选项
首页首页 Skill 开发者工具 mcore-linting-and-formatting

mcore-linting-and-formatting

NVIDIA/skills NVIDIA/skills

使用 ruff、black、isort、pylint 和 mypy 对 Megatron-LM 的 Python 代码进行 Lint 和格式化,并提供自动格式化和导入排序的命令。

...展开全部
0
更新时间 2026-09-27

代码检查与格式化

运行格式化工具

在提交拉取请求(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

这将安装 ruff、black、isort、pylint —— 与 tools/autoformat.sh 和 CI 的 linting 作业所使用的工具相同。

代码风格规则

  • 类型提示:所有公共 API 函数必须包含类型提示。使用 X | None,而非 Optional[X]。
  • 文档字符串:所有公共类和函数均采用 Google 风格。
  • 命名规范:遵循 Python 惯例 —— 函数和变量使用 snake_case,类使用 PascalCase。
  • 行长度:119 个字符(在 pyproject.toml 中配置)。
  • 禁止裸 except:必须始终捕获特定的异常类型。
在 GitHub 上查看
---
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

复制 复制
快速设置: 将技能文件夹复制到 .claude/skills/ 目录。Claude 将自动检测并使用该技能。
仓库 NVIDIA/skills

相关技能

algorithmic-art
更新时间 2026-08-27
systematic-debugging
更新时间 2026-09-03
tech-debt-tracker
更新时间 2026-08-29
continual-learning
更新时间 2026-09-10
OR