Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

pyproject.toml, pre-commit, ruff, uv and typing issues, fixes #1119 #1120

Merged
merged 19 commits into from
Feb 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
156 changes: 49 additions & 107 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,132 +1,66 @@
name: CI (PyTorch 1.12.1, TorchVision 0.13.1)
name: CI with uv
on:
push:
branches: [main]
paths-ignore:
- '**.md'
- '**.ipynb'
- '**.cff'
- "**.md"
- "**.ipynb"
- "**.cff"

pull_request:
branches: [main]
paths-ignore:
- '**.md'
- '**.ipynb'
- '**.cff'
- "**.md"
- "**.ipynb"
- "**.cff"

schedule:
- cron: "0 0 * * *" # Runs at 00:00 UTC every day

workflow_dispatch: # allow running sync via github ui button

jobs:
build:
ci:
runs-on: ubuntu-latest
strategy:
matrix:
operating-system: [ubuntu-latest, windows-latest, macos-latest]
python-version: [3.8, 3.9, '3.10']
fail-fast: false

python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
- uses: actions/checkout@v4
- name: Setup uv python package manager
uses: astral-sh/setup-uv@v5
with:
python-version: ${{ matrix.python-version }}

- name: Restore Ubuntu cache
uses: actions/cache@v4
if: matrix.operating-system == 'ubuntu-latest'
with:
path: ~/.cache/pip
key: ${{ matrix.os }}-${{ matrix.python-version }}-${{ hashFiles('**/setup.py')}}
restore-keys: ${{ matrix.os }}-${{ matrix.python-version }}-

- name: Restore MacOS cache
uses: actions/cache@v4
if: matrix.operating-system == 'macos-latest'
with:
path: ~/Library/Caches/pip
key: ${{ matrix.os }}-${{ matrix.python-version }}-${{ hashFiles('**/setup.py')}}
restore-keys: ${{ matrix.os }}-${{ matrix.python-version }}-

- name: Restore Windows cache
enable-cache: true
prune-cache: false
# For python 3.8 and 3.9, it does no suffice to install opencv-python-headless
# https://itsmycode.com/importerror-libgl-so-1-cannot-open-shared-object-file-no-such-file-or-directory/
- name: Cache apt packages
uses: actions/cache@v4
if: matrix.operating-system == 'windows-latest'
if: ${{ env.ACT }}
with:
path: ~\AppData\Local\pip\Cache
key: ${{ matrix.os }}-${{ matrix.python-version }}-${{ hashFiles('**/setup.py')}}
restore-keys: ${{ matrix.os }}-${{ matrix.python-version }}-

- name: Update pip
run: python -m pip install --upgrade pip

- name: Lint with flake8, black and isort
run: |
pip install -e .[dev]
# stop the build if there are Python syntax errors or undefined names
python -m scripts.run_code_style check

# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --exit-zero --max-complexity=10 --max-line-length=127

- name: Install core dependencies
run: >
pip install -r requirements.txt

- name: Install PyTorch(1.13.1) and TorchVision(0.14.1) on Linux and Windows
if: >
matrix.operating-system == 'ubuntu-latest' ||
matrix.operating-system == 'windows-latest'
run: >
pip install torch==1.13.1+cpu torchvision==0.14.1+cpu
-f https://download.pytorch.org/whl/torch_stable.html

- name: Install PyTorch on MacOS
if: matrix.operating-system == 'macos-latest'
run: pip install torch==1.13.1 torchvision==0.14.1

- name: Install MMDetection(3.0.0) with MMCV(2.0.0)
path: /var/cache/apt
key: apt-cache
- name: Install libgl
run: sudo apt-get update && sudo apt-get install -y libgl1
- name: Setup dependencies
run: uv sync
- name: Install sahi from PyPI
if: github.event_name == 'schedule'
run: |
pip install mmengine==0.7.3
pip install mmcv==2.0.0 -f https://download.openmmlab.com/mmcv/dist/cpu/torch1.13.0/index.html
pip install mmdet==3.0.0

- name: Install YOLOv5(7.0.13)
run: >
pip install yolov5==7.0.13

- name: Install DeepSparse
run: >
pip install deepsparse

- name: Install Transformers(4.35.0)
run: >
pip install transformers==4.35.0

- name: Install pycocotools(2.0.7)
run: >
pip install pycocotools==2.0.7

- name: Install ultralytics(8.3.50)
run: >
pip install ultralytics==8.3.50

- name: Unittest for SAHI+YOLO11/RTDETR/MMDET/HuggingFace/Torchvision on all platforms
rm -fr sahi
uv pip install --force-reinstall sahi
uv pip show sahi
source .venv/bin/activate
python -c "import sahi; print(sahi.__version__)"
- name: Test with python ${{ matrix.python-version }}
run: |
python -m unittest

- name: Install SAHI package from local setup.py
run: >
pip install -e .

source .venv/bin/activate
pytest --capture=no
- name: Test SAHI CLI
run: |
# help
sahi --help
# predict mmdet
sahi predict --source tests/data/ --novisual --model_path tests/data/models/mmdet/yolox/yolox_tiny_8x8_300e_coco_20211124_171234-b4047906.pth --model_config_path tests/data/models/mmdet/yolox/yolox_tiny_8xb8-300e_coco.py --image_size 320
sahi predict --source tests/data/coco_utils/terrain1.jpg --export_pickle --export_crop --model_path tests/data/models/mmdet/yolox/yolox_tiny_8x8_300e_coco_20211124_171234-b4047906.pth --model_config_path tests/data/models/mmdet/yolox/yolox_tiny_8xb8-300e_coco.py --image_size 320
sahi predict --source tests/data/coco_utils/ --novisual --dataset_json_path tests/data/coco_utils/combined_coco.json --model_path tests/data/models/mmdet/yolox/yolox_tiny_8x8_300e_coco_20211124_171234-b4047906.pth --model_config_path tests/data/models/mmdet/yolox/yolox_tiny_8xb8-300e_coco.py --image_size 320
# predict yolov5
source .venv/bin/activate
set -e
sahi predict --no_sliced_prediction --model_type yolov5 --source tests/data/coco_utils/terrain1.jpg --novisual --model_path tests/data/models/yolov5/yolov5s6.pt --image_size 320
sahi predict --model_type yolov5 --source tests/data/ --novisual --model_path tests/data/models/yolov5/yolov5s6.pt --image_size 320
sahi predict --model_type yolov5 --source tests/data/coco_utils/terrain1.jpg --export_pickle --export_crop --model_path tests/data/models/yolov5/yolov5s6.pt --image_size 320
Expand All @@ -137,3 +71,11 @@ jobs:
sahi coco evaluate --dataset_json_path tests/data/coco_evaluate/dataset.json --result_json_path tests/data/coco_evaluate/result.json
# coco analyse
sahi coco analyse --dataset_json_path tests/data/coco_evaluate/dataset.json --result_json_path tests/data/coco_evaluate/result.json --out_dir tests/data/coco_evaluate/
- name: Test SAHI CLI with MMCV
if: matrix.python-version == '3.8' || matrix.python-version == '3.9' || matrix.python-version == '3.10'
run: |
source .venv/bin/activate
set -e
sahi predict --model_type mmdet --source tests/data/ --novisual --model_path tests/data/models/mmdet/yolox/yolox_tiny_8x8_300e_coco_20211124_171234-b4047906.pth --model_config_path tests/data/models/mmdet/yolox/yolox_tiny_8xb8-300e_coco.py --image_size 320
sahi predict --model_type mmdet --source tests/data/coco_utils/terrain1.jpg --export_pickle --export_crop --model_path tests/data/models/mmdet/yolox/yolox_tiny_8x8_300e_coco_20211124_171234-b4047906.pth --model_config_path tests/data/models/mmdet/yolox/yolox_tiny_8xb8-300e_coco.py --image_size 320
sahi predict --model_type mmdet --source tests/data/coco_utils/ --novisual --dataset_json_path tests/data/coco_utils/combined_coco.json --model_path tests/data/models/mmdet/yolox/yolox_tiny_8x8_300e_coco_20211124_171234-b4047906.pth --model_config_path tests/data/models/mmdet/yolox/yolox_tiny_8xb8-300e_coco.py --image_size 320
117 changes: 0 additions & 117 deletions .github/workflows/package_testing.yml

This file was deleted.

28 changes: 12 additions & 16 deletions .github/workflows/publish_pypi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,15 @@ jobs:
publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.x'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install setuptools wheel twine
- name: Build and publish
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN }}
run: |
python setup.py sdist bdist_wheel
twine upload dist/*
- uses: actions/checkout@v4
- name: Setup uv python package manager
uses: astral-sh/setup-uv@v5
with:
enable-cache: true
prune-cache: false
- name: Build and publish
env:
UV_PUBLISH_TOKEN: ${{ secrets.PYPI_TOKEN }}
run: |
uv build
uv publish
18 changes: 18 additions & 0 deletions .github/workflows/ruff.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: Ruff
on: [push]
jobs:
ruff-format:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: astral-sh/ruff-action@v3
with:
args: "format --check"
version: "latest"
ruff:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: astral-sh/ruff-action@v3
with:
version: "latest"
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -165,3 +165,7 @@ cython_debug/
.elasticbeanstalk/*
!.elasticbeanstalk/*.cfg.yml
!.elasticbeanstalk/*.global.yml
tests/data

.archive
.python-version
4 changes: 4 additions & 0 deletions .markdownlint-cli2.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
config:
MD013: false
MD033: false
MD041: false
16 changes: 16 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.9.5
hooks:
# Run the linter.
- id: ruff
types_or: [ python, pyi ]
args: [--fix]
# Run import organizer
- id: ruff
types_or: [ python, pyi ]
args: [--select, I, --fix]
# Run the formatter.
- id: ruff-format
types_or: [ python, pyi ]
Loading