File tree 4 files changed +78
-3
lines changed
4 files changed +78
-3
lines changed Original file line number Diff line number Diff line change
1
+ # Black autoformater run
2
+ 1a7cf38f6fbac267d483597c95b3317cb1e1db10
Original file line number Diff line number Diff line change 1
1
[tox]
2
- envlist =py{37,38,39 }-{flake8,mypy}
2
+ envlist =py{39,310 }-{flake8,mypy}
3
3
skip_missing_interpreters = True
4
4
skipsdist = true
5
5
6
6
[testenv]
7
+ allowlist_externals =
8
+ {toxinidir}/utils/check-style.sh
9
+ {toxinidir}/utils/format-code.sh
7
10
description =
11
+ format: Autoformat the changed files to match the style
12
+ style: Style consistency checker
8
13
flake8: Style consistency checker
9
14
mypy: Static analyzer for type annotations
10
15
basepython =
11
- py37: python3.7
12
- py38: python3.8
13
16
py39: python3.9
17
+ py310: python3.10
14
18
deps =
19
+ format: black
20
+ format: isort
21
+ style: black
22
+ style: isort
15
23
flake8: flake8
16
24
mypy: mypy
17
25
mypy: types-requests
18
26
commands =
27
+ format: {toxinidir}/utils/format-code.sh
28
+ style: {toxinidir}/utils/check-style.sh
19
29
flake8: flake8
20
30
mypy: mypy dns tools/ganeti-netbox-sync.py
21
31
22
32
[flake8]
23
33
max-line-length = 120
24
34
statistics = True
25
35
ignore = W503
36
+
37
+ [testenv:py{39,310}-{format,style}]
Original file line number Diff line number Diff line change
1
+ #! /bin/bash -e
2
+ # Copied from the Spicerack repo
3
+
4
+ fail () {
5
+ echo " The code is not formatted according to the current style. You can autoformat your code running:"
6
+ echo " tox -e py3-format"
7
+ exit 1
8
+ }
9
+
10
+ UNSTAGED_FILES=(
11
+ $( git diff HEAD --name-only --diff-filter=d | grep ' \.py$' || true)
12
+ )
13
+ STAGED_FILES=(
14
+ $( git diff HEAD --cached --name-only --diff-filter=d | grep ' \.py$' || true)
15
+ )
16
+
17
+ if [[ " $( git diff HEAD) " == " " ]] && [[ " $( git diff HEAD --cached) " == " " ]]; then
18
+ echo " No local changes, testing the last commit."
19
+ COMMITTED_FILES=(
20
+ $( git diff HEAD^ --name-only --diff-filter=d | grep ' \.py$' || true)
21
+ )
22
+ else
23
+ COMMITTED_FILES=()
24
+ fi
25
+
26
+ if [[ " ${# UNSTAGED_FILES[@]} " -eq " 0" && " ${# STAGED_FILES[@]} " -eq " 0" && " ${# COMMITTED_FILES[@]} " -eq " 0" ]]; then
27
+ echo " No Python file modified, skipping black and isort checks."
28
+ exit 0
29
+ fi
30
+
31
+ black \
32
+ --check \
33
+ --diff \
34
+ " ${UNSTAGED_FILES[@]} " " ${STAGED_FILES[@]} " " ${COMMITTED_FILES[@]} " \
35
+ || fail
36
+
37
+ isort \
38
+ --check-only \
39
+ --diff \
40
+ " ${UNSTAGED_FILES[@]} " " ${STAGED_FILES[@]} " " ${COMMITTED_FILES[@]} " \
41
+ || fail
Original file line number Diff line number Diff line change
1
+ #! /bin/bash -e
2
+ # Copied from the Spicerack repo
3
+
4
+ if [[ -n " $( git diff --name-only --diff-filter=d HEAD) " ]]; then
5
+ echo " Using staged and unstaged files"
6
+ REVISION=" HEAD"
7
+ else
8
+ echo " Using files changed in the latest commit"
9
+ REVISION=" HEAD^"
10
+ fi
11
+
12
+ FILES=( $( git diff --name-only --diff-filter=d " ${REVISION} " | grep ' \.py$' || true) )
13
+
14
+ if [[ " ${# FILES[@]} " -eq " 0" ]]; then
15
+ echo " No Python files to format"
16
+ exit 0
17
+ fi
18
+
19
+ black " ${FILES[@]} "
20
+ isort --apply " ${FILES[@]} "
You can’t perform that action at this time.
0 commit comments