Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 4 additions & 11 deletions .github/workflows/actions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,7 @@ jobs:
run: |
pip install -r requirements.txt --progress-bar off
pip install --no-deps -e "." --progress-bar off
- name: Lint
run: bash shell/lint.sh
- name: Check for API changes
run: |
bash shell/api_gen.sh
git status
clean=$(git status | grep "nothing to commit")
if [ -z "$clean" ]; then
echo "Please run shell/api_gen.sh to generate API."
exit 1
fi
- name: Install pre-commit
run: pip install pre-commit && pre-commit install
- name: Run pre-commit
run: pre-commit run --all-files --hook-stage manual
31 changes: 31 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
repos:
- repo: local
hooks:
- id: api-gen
name: api_gen
entry: |
bash shell/api_gen.sh
git status
clean=$(git status | grep "nothing to commit")
if [ -z "$clean" ]; then
echo "Please run shell/api_gen.sh to generate API."
exit 1
fi
language: system
stages: [pre-commit, manual]
require_serial: true
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.9.2
hooks:
- id: ruff
args: [--config, pyproject.toml, --fix, .]
stages: [pre-commit]
- id: ruff-format
args: [--config, pyproject.toml, .]
stages: [pre-commit]
- id: ruff
args: [--config, pyproject.toml, .]
stages: [manual]
- id: ruff-format
args: ["--check", --config, pyproject.toml, .]
stages: [manual]
35 changes: 19 additions & 16 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,15 +158,6 @@ This is automatically done if you clone using git inside WSL.
Note that will not support Windows Shell/PowerShell for any scripts in this
repository.

## Update Public API

Run API generation script when creating PRs that update `keras_hub_export`
public APIs. Add the files changed in `keras_hub/api` to the same PR.

```
./shell/api_gen.sh
```

## Testing changes

KerasHub is tested using [PyTest](https://docs.pytest.org/en/6.2.x/).
Expand Down Expand Up @@ -214,13 +205,25 @@ pytest --run_extra_large
When running "extra_large" tests, we recommend also specify a specific test file
so you aren't waiting around forever!

## Formatting Code
## Generating public API and formatting the code

KerasHub uses [Ruff](https://docs.astral.sh/ruff/) to format the code. You can
run `the following commands manually every time you want to format your code:
For the first time you are setting up the repo, please run `pre-commit install`.
Note that this needs to be done only once at the beginning.

- Run `shell/format.sh` to format your code
- Run `shell/lint.sh` to check the result.
Now, whenever you run `git commit -m "<message>"`, three things are
automatically done:

- Public API generation
- Code formatting
- Code linting

If there's any error, the commit will not go through. Please fix the error (
most of the times, the error is fixed automatically by the formatter/linter) and
re-run the following:

```
git add .
git commit -m "<message>" # This will not get logged as a duplicate commit.
```

If after running these the CI flow is still failing, try updating `ruff`
with `pip install --upgrade ruff`.
KerasHub uses [Ruff](https://docs.astral.sh/ruff/) to format the code.
3 changes: 3 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,7 @@ torchvision>=0.16.0
# Jax.
jax[cpu]

# pre-commit checks (formatting, linting, etc.)
pre-commit

-r requirements-common.txt
5 changes: 3 additions & 2 deletions shell/api_gen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ echo "Generating api directory with public APIs..."
# Generate API Files
python3 "${base_dir}"/api_gen.py

# Format code because `api_gen.py` might order
# imports differently.
echo "Formatting api directory..."
# Format API Files
bash "${base_dir}"/shell/format.sh
(SKIP=api-gen pre-commit run --files $(find "${base_dir}"/keras_hub/api -type f) --hook-stage pre-commit || true) > /dev/null
8 changes: 0 additions & 8 deletions shell/format.sh

This file was deleted.

11 changes: 0 additions & 11 deletions shell/lint.sh

This file was deleted.

Loading