-
Notifications
You must be signed in to change notification settings - Fork 595
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
enable pre-commit #452
Open
antoinejeannot
wants to merge
1
commit into
huggingface:main
Choose a base branch
from
antoinejeannot:pre-commit
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+56
−54
Open
enable pre-commit #452
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,26 +5,9 @@ on: [pull_request] | |
jobs: | ||
check_code_quality: | ||
runs-on: ubuntu-latest | ||
env: | ||
UV_HTTP_TIMEOUT: 600 # max 10min to install deps | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Set up Python | ||
uses: actions/setup-python@v2 | ||
- uses: actions/checkout@v4 | ||
- uses: actions/setup-python@v5 | ||
with: | ||
python-version: "3.12" | ||
|
||
# Setup venv | ||
- name: Setup venv + uv | ||
run: | | ||
pip install --upgrade uv | ||
uv venv | ||
|
||
- name: Install dependencies | ||
run: uv pip install "smolagents[quality] @ ." | ||
|
||
# Equivalent of "make quality" but step by step | ||
- run: uv run ruff check examples src tests utils # linter | ||
- run: uv run ruff format --check examples src tests utils # formatter | ||
- run: uv run python utils/check_tests_in_ci.py | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Now a |
||
python-version: "3.10" # lower bound of the supported Python versions | ||
- uses: pre-commit/[email protected] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this action uses some caching under the hood, which speeds up ci actions |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,26 @@ | ||
repos: | ||
- repo: https://github.com/pre-commit/pre-commit-hooks | ||
rev: v5.0.0 | ||
hooks: | ||
- id: check-merge-conflict | ||
- id: check-yaml | ||
- id: debug-statements | ||
|
||
- repo: https://github.com/astral-sh/ruff-pre-commit | ||
rev: v0.2.1 | ||
rev: v0.9.4 | ||
hooks: | ||
- id: ruff | ||
args: | ||
- --fix | ||
- id: ruff-format | ||
- repo: https://github.com/pre-commit/pre-commit-hooks | ||
rev: v4.5.0 | ||
|
||
- repo: local | ||
hooks: | ||
- id: check-merge-conflict | ||
- id: check-yaml | ||
- id: check-tests-in-ci | ||
name: check tests listed in ci | ||
entry: .pre-commit-hooks/check_tests_in_ci.py | ||
language: python | ||
always_run: true | ||
pass_filenames: false | ||
types: [python, yaml] | ||
files: ^tests/.*\.py$|^\.github/workflows/tests\.yml$ |
1 change: 1 addition & 0 deletions
1
utils/check_tests_in_ci.py → .pre-commit-hooks/check_tests_in_ci.py
100644 → 100755
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
#!/usr/bin/env python3 | ||
# coding=utf-8 | ||
# Copyright 2025-present, the HuggingFace Inc. team. | ||
# | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,18 @@ | ||
.PHONY: quality style test docs utils | ||
.PHONY: quality style test | ||
|
||
check_dirs := examples src tests utils | ||
# quality and style targets are redundant | ||
# they are kept not to introduce a breaking change in users' workflows. | ||
# though style target is being deprecated and will be removed in the future. | ||
|
||
# Check code quality of the source code | ||
quality: | ||
ruff check $(check_dirs) | ||
ruff format --check $(check_dirs) | ||
python utils/check_tests_in_ci.py | ||
pre-commit run --all-files --show-diff-on-failure --color always | ||
|
||
# Format source code automatically | ||
style: | ||
ruff check $(check_dirs) --fix | ||
ruff format $(check_dirs) | ||
pre-commit run --all-files --show-diff-on-failure --color always | ||
echo "\nDeprecated target. Use 'make quality' instead." | ||
|
||
# Run smolagents tests | ||
test: | ||
pytest ./tests/ | ||
pytest |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pre-commit manages its own isolated venv, hence no more env management.
Also no need to install
smolagents
for lint & formating, onlypre-commit
andruff
are needed