Skip to content

Commit e95efa8

Browse files
committed
CI: test both python3.8 and 3.10
1 parent ab8fdbd commit e95efa8

File tree

2 files changed

+55
-9
lines changed

2 files changed

+55
-9
lines changed

.gitlab-ci.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,22 @@ pytest-pip-py38:
104104
tags:
105105
- docker
106106

107+
pytest-pip-py310:
108+
stage: test
109+
image: python:3.10-bullseye
110+
before_script:
111+
- apt-get update -y
112+
- apt-get install -y libgl1-mesa-glx build-essential
113+
- python3 -m venv venv
114+
- source venv/bin/activate
115+
- pip install -U pip wheel setuptools
116+
- pip install torch==2.0.0 torchvision==0.15.1 --index-url https://download.pytorch.org/whl/cpu
117+
- bash scripts/install.sh --no-weights --cpu -m "detectron2,yolox,segment_anything,jde"
118+
- pip install -e .[dev,cpu]
119+
script:
120+
- pytest
121+
tags:
122+
- docker
107123

108124
ruff-format:
109125
stage: static-analysis
Lines changed: 39 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
--- a/setup.py
22
+++ b/setup.py
3-
@@ -7,13 +7,9 @@
3+
@@ -4,14 +4,20 @@
4+
import glob
5+
import os
6+
import shutil
7+
+import sys
48
from os import path
59
from setuptools import find_packages, setup
610
from typing import List
@@ -10,31 +14,57 @@
1014

1115
-torch_ver = [int(x) for x in torch.__version__.split(".")[:2]]
1216
-assert torch_ver >= [1, 8], "Requires PyTorch >= 1.8"
17+
+
18+
+
19+
+def _get_torch_version():
20+
+ import torch
21+
+ return [int(x) for x in torch.__version__.split(".")[:2]]
22+
+
23+
+
24+
+def _get_build_ext_class():
25+
+ try:
26+
+ from torch.utils.cpp_extension import BuildExtension
27+
+ return BuildExtension
28+
+ except ImportError:
29+
+ return type('DummyBuildExt', (), {'run': lambda self: None})
1330

1431
-
1532
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 @@
33+
@@ -38,6 +44,21 @@ def get_version():
1934

2035

2136
def get_extensions():
37+
+ # Skip extension building during build requirements detection
38+
+ # This is called by setuptools even when just determining build requirements
39+
+ if any(arg in sys.argv for arg in ['egg_info', 'dist_info', '--help-commands', '--name', '--version']):
40+
+ return []
41+
+
42+
+ # Import torch only when actually building extensions
2243
+ try:
2344
+ import torch
2445
+ from torch.utils.cpp_extension import CUDA_HOME, CppExtension, CUDAExtension
25-
+ torch_ver = [int(x) for x in torch.__version__.split(".")[:2]]
46+
+ torch_ver = _get_torch_version()
2647
+ assert torch_ver >= [1, 8], "Requires PyTorch >= 1.8"
2748
+ except ImportError:
28-
+ # Return empty extensions list if torch is not available during build requirements detection
2949
+ return []
30-
+
50+
+ except Exception:
51+
+ return []
52+
+
3153
this_dir = path.dirname(path.abspath(__file__))
3254
extensions_dir = path.join(this_dir, "detectron2", "layers", "csrc")
3355

34-
@@ -204,5 +209,5 @@
56+
@@ -204,9 +225,6 @@ setup(
3557
],
3658
},
3759
ext_modules=get_extensions(),
3860
- cmdclass={"build_ext": torch.utils.cpp_extension.BuildExtension},
39-
+ cmdclass={"build_ext": lambda dist: __import__('torch.utils.cpp_extension', fromlist=['BuildExtension']).BuildExtension(dist)},
61+
+ cmdclass={"build_ext": _get_build_ext_class()},
4062
)
63+
-
64+
-
65+
-def _get_build_ext_class():
66+
- try:
67+
- from torch.utils.cpp_extension import BuildExtension
68+
- return BuildExtension
69+
- except ImportError:
70+
- return type('DummyBuildExt', (), {'run': lambda self: None})

0 commit comments

Comments
 (0)