Add python checks

This commit is contained in:
jbajic 2022-11-09 10:39:29 +01:00
parent 3c07a5dc04
commit 5f5fe7eb29
4 changed files with 54 additions and 13 deletions

View File

@ -75,14 +75,39 @@ jobs:
- name: Fetch all history for all tags and branches - name: Fetch all history for all tags and branches
run: git fetch run: git fetch
- name: Initialize deps
run: |
# Activate toolchain.
source /opt/toolchain-v4/activate
# Initialize dependencies.
./init
- name: Set base branch
if: ${{ github.event_name == 'pull_request' }}
run: |
echo "BASE_BRANCH=origin/${{ github.base_ref }}" >> $GITHUB_ENV
- name: Set base branch # if we manually dispatch or push to master
if: ${{ github.event_name != 'pull_request' }}
run: |
echo "BASE_BRANCH=origin/master" >> $GITHUB_ENV
- name: Python code analysis
run: |
CHANGED_FILES=$(git diff -U0 ${{ env.BASE_BRANCH }}... --name-only)
for file in ${CHANGED_FILES}; do
echo ${file}
if [[ ${file} == *.py ]]; then
python3 -m black --check --diff ${file}
python3 -m isort --check-only --diff ${file}
fi
done
- name: Build combined ASAN, UBSAN and coverage binaries - name: Build combined ASAN, UBSAN and coverage binaries
run: | run: |
# Activate toolchain. # Activate toolchain.
source /opt/toolchain-v4/activate source /opt/toolchain-v4/activate
# Initialize dependencies.
./init
cd build cd build
cmake -DTEST_COVERAGE=ON -DASAN=ON -DUBSAN=ON .. cmake -DTEST_COVERAGE=ON -DASAN=ON -DUBSAN=ON ..
make -j$THREADS memgraph__unit make -j$THREADS memgraph__unit

View File

@ -6,18 +6,14 @@ repos:
- id: end-of-file-fixer - id: end-of-file-fixer
- id: trailing-whitespace - id: trailing-whitespace
- repo: https://github.com/psf/black - repo: https://github.com/psf/black
rev: 22.3.0 rev: 22.10.0
hooks: hooks:
- id: black - id: black
args: # arguments to configure black - repo: https://github.com/pycqa/isort
- --line-length=120 rev: 5.10.1
- --include='\.pyi?$' hooks:
# these folders wont be formatted by black - id: isort
- --exclude="""\.git | name: isort (python)
\.__pycache__|
build|
libs|
.cache"""
- repo: https://github.com/pre-commit/mirrors-clang-format - repo: https://github.com/pre-commit/mirrors-clang-format
rev: v13.0.0 rev: v13.0.0
hooks: hooks:

7
init
View File

@ -140,5 +140,12 @@ done;
python3 -m pip install pre-commit python3 -m pip install pre-commit
python3 -m pre_commit install python3 -m pre_commit install
# Install py format tools
echo "Install black formatter"
python3 -m pip install black==22.10.*
echo "Install isort"
python3 -m pip install isort==5.10.*
# Link `include/mgp.py` with `release/mgp/mgp.py` # Link `include/mgp.py` with `release/mgp/mgp.py`
ln -v -f include/mgp.py release/mgp/mgp.py ln -v -f include/mgp.py release/mgp/mgp.py

13
pyproject.toml Normal file
View File

@ -0,0 +1,13 @@
[tool.black]
line-length = 120
include = '\.pyi?$'
extend-exclude = '''
/(
| .git
| .__pycache__
| build
| libs
| .cache
)/
'''