Skip to content
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

Pre-commit setup for the repo #1071

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
53 changes: 53 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# clang-format file taken from:
# https://github.com/googleapis/google-cloud-cpp

# Use the Google style in this project.
BasedOnStyle: Google

# Some folks prefer to write "int& foo" while others prefer "int &foo". The
# Google Style Guide only asks for consistency within a project, we chose
# "int& foo" for this project:
DerivePointerAlignment: false
PointerAlignment: Left

# The Google Style Guide only asks for consistency w.r.t. "east const" vs.
# "const west" alignment of cv-qualifiers. In this project we use "east const".
QualifierAlignment: Right

IncludeBlocks: Merge
IncludeCategories:
# Matches common headers first, but sorts them after project includes
- Regex: '^\"google/cloud/internal/disable_deprecation_warnings.inc\"$'
Priority: -1
- Regex: '^\"google/cloud/(internal/|grpc_utils/|testing_util/|[^/]+\.h)'
Priority: 1000
- Regex: '^\"google/cloud/' # project includes should sort first
Priority: 500
- Regex: '^\"generator/' # project includes should sort first
Priority: 500
- Regex: '^\"generator/internal/' # project internals second
Priority: 1000
- Regex: '^\"generator/testing/' # testing helpers third
Priority: 1100
- Regex: '^\"' # And then includes from other projects or the system
Priority: 1500
- Regex: '^<grpc/'
Priority: 2000
- Regex: '^<google/*'
Priority: 3000
- Regex: '^<.*/.*'
Priority: 4000
- Regex: '^<.*.hpp>'
Priority: 4000
- Regex: '^<[^/]*>'
Priority: 5000

# Format raw string literals with a `pb` or `proto` tag as proto.
RawStringFormats:
- Language: TextProto
Delimiters:
- 'pb'
- 'proto'
BasedOnStyle: Google

CommentPragmas: '(@copydoc|@copybrief|@see|@overload)'
18 changes: 18 additions & 0 deletions .cmake-format.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
additional_commands:
foo:
flags:
- BAR
- BAZ
kwargs:
DEPENDS: '*'
HEADERS: '*'
SOURCES: '*'
bullet_char: '*'
dangle_parens: false
enum_char: .
line_ending: unix
line_width: 120
max_pargs_hwrap: 3
separate_ctrl_name_with_space: false
separate_fn_name_with_space: false
tab_size: 2
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,5 @@ Package.resolved
# Visual Studio generated files
open_spiel/.vs
/.env

open_spiel.egg-info/
95 changes: 95 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
# To run all pre-commit checks, use:
#
# pre-commit run -a
#
# To install pre-commit hooks that run every time you commit:
#
# pre-commit install
#


repos:
# Standard hooks
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: "v4.4.0"
hooks:
- id: check-added-large-files
- id: check-case-conflict
# Check docstring-first currently clashes with an integrated file:
# open_spiel/python/algorithms/psro_v2/strategy_selectors.py:281: Multiple module docstrings (first docstring on line 15).
# - id: check-docstring-first
- id: check-merge-conflict
- id: check-symlinks
- id: check-toml
- id: check-yaml
- id: debug-statements
- id: end-of-file-fixer
- id: mixed-line-ending
- id: requirements-txt-fixer
- id: trailing-whitespace

# Check for basic python "dont's"
- repo: https://github.com/pre-commit/pygrep-hooks
rev: "v1.10.0"
hooks:
- id: python-check-blanket-noqa
- id: python-check-blanket-type-ignore
# Python-no-log-warn clashes in multiple places where logging.warn has been used
# - id: python-no-log-warn
- id: python-no-eval
- id: python-use-type-annotations

# Sort includes
- repo: https://github.com/PyCQA/isort
rev: "5.12.0"
hooks:
- id: isort

# # Format Python code with black
# black uses an uncompromisable 4-indent as the formatting basis of
# python files which clashes with google's pylint configuration.
# That's why we are using pyink instead which allows 2-indent.
# - repo: https://github.com/psf/black
# rev: 23.3.0
# hooks:
# - id: black
# language_version: python3
# types: [ python ]

# Format Python code with pyink
- repo: https://github.com/google/pyink
rev: 23.3.0
hooks:
- id: pyink
language_version: python3
types: [python]

# Clang-format the C++ part of the code base automatically
- repo: https://github.com/pre-commit/mirrors-clang-format
rev: "v16.0.3"
hooks:
- id: clang-format
types_or: [ c++, c, cuda ]

# CMake format the CMakeLists.txt files
- repo: https://github.com/cheshirekow/cmake-format-precommit
rev: v0.6.13
hooks:
- id: cmake-format
additional_dependencies:
- pyyaml

# Lint python code with PyLint
- repo: local
hooks:
- id: pylint
name: pylint
entry: pylint
language: system
types: [ python ]
args:
[
"-rn", # Only display messages
"-sn", # Don't display the score
"--rcfile=.pylintrc",
]
Loading