forked from cocodataset/cocoapi
-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathsetup.py
More file actions
56 lines (49 loc) · 1.83 KB
/
Copy pathsetup.py
File metadata and controls
56 lines (49 loc) · 1.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
from os.path import join, exists
from setuptools import setup, Extension
from sys import version_info
# Provide cythonize fallback: if Cython is available build from .pyx,
# otherwise use the checked-in .c/.cpp files.
try:
from Cython.Build import cythonize
USE_CYTHON = True
except Exception:
cythonize = None
USE_CYTHON = False
# Ensure numpy is available at build time (pyproject.toml should include numpy in build-system.requires)
import numpy as np
# Workaround for Python 3.12 on this repo (keeps compatibility with existing behavior)
if (version_info.major, version_info.minor) >= (3, 12) and not exists("pycocotools/_mask.c"):
open("pycocotools/_mask.c", "w").close()
mask_source = 'pycocotools/_mask.pyx' if USE_CYTHON else 'pycocotools/_mask.c'
ext_source_maskapi = join('..', 'common', 'maskApi.c')
ext_modules = [
Extension(
name='pycocotools._mask',
sources=[ext_source_maskapi, mask_source],
extra_compile_args=['-Wno-cpp', '-Wno-unused-function', '-std=c99'],
include_dirs=[np.get_include(), join('..', 'common')],
),
Extension(
name='ext',
sources=['pycocotools/ext.cpp', 'pycocotools/simdjson.cpp'],
extra_compile_args=['-O3', '-Wall', '-shared', '-fopenmp', '-std=c++17', '-fPIC'],
include_dirs=[np.get_include(), 'pycocotools'],
library_dirs=[join(np.get_include(), '..', 'lib')],
libraries=['npymath', 'gomp'],
language='c++',
)
]
# If Cython is present, cythonize the extensions so .pyx is compiled
if USE_CYTHON:
ext_modules = cythonize(ext_modules, language_level=3)
setup(
name='pycocotools',
packages=['pycocotools'],
package_dir={'pycocotools': 'pycocotools'},
install_requires=[
'setuptools>=18.0',
'matplotlib>=2.1.0',
],
version='2.0+nv0.8.1',
ext_modules=ext_modules,
)