Skip to content

Commit 7d3832b

Browse files
committed
CI: add tests with the install of compressai-vision via pip in a venv, in addition to the CI based on UV
1 parent 2ca253b commit 7d3832b

File tree

4 files changed

+150
-18
lines changed

4 files changed

+150
-18
lines changed

.github/workflows/test-pip.yml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: Test (pip)
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
9+
jobs:
10+
test-pip:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- uses: actions/checkout@v3
15+
with:
16+
submodules: 'recursive'
17+
18+
- name: Set up Python 3.10
19+
uses: actions/setup-python@v4
20+
with:
21+
python-version: '3.10'
22+
23+
- name: Install system dependencies
24+
run: |
25+
sudo apt-get update -y
26+
sudo apt-get install -y libgl1-mesa-glx build-essential
27+
28+
- name: Create and activate virtual environment
29+
run: |
30+
python3 -m venv venv
31+
source venv/bin/activate
32+
33+
- name: Install dependencies
34+
run: |
35+
source venv/bin/activate
36+
pip install -U pip wheel setuptools
37+
bash scripts/install.sh --no-weights --cpu -m "detectron2,yolox,segment_anything,jde"
38+
pip install -e .[dev,cpu]
39+
40+
- name: Run pytest
41+
run: |
42+
source venv/bin/activate
43+
pytest

.gitlab-ci.yml

Lines changed: 57 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,20 @@ stages:
1616
- uv run --no-sync python --version
1717
- bash scripts/install_uv.sh --no-install --no-weights --cpu
1818

19-
uv-install:
19+
uv-install-py38:
20+
image: python:3.8-bullseye
21+
stage: setup
22+
script:
23+
- curl -LsSf https://astral.sh/uv/install.sh | sh
24+
- *default-before-script
25+
artifacts:
26+
paths:
27+
- ".local/"
28+
expire_in: 1 day
29+
tags:
30+
- docker
31+
32+
uv-install-py310:
2033
image: python:3.10-bullseye
2134
stage: setup
2235
script:
@@ -30,7 +43,7 @@ uv-install:
3043
- docker
3144
ruff-lint:
3245
stage: static-analysis
33-
image: python:3.10-bullseye
46+
image: python:3.8-bullseye
3447
before_script:
3548
- *default-before-script
3649
- uv pip install -U pip wheel setuptools
@@ -40,24 +53,61 @@ ruff-lint:
4053
tags:
4154
- docker
4255

43-
pytest:
56+
pytest-py38:
57+
stage: test
58+
image: python:3.8-bullseye
59+
dependencies:
60+
- uv-install-py38
61+
before_script:
62+
- apt-get update -y
63+
- apt-get install -y libgl1-mesa-glx build-essential
64+
- *default-before-script
65+
- uv pip install -U pip wheel setuptools
66+
- bash scripts/install_uv.sh --no-weights --cpu -m "detectron2,yolox,segment_anything,jde"
67+
- uv sync --inexact --extra=dev
68+
script:
69+
- uv run --no-sync pytest
70+
tags:
71+
- docker
72+
73+
pytest-py310:
4474
stage: test
4575
image: python:3.10-bullseye
76+
dependencies:
77+
- uv-install-py310
4678
before_script:
4779
- apt-get update -y
4880
- apt-get install -y libgl1-mesa-glx build-essential
4981
- *default-before-script
5082
- uv pip install -U pip wheel setuptools
5183
- bash scripts/install_uv.sh --no-weights --cpu -m "detectron2,yolox,segment_anything,jde"
52-
- uv sync --group=dev
84+
- uv sync --inexact --extra=dev
5385
script:
5486
- uv run --no-sync pytest
5587
tags:
5688
- docker
5789

90+
pytest-pip-py38:
91+
stage: test
92+
image: python:3.8-bullseye
93+
before_script:
94+
- apt-get update -y
95+
- apt-get install -y libgl1-mesa-glx build-essential
96+
- python3 -m venv venv
97+
- source venv/bin/activate
98+
- pip install -U pip wheel setuptools
99+
- pip install torch==2.0.0 torchvision==0.15.1 --index-url https://download.pytorch.org/whl/cpu
100+
- bash scripts/install.sh --no-weights --cpu -m "detectron2,yolox,segment_anything,jde"
101+
- pip install -e .[dev,cpu]
102+
script:
103+
- pytest
104+
tags:
105+
- docker
106+
107+
58108
ruff-format:
59109
stage: static-analysis
60-
image: python:3.10-bullseye
110+
image: python:3.8-bullseye
61111
before_script:
62112
- *default-before-script
63113
- uv pip install -U pip wheel setuptools
@@ -69,7 +119,7 @@ ruff-format:
69119

70120
ruff-organize-imports:
71121
stage: static-analysis
72-
image: python:3.10-bullseye
122+
image: python:3.8-bullseye
73123
before_script:
74124
- *default-before-script
75125
- uv pip install -U pip wheel setuptools
@@ -81,7 +131,7 @@ ruff-organize-imports:
81131

82132
doc:
83133
stage: doc
84-
image: python:3.10-bullseye
134+
image: python:3.8-bullseye
85135
before_script:
86136
- *default-before-script
87137
- uv pip install -U pip wheel setuptools

scripts/install.sh

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -165,10 +165,8 @@ run_install () {
165165
"${PIP[@]}" install -e "${COMPRESSAI_VISION_ROOT_DIR}/compressai"
166166
elif [[ "${PACKAGE_MANAGER}" == "uv" ]]; then
167167
echo "Building compressai C++ extensions from source..."
168-
# Install build dependencies first
169-
"${PIP[@]}" install "pybind11>=2.6.0" "setuptools>=68" wheel
168+
"${PIP[@]}" install "pybind11>=2.6.0" "setuptools>=68" wheel setuptools
170169
cd "${COMPRESSAI_VISION_ROOT_DIR}/compressai"
171-
# Clean any previous build artifacts
172170
rm -rf build/ **/*.so
173171
"${PIP[@]}" install -e . --no-build-isolation
174172
cd "${COMPRESSAI_VISION_ROOT_DIR}"
@@ -179,7 +177,7 @@ run_install () {
179177
echo "Installing compressai-vision"
180178
echo
181179
if [[ "${PACKAGE_MANAGER}" == "pip3" ]]; then
182-
"${PIP[@]}" install -e "${COMPRESSAI_VISION_ROOT_DIR}"
180+
"${PIP[@]}" install -e "${COMPRESSAI_VISION_ROOT_DIR}" --no-build-isolation
183181
elif [[ "${PACKAGE_MANAGER}" == "uv" ]]; then
184182
echo "Already installed by initial uv sync."
185183
fi
@@ -226,15 +224,17 @@ prepare_detectron2 () {
226224
echo "Preparing detectron2 for installation"
227225
echo
228226

227+
229228
if [ -n "$(ls -A "${MODELS_SOURCE_DIR}/detectron2")" ]; then
230229
echo "Source directory already exists: ${MODELS_SOURCE_DIR}/detectron2"
231230
return
232231
fi
233-
232+
234233
git clone --single-branch --branch main https://github.com/facebookresearch/detectron2.git "${MODELS_SOURCE_DIR}/detectron2"
235234
cd "${MODELS_SOURCE_DIR}/detectron2"
236235
git -c advice.detachedHead=false checkout 175b2453c2bc4227b8039118c01494ee75b08136
237-
git apply "${SCRIPT_DIR}/patches/0001-detectron2-fpn-bottom-up-separate.patch" || echo "Patch could not be applied. Possibly already applied."
236+
git apply "${SCRIPT_DIR}/patches/0001-detectron2-fpn-bottom-up-separate.patch" || echo "Patch 0001 could not be applied. Possibly already applied."
237+
git apply "${SCRIPT_DIR}/patches/0002-detectron2-setup-defer-torch-import.patch" || echo "Patch 0002 could not be applied. Possibly already applied."
238238
cd "${COMPRESSAI_VISION_ROOT_DIR}"
239239
}
240240

@@ -246,11 +246,10 @@ install_detectron2 () {
246246
cd "${MODELS_SOURCE_DIR}/detectron2"
247247
rm -rf build/ **/*.so
248248

249-
if [[ "${PACKAGE_MANAGER}" == "pip3" ]]; then
250-
"${PIP[@]}" install -e .
251-
elif [[ "${PACKAGE_MANAGER}" == "uv" ]]; then
252-
uv sync --inexact --group=models-detectron2
253-
fi
249+
# Install build dependencies first for detectron2
250+
"${PIP[@]}" install setuptools wheel
251+
"${PIP[@]}" install -e . --no-build-isolation
252+
254253

255254
cd "${COMPRESSAI_VISION_ROOT_DIR}"
256255
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
--- a/setup.py
2+
+++ b/setup.py
3+
@@ -7,13 +7,9 @@
4+
from os import path
5+
from setuptools import find_packages, setup
6+
from typing import List
7+
-import torch
8+
-from torch.utils.cpp_extension import CUDA_HOME, CppExtension, CUDAExtension
9+
+# torch.utils.cpp_extension imports moved to get_extensions() to avoid ModuleNotFoundError
10+
11+
-torch_ver = [int(x) for x in torch.__version__.split(".")[:2]]
12+
-assert torch_ver >= [1, 8], "Requires PyTorch >= 1.8"
13+
14+
-
15+
def get_version():
16+
init_py_path = path.join(path.abspath(path.dirname(__file__)), "detectron2", "__init__.py")
17+
init_py = open(init_py_path, "r").readlines()
18+
@@ -38,6 +34,15 @@
19+
20+
21+
def get_extensions():
22+
+ try:
23+
+ import torch
24+
+ from torch.utils.cpp_extension import CUDA_HOME, CppExtension, CUDAExtension
25+
+ torch_ver = [int(x) for x in torch.__version__.split(".")[:2]]
26+
+ assert torch_ver >= [1, 8], "Requires PyTorch >= 1.8"
27+
+ except ImportError:
28+
+ # Return empty extensions list if torch is not available during build requirements detection
29+
+ return []
30+
+
31+
this_dir = path.dirname(path.abspath(__file__))
32+
extensions_dir = path.join(this_dir, "detectron2", "layers", "csrc")
33+
34+
@@ -204,5 +209,5 @@
35+
],
36+
},
37+
ext_modules=get_extensions(),
38+
- cmdclass={"build_ext": torch.utils.cpp_extension.BuildExtension},
39+
+ cmdclass={"build_ext": lambda dist: __import__('torch.utils.cpp_extension', fromlist=['BuildExtension']).BuildExtension(dist)},
40+
)

0 commit comments

Comments
 (0)