Skip to content

Commit

Permalink
add cmake target for ruff and ruff-format
Browse files Browse the repository at this point in the history
  • Loading branch information
m-fila authored and tmadlener committed Sep 19, 2024
1 parent d6196d3 commit b4d2337
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,6 @@ add_subdirectory(python)

#--- create uninstall target ---------------------------------------------------
include(cmake/EDM4HEPUninstall.cmake)

#--- code format targets -------------------------------------------------------
include(cmake/pythonFormat.cmake)
25 changes: 25 additions & 0 deletions cmake/pythonFormat.cmake
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()

0 comments on commit b4d2337

Please sign in to comment.