-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add formatting and linting python in pre-commit (#370)
* add ruff pre-commit * install ruff in pre-commit venv * add cmake target for ruff and ruff-format * fix formatting * fix linted warnings * be explicit about formatting options * target py311
- Loading branch information
Showing
13 changed files
with
240 additions
and
204 deletions.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
target-version = "py311" | ||
|
||
line-length = 99 | ||
|
||
[format] | ||
# Make things format the same way as black | ||
quote-style = "double" | ||
indent-style = "space" | ||
skip-magic-trailing-comma = false | ||
line-ending = "auto" | ||
|
||
[lint] | ||
select = ["F", "E", "W", "PLE", "PLW", "PLC"] |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# Additional target to run python linters and formatters on python files | ||
# | ||
# Requires ruff to be available in the environment | ||
|
||
# Get all our Python files | ||
file(GLOB_RECURSE ALL_PYTHON_FILES ${PROJECT_SOURCE_DIR}/python/*.py | ||
${PROJECT_SOURCE_DIR}/scripts/*.py ${PROJECT_SOURCE_DIR}/test/*.py) | ||
|
||
find_program(RUFF_EXECUTABLE ruff) | ||
if(RUFF_EXECUTABLE) | ||
add_custom_target( | ||
ruff | ||
COMMAND ${RUFF_EXECUTABLE} | ||
check --force-exclude ${ALL_PYTHON_FILES} | ||
) | ||
set_target_properties(ruff PROPERTIES EXCLUDE_FROM_ALL TRUE) | ||
add_custom_target( | ||
ruff-format | ||
COMMAND ${RUFF_EXECUTABLE} | ||
format --force-exclude ${ALL_PYTHON_FILES} | ||
) | ||
set_target_properties(ruff-format PROPERTIES EXCLUDE_FROM_ALL TRUE) | ||
else() | ||
message(STATUS "Failed to find ruff executable - no target to run ruff can be set") | ||
endif() |
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
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.