-
Notifications
You must be signed in to change notification settings - Fork 108
133 lines (120 loc) · 4.53 KB
/
python-package.yml
File metadata and controls
133 lines (120 loc) · 4.53 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
# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions
name: Python package
permissions:
contents: read
on:
push:
branches: [ develop, pre-release, master, main ]
tags: v*
pull_request:
branches: [ develop, pre-release, master, main ]
jobs:
build:
runs-on: ubuntu-24.04
strategy:
fail-fast: true
matrix:
python-version: ["3.11", "3.12", "3.13"]
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
sudo apt update
sudo apt-get install -y libopenjp2-7 libopenjp2-tools
python -m pip install --upgrade pip
python -m pip install ruff==0.15.4 pytest pytest-cov pytest-runner
pip install torch torchvision --index-url https://download.pytorch.org/whl/cpu
pip install -r requirements/requirements.txt
- name: Cache tiatoolbox static assets
uses: actions/cache@v4
with:
key: tiatoolbox-home-static
path: ~/.tiatoolbox
- name: Print Version Information
run: |
echo "---SQlite---"
sqlite3 --version
sqlite3 ":memory:" -list ".output stdout" "pragma compile_options" ".exit"
echo "---OpenJPEG---"
opj_dump -h | head -n 5
echo "---Python---"
python -c "import sys; print('Python %s' % sys.version)"
python -c "import sqlite3; print('SQLite %s' % sqlite3.sqlite_version)"
python -c "import numpy; print('Numpy %s' % numpy.__version__)"
python -c "import openslide; print('OpenSlide %s' % openslide.__version__)"
- name: Lint with ruff
run: |
# stop the build if there are Python syntax errors or undefined names
ruff check .
- name: Test with pytest
run: |
pytest --basetemp={envtmpdir} \
--cov=tiatoolbox --cov-report=term --cov-report=xml --cov-config=pyproject.toml \
--capture=sys \
--durations=10 --durations-min=1.0 \
--maxfail=1
- name: Report test coverage to Codecov
uses: codecov/codecov-action@v4
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
with:
files: coverage.xml
fail_ci_if_error: false
verbose: true
- name: Report test coverage to DeepSource
uses: deepsourcelabs/test-coverage-action@master
with:
key: python
coverage-file: coverage.xml
dsn: ${{ secrets.DEEPSOURCE_DSN }}
fail-ci-on-error: false
- name: List tiatoolbox contents
run: ls -lahR ~/.tiatoolbox
- name: Delete Hugging Face cache for large models
run: |
find ~/.tiatoolbox/models -type f -size +250M -exec bash -c '
for model_path; do
model_name=$(basename "$model_path")
cache_dir="$HOME/.tiatoolbox/models/.cache/huggingface/download"
rm -vf "$cache_dir/${model_name}.lock" "$cache_dir/${model_name}.metadata"
done
' bash {} +
release:
runs-on: ubuntu-24.04
timeout-minutes: 15
needs: build
if: github.ref == 'refs/heads/master' || github.ref == 'refs/heads/main' || github.ref == 'refs/heads/pre-release' || startsWith(github.ref, 'refs/tags/v')
steps:
- uses: actions/checkout@v4
- name: Set up Python 3.11
uses: actions/setup-python@v4
with:
python-version: '3.11'
cache: 'pip'
- name: Install dependencies
run: |
sudo apt-get install -y libopenslide-dev libopenjp2-7
python -m pip install --upgrade pip
pip install torch torchvision --index-url https://download.pytorch.org/whl/cpu
pip install -r requirements/requirements.txt
pip install build
- name: Build package
run: python -m build
- name: Publish package to Test PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
user: __token__
password: ${{ secrets.TEST_PYPI_API_TOKEN }}
repository_url: https://test.pypi.org/legacy/
skip_existing: true # Ignore errors if the current version exists already
- name: Publish package to PyPI
if: startsWith(github.ref, 'refs/tags/v') # Only run on tags starting with v
uses: pypa/gh-action-pypi-publish@release/v1
with:
user: __token__
password: ${{ secrets.PYPI_API_TOKEN }}