Skip to content
Open
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
34 changes: 34 additions & 0 deletions PythonAPI/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
[build-system]
# Required at build time so wheels can be built in an isolated environment.
# numpy and cython are needed at build-time because the project builds C/Cython extensions.
requires = [
"setuptools>=61.0",
"wheel",
"cython>=0.27.3",
"numpy>=1.16"
]
build-backend = "setuptools.build_meta"

[project]
name = "pycocotools"
version = "2.0+nv0.8.1"
description = "Python API for the Microsoft COCO dataset (NVIDIA fork)."
readme = "README.md"
requires-python = ">=3.7"
authors = [
{ name = "NVIDIA" }
]
keywords = ["coco", "computer-vision", "annotation", "dataset"]
classifiers = [
"Programming Language :: Python :: 3",
"License :: OSI Approved :: Apache Software License",
"Operating System :: OS Independent"
]

dependencies = [
"matplotlib>=2.1.0"
]

[tool.setuptools]
packages = ["pycocotools"]
package-dir = { "pycocotools" = "pycocotools" }
36 changes: 26 additions & 10 deletions PythonAPI/setup.py
Original file line number Diff line number Diff line change
@@ -1,40 +1,56 @@
from os.path import abspath, join, exists
from os.path import join, exists
from setuptools import setup, Extension
from sys import version_info
import numpy as np

# To compile and install locally run "python setup.py build_ext --inplace"
# To install library to Python site-packages run "python setup.py build_ext install"
# 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=['../common/maskApi.c', 'pycocotools/_mask.pyx'],
sources=[ext_source_maskapi, mask_source],
extra_compile_args=['-Wno-cpp', '-Wno-unused-function', '-std=c99'],
include_dirs=[np.get_include(), '../common'],
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=[abspath(join(np.get_include(), '..', 'lib'))],
libraries=['npymath', 'gomp']
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',
'cython>=0.27.3',
'matplotlib>=2.1.0',
],
version='2.0+nv0.8.1',
ext_modules=ext_modules
ext_modules=ext_modules,
)