Skip to content
Snippets Groups Projects

Code formatting

Closed Grégoire Kubler requested to merge feat/formatter into main
Compare and
16 files
+ 160
107
Compare changes
  • Side-by-side
  • Inline
Files
16
format:check_code:
stage: formatting
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=$($modified_files| grep ".py$\|.ipynb$")
- modified_CXX_files=$($modified_files| grep ".h$\|.c$\|.hpp$\|.cpp$\|.cu$")
- >
if [ ! -z $modified_python_files ]; then
python_files_to_format=$(ruff format --check $modified_python_files)
echo "PYTHON FILES TO FORMAT : "
if [ ! -z "$python_files_to_format" ]; then
echo $python_files_to_format
else
echo "None"
fi
fi
if [ ! -z $modified_CXX_files ]; then
CXX_files_to_format=$(clang-format-12 --dry-run $modified_CXX_files)
if [ ! -z "$CXX_files_to_format" ]; then
echo $CXX_files_to_format
else
echo "None"
fi
fi
if [ ! -z "$python_files_to_format$CXX_files_to_format" ]; 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, congratulation!"
fi
Loading