Skip to content

Commit

Permalink
Merge pull request optuna#5408 from HideakiImamura/add-pre-commit-config
Browse files Browse the repository at this point in the history
Add pre-commit config
  • Loading branch information
not522 authored Oct 16, 2024
2 parents 3e31e8d + 0d7fb5a commit 2f9cc79
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 3 deletions.
60 changes: 60 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# pre-commit package installation is necessary to use pre-commit.
# $ pip install pre-commit
# $ pre-commit install

default_language_version:
python: python3

repos:
# Args are based on setup.cfg.
- repo: https://github.com/psf/black
rev: 24.8.0
hooks:
- id: black
- repo: https://github.com/pycqa/flake8
rev: 7.1.1
hooks:
- id: flake8
exclude: tutorial|docs/visualization_examples|docs/visualization_matplotlib_examples
args: [
"--max-line-length=99",
"--ignore=E203,E704,W503",
"--statistics",
]
- repo: https://github.com/pycqa/isort
rev: 5.13.2
hooks:
- id: isort
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.11.2
hooks:
- id: mypy
additional_dependencies: [
"alembic>=1.5.0",
"colorlog",
"numpy",
"packaging>=20.0",
"sqlalchemy>=1.3.0",
"tqdm",
"PyYAML",
"mypy_boto3_s3",
"types-PyYAML",
"types-redis",
"types-setuptools",
"types-tqdm",
"typing_extensions>=3.10.0.0",
]
exclude: docs|tutorial|optuna/storages/_rdb/alembic
args: [
--warn-unused-configs,
--disallow-untyped-calls,
--disallow-untyped-defs,
--disallow-incomplete-defs,
--check-untyped-defs,
--no-implicit-optional,
--warn-redundant-casts,
--strict-equality,
--extra-checks,
--no-implicit-reexport,
--ignore-missing-imports,
]
11 changes: 11 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,17 @@ $ pip install ".[checking]"
$ ./formats.sh
```

You can use `pre-commit` to automatically check the format, coding style, and type hints before committing.
The following commands automatically fix format errors by auto-formatters.

```bash
# Install `pre-commit`.
$ pip install pre-commit

$ pre-commit install
$ pre-commit run --all-files
```

### Documentation

When adding a new feature to the framework, you also need to document it in the reference.
Expand Down
3 changes: 1 addition & 2 deletions optuna/storages/_rdb/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@
_Column = mapped_column
except ImportError:
# TODO(Shinichi): Remove this after dropping support for SQLAlchemy<2.0.
from sqlalchemy import Column as _Column # type: ignore[assignment]

from sqlalchemy import Column as _Column # type: ignore[assignment, no-redef]

# Don't modify this version number anymore.
# The schema management functionality has been moved to alembic.
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ version = {attr = "optuna.version.__version__"}
[tool.black]
line-length = 99
target-version = ['py38']
exclude = '''
force-exclude = '''
/(
\.eggs
| \.git
Expand Down

0 comments on commit 2f9cc79

Please sign in to comment.