選項
首頁首頁 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