forked from PytorchConnectomics/pytorch_connectomics
-
Notifications
You must be signed in to change notification settings - Fork 0
148 lines (123 loc) · 4.03 KB
/
Copy pathtests.yml
File metadata and controls
148 lines (123 loc) · 4.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
name: Tests
on:
push:
branches: [ main, master, v2.0 ]
pull_request:
branches: [ main, master, v2.0 ]
jobs:
test:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
python-version: ['3.11']
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install pytest pytest-cov
pip install -e .
- name: Validate tutorial configs
run: |
python scripts/validate_tutorial_configs.py
- name: Run tests
run: |
pytest tests/ -v --cov=connectomics --cov-report=xml
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
with:
file: ./coverage.xml
flags: unittests
name: codecov-${{ matrix.os }}-py${{ matrix.python-version }}
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.11'
- name: Install linters
run: |
python -m pip install --upgrade pip
pip install black flake8 isort mypy
- name: Collect changed Python files
id: changed-py
shell: bash
run: |
if [[ "${{ github.event_name }}" == "pull_request" ]]; then
git fetch --no-tags --depth=1 origin "${{ github.base_ref }}"
files=$(git diff --name-only --diff-filter=ACMRT "origin/${{ github.base_ref }}...HEAD" -- 'connectomics/**/*.py')
else
if git rev-parse --verify HEAD~1 >/dev/null 2>&1; then
files=$(git diff --name-only --diff-filter=ACMRT HEAD~1..HEAD -- 'connectomics/**/*.py')
else
files=$(git ls-files 'connectomics/**/*.py')
fi
fi
echo "files<<EOF" >> "$GITHUB_OUTPUT"
echo "$files" >> "$GITHUB_OUTPUT"
echo "EOF" >> "$GITHUB_OUTPUT"
- name: Run black
env:
CHANGED_FILES: ${{ steps.changed-py.outputs.files }}
run: |
python - <<'PY'
import os
import subprocess
import sys
files = [f for f in os.environ.get("CHANGED_FILES", "").splitlines() if f]
if not files:
print("No changed Python files under connectomics/. Skipping black.")
sys.exit(0)
subprocess.check_call(["black", "--check", *files])
PY
- name: Run flake8
env:
CHANGED_FILES: ${{ steps.changed-py.outputs.files }}
run: |
python - <<'PY'
import os
import subprocess
import sys
files = [f for f in os.environ.get("CHANGED_FILES", "").splitlines() if f]
if not files:
print("No changed Python files under connectomics/. Skipping flake8.")
sys.exit(0)
subprocess.check_call(["flake8", "--max-line-length=100", *files])
PY
- name: Run isort
env:
CHANGED_FILES: ${{ steps.changed-py.outputs.files }}
run: |
python - <<'PY'
import os
import subprocess
import sys
files = [f for f in os.environ.get("CHANGED_FILES", "").splitlines() if f]
if not files:
print("No changed Python files under connectomics/. Skipping isort.")
sys.exit(0)
subprocess.check_call(["isort", "--check", *files])
PY
- name: Run mypy
env:
CHANGED_FILES: ${{ steps.changed-py.outputs.files }}
run: |
python - <<'PY'
import os
import subprocess
import sys
files = [f for f in os.environ.get("CHANGED_FILES", "").splitlines() if f]
if not files:
print("No changed Python files under connectomics/. Skipping mypy.")
sys.exit(0)
subprocess.check_call(["mypy", "--config-file", ".github/mypy_changed.ini", *files])
PY