[STYLE] use ruff in lieu of black/flake8/isort + add pre-commit (#219) #366
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: ci | |
on: | |
push: | |
branches: [ main ] | |
pull_request: | |
branches: [ main ] | |
jobs: | |
test: | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"] | |
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 the package | |
run: | | |
sudo apt update | |
sudo apt install -y libopenslide0 | |
python -m pip install --upgrade pip setuptools wheel | |
python -m pip install torch torchvision --extra-index-url https://download.pytorch.org/whl/cpu openslide-python tiffslide | |
python -m pip install --editable .[dev] | |
- name: Run tests | |
run: python -m pytest --verbose tests/ | |
test-pytorch-nightly: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Set up Python 3.10 | |
uses: actions/setup-python@v4 | |
with: | |
python-version: "3.10" | |
- name: Install the package | |
run: | | |
sudo apt update | |
sudo apt install -y libopenslide0 | |
python -m pip install --upgrade pip setuptools wheel | |
python -m pip install --pre torch torchvision --extra-index-url https://download.pytorch.org/whl/nightly/cpu openslide-python tiffslide | |
python -m pip install --editable .[dev] | |
- name: Run tests | |
run: python -m pytest --verbose tests/ | |
test-docker: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Build Docker image | |
run: docker build -t wsinferimage . | |
- name: Run pytest in Docker image | |
run: | | |
docker run --rm --shm-size=512m --workdir /opt/wsinfer/ --entrypoint bash wsinferimage \ | |
-c "python -m pip install -e /opt/wsinfer[dev] && python -m pytest -vx /opt/wsinfer/tests/test_all.py" | |
- name: Run wsinfer on a sample image in Docker | |
run: | | |
mkdir slides | |
cd slides | |
wget -q https://openslide.cs.cmu.edu/download/openslide-testdata/Aperio/JP2K-33003-1.svs | |
cd .. | |
docker run --rm --shm-size=512m --volume $HOME:$HOME --volume $(pwd):/work --workdir /work wsinferimage run \ | |
--wsi-dir slides/ --results-dir results/ --model breast-tumor-resnet34.tcga-brca | |
test -f results/run_metadata_*.json | |
test -f results/patches/JP2K-33003-1.h5 | |
test -f results/model-outputs-csv/JP2K-33003-1.csv | |
test $(wc -l < results/model-outputs-csv/JP2K-33003-1.csv) -eq 675 | |
test-package: | |
strategy: | |
matrix: | |
os: [ubuntu-latest, windows-latest, macos-latest] | |
runs-on: ${{ matrix.os }} | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Set up Python 3.10 | |
uses: actions/setup-python@v4 | |
with: | |
python-version: "3.10" | |
- name: Install OpenSlide on Ubuntu | |
if: matrix.os == 'ubuntu-latest' | |
run: sudo apt update && sudo apt install -y libopenslide0 | |
- name: Install OpenSlide on macOS | |
if: matrix.os == 'macos-latest' | |
run: brew install openslide | |
- name: Install the wsinfer python package | |
run: | | |
python -m pip install --upgrade pip setuptools wheel | |
python -m pip install torch torchvision --extra-index-url https://download.pytorch.org/whl/cpu openslide-python tiffslide | |
python -m pip install . | |
- name: Run 'wsinfer run' on Unix | |
if: matrix.os != 'windows-latest' | |
run: | | |
mkdir newdir && cd newdir | |
mkdir slides && cd slides | |
wget -q https://openslide.cs.cmu.edu/download/openslide-testdata/Aperio/JP2K-33003-1.svs | |
cd .. | |
WSINFER_FORCE_CPU=1 wsinfer run --wsi-dir slides/ --results-dir results/ --model breast-tumor-resnet34.tcga-brca | |
test -f results/run_metadata_*.json | |
test -f results/patches/JP2K-33003-1.h5 | |
test -f results/model-outputs-csv/JP2K-33003-1.csv | |
test $(wc -l < results/model-outputs-csv/JP2K-33003-1.csv) -eq 675 | |
# FIXME: tissue segmentation has different outputs on Windows. The patch sizes | |
# are the same but the coordinates found are different. | |
- name: Run 'wsinfer run' on Windows | |
if: matrix.os == 'windows-latest' | |
run: | | |
mkdir newdir && cd newdir | |
mkdir slides && cd slides | |
Invoke-WebRequest -URI https://openslide.cs.cmu.edu/download/openslide-testdata/Aperio/JP2K-33003-1.svs -OutFile JP2K-33003-1.svs | |
cd .. | |
wsinfer run --wsi-dir slides/ --results-dir results/ --model breast-tumor-resnet34.tcga-brca | |
Test-Path -Path results/run_metadata_*.json -PathType Leaf | |
Test-Path -Path results/patches/JP2K-33003-1.h5 -PathType Leaf | |
Test-Path -Path results/model-outputs-csv/JP2K-33003-1.csv -PathType Leaf | |
# test $(python -c "print(sum(1 for _ in open('results/model-outputs/JP2K-33003-1.csv')))") -eq 675 | |
mypy: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Set up Python 3.10 | |
uses: actions/setup-python@v4 | |
with: | |
python-version: "3.10" | |
- name: Install the package | |
run: | | |
sudo apt update | |
sudo apt install -y libopenslide0 | |
python -m pip install --upgrade pip setuptools wheel | |
python -m pip install torch torchvision --extra-index-url https://download.pytorch.org/whl/cpu openslide-python tiffslide | |
python -m pip install -e .[all] | |
- name: Check types | |
run: python -m mypy --install-types --non-interactive wsinfer/ tests/ | |
docs: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Set up Python | |
uses: actions/setup-python@v4 | |
with: | |
python-version: "3.10" | |
- name: Install the package | |
run: | | |
sudo apt update | |
sudo apt install -y libopenslide0 | |
python -m pip install --upgrade pip setuptools wheel | |
python -m pip install torch torchvision --extra-index-url https://download.pytorch.org/whl/cpu openslide-python tiffslide | |
python -m pip install .[docs] | |
- name: Build docs | |
run: | | |
cd docs | |
make html |