An open problemset for teaching programming — from absolute basics to advanced competitive programming. Jointly maintained and used by MATFIN Foundation and Algo Pro Club.
- Install pre-commit, black and clang-format. These are the tools used for autoformating in the project.
pip install pre-commit
pip install black
pip install clang-formatRemark: It worked for ubuntu 22.04, but for 24.04 I needed this: sudo apt install pre-commit black clang-format.
- Set up precommit hooks
pre-commit installBlack and clang-format automatically checks added python and c++ files before each commit and formats them if they do not fit the formating requirements. In this case the formated files need to be added and commited again.
To avoid having to do each commit twice, run the format.py python script in the root directory, which runs formating on all .py and .cpp files in the repository. If the script cannot run, because python is not a recognized command, then you should run this command in your terminal, which creates a link from the python command to the python3 command.
sudo ln -s $(which python3) /usr/bin/pythonAlternatively you can setup VSCode to automatically format files according to black and clang-format. For black, you need to download an extension
extension id: ms-python.black-formatter
If you want to run formating on a specific file, you can use these commands
- Black:
python -m black myfilename.py- clang-format
clang-format -i myfilename.cpp