Skip to content

Commit 4a11b02

Browse files
authored
pyproject.toml, pre-commit, ruff, uv and typing issues, fixes #1119 (#1120)
1 parent c9469f5 commit 4a11b02

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+10262
-1001
lines changed

.github/workflows/ci.yml

Lines changed: 49 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -1,132 +1,66 @@
1-
name: CI (PyTorch 1.12.1, TorchVision 0.13.1)
1+
name: CI with uv
22
on:
33
push:
44
branches: [main]
55
paths-ignore:
6-
- '**.md'
7-
- '**.ipynb'
8-
- '**.cff'
6+
- "**.md"
7+
- "**.ipynb"
8+
- "**.cff"
99

1010
pull_request:
1111
branches: [main]
1212
paths-ignore:
13-
- '**.md'
14-
- '**.ipynb'
15-
- '**.cff'
13+
- "**.md"
14+
- "**.ipynb"
15+
- "**.cff"
16+
17+
schedule:
18+
- cron: "0 0 * * *" # Runs at 00:00 UTC every day
19+
20+
workflow_dispatch: # allow running sync via github ui button
1621

1722
jobs:
18-
build:
23+
ci:
1924
runs-on: ubuntu-latest
2025
strategy:
2126
matrix:
22-
operating-system: [ubuntu-latest, windows-latest, macos-latest]
23-
python-version: [3.8, 3.9, '3.10']
24-
fail-fast: false
25-
27+
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
2628
steps:
27-
- name: Checkout
28-
uses: actions/checkout@v4
29-
30-
- name: Set up Python
31-
uses: actions/setup-python@v5
29+
- uses: actions/checkout@v4
30+
- name: Setup uv python package manager
31+
uses: astral-sh/setup-uv@v5
3232
with:
3333
python-version: ${{ matrix.python-version }}
34-
35-
- name: Restore Ubuntu cache
36-
uses: actions/cache@v4
37-
if: matrix.operating-system == 'ubuntu-latest'
38-
with:
39-
path: ~/.cache/pip
40-
key: ${{ matrix.os }}-${{ matrix.python-version }}-${{ hashFiles('**/setup.py')}}
41-
restore-keys: ${{ matrix.os }}-${{ matrix.python-version }}-
42-
43-
- name: Restore MacOS cache
44-
uses: actions/cache@v4
45-
if: matrix.operating-system == 'macos-latest'
46-
with:
47-
path: ~/Library/Caches/pip
48-
key: ${{ matrix.os }}-${{ matrix.python-version }}-${{ hashFiles('**/setup.py')}}
49-
restore-keys: ${{ matrix.os }}-${{ matrix.python-version }}-
50-
51-
- name: Restore Windows cache
34+
enable-cache: true
35+
prune-cache: false
36+
# For python 3.8 and 3.9, it does no suffice to install opencv-python-headless
37+
# https://itsmycode.com/importerror-libgl-so-1-cannot-open-shared-object-file-no-such-file-or-directory/
38+
- name: Cache apt packages
5239
uses: actions/cache@v4
53-
if: matrix.operating-system == 'windows-latest'
40+
if: ${{ env.ACT }}
5441
with:
55-
path: ~\AppData\Local\pip\Cache
56-
key: ${{ matrix.os }}-${{ matrix.python-version }}-${{ hashFiles('**/setup.py')}}
57-
restore-keys: ${{ matrix.os }}-${{ matrix.python-version }}-
58-
59-
- name: Update pip
60-
run: python -m pip install --upgrade pip
61-
62-
- name: Lint with flake8, black and isort
63-
run: |
64-
pip install -e .[dev]
65-
# stop the build if there are Python syntax errors or undefined names
66-
python -m scripts.run_code_style check
67-
68-
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
69-
flake8 . --exit-zero --max-complexity=10 --max-line-length=127
70-
71-
- name: Install core dependencies
72-
run: >
73-
pip install -r requirements.txt
74-
75-
- name: Install PyTorch(1.13.1) and TorchVision(0.14.1) on Linux and Windows
76-
if: >
77-
matrix.operating-system == 'ubuntu-latest' ||
78-
matrix.operating-system == 'windows-latest'
79-
run: >
80-
pip install torch==1.13.1+cpu torchvision==0.14.1+cpu
81-
-f https://download.pytorch.org/whl/torch_stable.html
82-
83-
- name: Install PyTorch on MacOS
84-
if: matrix.operating-system == 'macos-latest'
85-
run: pip install torch==1.13.1 torchvision==0.14.1
86-
87-
- name: Install MMDetection(3.0.0) with MMCV(2.0.0)
42+
path: /var/cache/apt
43+
key: apt-cache
44+
- name: Install libgl
45+
run: sudo apt-get update && sudo apt-get install -y libgl1
46+
- name: Setup dependencies
47+
run: uv sync
48+
- name: Install sahi from PyPI
49+
if: github.event_name == 'schedule'
8850
run: |
89-
pip install mmengine==0.7.3
90-
pip install mmcv==2.0.0 -f https://download.openmmlab.com/mmcv/dist/cpu/torch1.13.0/index.html
91-
pip install mmdet==3.0.0
92-
93-
- name: Install YOLOv5(7.0.13)
94-
run: >
95-
pip install yolov5==7.0.13
96-
97-
- name: Install DeepSparse
98-
run: >
99-
pip install deepsparse
100-
101-
- name: Install Transformers(4.35.0)
102-
run: >
103-
pip install transformers==4.35.0
104-
105-
- name: Install pycocotools(2.0.7)
106-
run: >
107-
pip install pycocotools==2.0.7
108-
109-
- name: Install ultralytics(8.3.50)
110-
run: >
111-
pip install ultralytics==8.3.50
112-
113-
- name: Unittest for SAHI+YOLO11/RTDETR/MMDET/HuggingFace/Torchvision on all platforms
51+
rm -fr sahi
52+
uv pip install --force-reinstall sahi
53+
uv pip show sahi
54+
source .venv/bin/activate
55+
python -c "import sahi; print(sahi.__version__)"
56+
- name: Test with python ${{ matrix.python-version }}
11457
run: |
115-
python -m unittest
116-
117-
- name: Install SAHI package from local setup.py
118-
run: >
119-
pip install -e .
120-
58+
source .venv/bin/activate
59+
pytest --capture=no
12160
- name: Test SAHI CLI
12261
run: |
123-
# help
124-
sahi --help
125-
# predict mmdet
126-
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
127-
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
128-
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
129-
# predict yolov5
62+
source .venv/bin/activate
63+
set -e
13064
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
13165
sahi predict --model_type yolov5 --source tests/data/ --novisual --model_path tests/data/models/yolov5/yolov5s6.pt --image_size 320
13266
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
@@ -137,3 +71,11 @@ jobs:
13771
sahi coco evaluate --dataset_json_path tests/data/coco_evaluate/dataset.json --result_json_path tests/data/coco_evaluate/result.json
13872
# coco analyse
13973
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/
74+
- name: Test SAHI CLI with MMCV
75+
if: matrix.python-version == '3.8' || matrix.python-version == '3.9' || matrix.python-version == '3.10'
76+
run: |
77+
source .venv/bin/activate
78+
set -e
79+
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
80+
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
81+
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

.github/workflows/package_testing.yml

Lines changed: 0 additions & 117 deletions
This file was deleted.

.github/workflows/publish_pypi.yml

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,15 @@ jobs:
88
publish:
99
runs-on: ubuntu-latest
1010
steps:
11-
- uses: actions/checkout@v3
12-
- name: Set up Python
13-
uses: actions/setup-python@v4
14-
with:
15-
python-version: '3.x'
16-
- name: Install dependencies
17-
run: |
18-
python -m pip install --upgrade pip
19-
pip install setuptools wheel twine
20-
- name: Build and publish
21-
env:
22-
TWINE_USERNAME: __token__
23-
TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN }}
24-
run: |
25-
python setup.py sdist bdist_wheel
26-
twine upload dist/*
11+
- uses: actions/checkout@v4
12+
- name: Setup uv python package manager
13+
uses: astral-sh/setup-uv@v5
14+
with:
15+
enable-cache: true
16+
prune-cache: false
17+
- name: Build and publish
18+
env:
19+
UV_PUBLISH_TOKEN: ${{ secrets.PYPI_TOKEN }}
20+
run: |
21+
uv build
22+
uv publish

.github/workflows/ruff.yaml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: Ruff
2+
on: [push]
3+
jobs:
4+
ruff-format:
5+
runs-on: ubuntu-latest
6+
steps:
7+
- uses: actions/checkout@v4
8+
- uses: astral-sh/ruff-action@v3
9+
with:
10+
args: "format --check"
11+
version: "latest"
12+
ruff:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- uses: actions/checkout@v4
16+
- uses: astral-sh/ruff-action@v3
17+
with:
18+
version: "latest"

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,3 +165,7 @@ cython_debug/
165165
.elasticbeanstalk/*
166166
!.elasticbeanstalk/*.cfg.yml
167167
!.elasticbeanstalk/*.global.yml
168+
tests/data
169+
170+
.archive
171+
.python-version

.markdownlint-cli2.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
config:
2+
MD013: false
3+
MD033: false
4+
MD041: false

.pre-commit-config.yaml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
repos:
2+
- repo: https://github.com/astral-sh/ruff-pre-commit
3+
# Ruff version.
4+
rev: v0.9.5
5+
hooks:
6+
# Run the linter.
7+
- id: ruff
8+
types_or: [ python, pyi ]
9+
args: [--fix]
10+
# Run import organizer
11+
- id: ruff
12+
types_or: [ python, pyi ]
13+
args: [--select, I, --fix]
14+
# Run the formatter.
15+
- id: ruff-format
16+
types_or: [ python, pyi ]

0 commit comments

Comments
 (0)