Skip to content
Snippets Groups Projects

Code formatting

Closed Grégoire Kubler requested to merge feat/formatter into main
Compare and
16 files
+ 156
107
Compare changes
  • Side-by-side
  • Inline
Files
16
 
format:check_code:
 
stage: format
 
rules:
 
tags:
 
- docker
 
before_script:
 
- !reference [.retrieve_deps:apt, script]
 
- apt-get install -y git
 
- pip install ruff
 
script:
 
- echo "Ensuring that all python files modified in previous commit are correctly formatted. If not, this job will fail."
 
- modified_files=$(git merge-base HEAD origin/dev) # change "dev" to $CI_DEFAULT_BRANCH when whole codebase is formatted
 
- modified_python_files=$(echo $modified_files| grep ".py$\|.ipynb$" || true)
 
- modified_CXX_files=$(echo $modified_files| grep ".h$\|.c$\|.hpp$\|.cpp$\|.cu$" || true)
 
- >
 
if [ $modified_python_files != true ]; then
 
python_files_to_format=$(ruff format --check $modified_python_files)
 
python_files_to_format=$(( $python_files_to_format != "" ? $python_files_to_format : "None"))
 
echo "PYTHON FILES TO FORMAT :"
 
echo "$python_files_to_format"
 
fi
 
if [ $modified_CXX_files != true ]; then
 
CXX_files_to_format=$(clang-format-12 --dry-run $modified_CXX_files)
 
CXX_files_to_format=$(( $CXX_files_to_format != "" ? $CXX_files_to_format : "None"))
 
echo "CXX FILES TO FORMAT :"
 
echo "$CXX_files_to_format"
 
fi
 
if [ "$python_files_to_format$CXX_files_to_format" != "NoneNone"]; then
 
echo "You pushed unformatted files, setup a code formatter before pushing your code."
 
echo "For more informations about code formatting head to the dedicated wiki page :"
 
echo "https://gitlab.eclipse.org/groups/eclipse/aidge/-/wikis/code-quality-:-formatting-&-linting"
 
exit
 
else
 
echo "No files to format, congratulations!"
 
fi
 
Loading