Skip to content

feat: add ruff lint & pre-commit#313

Merged
imbajin merged 38 commits intoapache:mainfrom
hugegraph:feat/add-ruff-mypy
Nov 27, 2025
Merged

feat: add ruff lint & pre-commit#313
imbajin merged 38 commits intoapache:mainfrom
hugegraph:feat/add-ruff-mypy

Conversation

@fantasy-lotus
Copy link
Contributor

No description provided.

imbajin and others added 26 commits June 11, 2025 19:36
This workflow will be triggered when a pull request is opened. It will then post a comment "@codecov-ai-reviewer review" to help with automated AI code reviews.

It will use the `peter-evans/create-or-update-comment` action to create the comment.

Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
@dosubot dosubot bot added the size:XL This PR changes 500-999 lines, ignoring generated files. label Nov 25, 2025
fantasy-lotus and others added 5 commits November 26, 2025 17:25
- Add .pre-commit-config.yaml with ruff formatter and linter hooks
- Remove .pre-commit-config.yaml from .gitignore to track the configuration
- Include standard pre-commit hooks for code quality checks
Co-authored-by: Yan Chao Mei <1653720237@qq.com>
Co-authored-by: imbajin <jin@apache.org>
@fantasy-lotus fantasy-lotus changed the title feat: add ruff lint & format feat: add ruff lint & pre-commit Nov 26, 2025
Comment on lines 31 to 82
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: ["3.10", "3.11"]

steps:
- name: Prepare HugeGraph Server Environment
run: |
docker run -d --name=graph -p 8080:8080 -e PASSWORD=admin hugegraph/hugegraph:1.5.0
sleep 10

- uses: actions/checkout@v4

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

- name: Install uv
run: |
curl -LsSf https://astral.sh/uv/install.sh | sh
echo "$HOME/.cargo/bin" >> $GITHUB_PATH

- name: Cache dependencies
uses: actions/cache@v4
with:
path: |
~/.cache/uv
~/nltk_data
key: ${{ runner.os }}-uv-${{ matrix.python-version }}-${{ hashFiles('**/pyproject.toml', 'uv.lock') }}
restore-keys: |
${{ runner.os }}-uv-${{ matrix.python-version }}-

- name: Install dependencies
run: |
uv sync --extra llm --extra dev
uv run python -c "import nltk; nltk.download('stopwords'); nltk.download('punkt')"

- name: Run unit tests
working-directory: hugegraph-llm
env:
SKIP_EXTERNAL_SERVICES: true
run: |
uv run pytest src/tests/config/ src/tests/document/ src/tests/middleware/ src/tests/operators/ src/tests/models/ src/tests/indices/ src/tests/test_utils.py -v --tb=short

- name: Run integration tests
working-directory: hugegraph-llm
env:
SKIP_EXTERNAL_SERVICES: true
run: |
uv run pytest src/tests/integration/test_graph_rag_pipeline.py src/tests/integration/test_kg_construction.py src/tests/integration/test_rag_pipeline.py -v --tb=short

Check warning

Code scanning / CodeQL

Workflow does not contain permissions

Actions job or workflow does not limit the permissions of the GITHUB_TOKEN. Consider setting an explicit permissions block, using the following as a minimal starting point: {{contents: read}}
@@ -43,6 +43,9 @@ dev = [
"pytest~=8.0.0",
"pytest-cov~=5.0.0",
"pylint~=3.0.0",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ 建议:保留 pylint 或明确说明迁移计划

虽然 ruff 可以替代大部分 pylint 功能,但 pylint 仍然有一些独特的检查规则(如更深入的类型推断和复杂的代码分析)。当前配置同时保留了 pylint 和 ruff:

  1. 如果打算用 ruff 完全替代 pylint,建议在后续 PR 中移除 pylint 依赖
  2. 如果需要两者并存,建议在文档中说明各自的职责

另外,注意当前代码中还有大量 # pylint: disable=... 注释,迁移到 ruff 后这些注释将失效(不会报错但也不起作用)。

[tool.ruff.lint]
# Select a broad set of rules for comprehensive checks.
# E: pycodestyle Errors, F: Pyflakes, W: pycodestyle Warnings, I: isort
# C: flake8-comprehensions, N: pep8-naming
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Ruff 规则配置建议

当前配置选择了多个规则集,整体配置合理。有几点建议:

  1. T20 (flake8-print): 这个规则在生产代码中很有用,但注意当前只在测试文件和 examples 中忽略了它。如果项目其他地方有合法的 print 使用(如 CLI 工具输出),可能需要更多的豁免配置。

  2. C901 (complexity): 虽然暂时忽略了复杂度检查,建议后续通过重构逐步启用,这是代码质量的重要指标。

  3. 缺少 D (pydocstyle): 如果项目对文档字符串有要求,可以考虑启用。

  4. 缺少 S (flake8-bandit): 建议启用安全相关的检查,特别是对于处理用户输入的 LLM 项目。

# 可考虑添加的安全规则
select = [..., "S"]  # flake8-bandit for security


## 🚀 Quick Start

Choose your preferred deployment method:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

‼️ 潜在问题:hugegraph-llm 子目录的 README 中路径可能有问题

配置文件位于项目根目录 ../.pre-commit-config.yaml,但从 hugegraph-llm/ 子目录运行 pre-commit install 可能不会正确识别根目录的配置。

建议:

  1. 在文档中说明需要在项目根目录运行 pre-commit install
  2. 或者验证当前配置在子目录中也能正常工作

Replaced str() with !s in f-strings for more concise formatting in multiple modules. Updated type hints to use PEP 604 syntax (e.g., dict | None) where appropriate.

 Made minor improvements to logging, singleton pattern, and test error reporting. Updated ruff configuration to include RUF rules and added formatting options.
Replaced unused variables with underscores in BGNNPredictor and LinkPredictionPGNN to clarify intent and prevent linter warnings.
imbajin
imbajin previously approved these changes Nov 27, 2025
@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Nov 27, 2025
@imbajin imbajin merged commit 53a8255 into apache:main Nov 27, 2025
13 checks passed
fantasy-lotus added a commit to hugegraph/hugegraph-ai that referenced this pull request Nov 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request lgtm This PR has been approved by a maintainer llm ml python-client size:XL This PR changes 500-999 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants