From e4c61a2244ff4cd820bdaa508401deb46bc3f8fc Mon Sep 17 00:00:00 2001 From: Roman Donchenko Date: Tue, 17 Aug 2021 18:53:23 +0300 Subject: [PATCH 1/3] Revamp Python build system to fix multiple build problems Use `pyproject.toml` to define build metadata. This enables the following improvements: * `pycocotools.mask` previously failed to load if the NumPy version was downgraded after `pycocotools` was installed, due to an ABI mismatch. This is fixed by using the oldest supported NumPy version for the current environment as the build dependency. * Installing `pycocotools` no longer installs Cython as a dependency (it's not needed at runtime). * `pycocotools` can now be installed without having `setuptools` in your environment. All this is accomplished at the price of more strict system requirements: * Required Python version is now 3.5+, primarily because that is what `oldest-supported-numpy` requires. Notably, this means that Python 2 support is dropped. * pip 10 or higher is required to install `pycocotools` from an sdist. The setuptools requirement is bumped to 43, because setuptools includes pyproject.toml in the sdist starting with this version. However, this has no impact on users, since pip will automatically fetch the correct version. Additionally, update the documentation to recommend using `pip` to install the project, instead of running `setup.py` directly. This ensures that the build result is the same as you would get by installing from an sdist. pip 21.1+ is required for this, because it uses the `in-tree-build` feature. --- .circleci/config.yml | 8 ++++---- PythonAPI/Makefile | 2 +- PythonAPI/pyproject.toml | 8 ++++++++ PythonAPI/setup.py | 18 +++++------------- 4 files changed, 18 insertions(+), 18 deletions(-) create mode 100644 PythonAPI/pyproject.toml diff --git a/.circleci/config.yml b/.circleci/config.yml index bbebab8..ffb1625 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -9,8 +9,7 @@ jobs: steps: - checkout - run: - # TODO in-place pip install is not working - command: cd PythonAPI && python setup.py build_ext + command: python -m pip install --use-feature=in-tree-build ./PythonAPI name: Install From Source build-from-sdist: @@ -19,8 +18,9 @@ jobs: - checkout - run: command: | - cd PythonAPI && python setup.py sdist - python -m pip install --progress-bar off dist/*.tar.gz + python -m pip install build + python -m build --sdist ./PythonAPI + python -m pip install --progress-bar off ./PythonAPI/dist/*.tar.gz name: Install From Distribution - run: command: | diff --git a/PythonAPI/Makefile b/PythonAPI/Makefile index ab5e3d2..bfb5cad 100644 --- a/PythonAPI/Makefile +++ b/PythonAPI/Makefile @@ -5,5 +5,5 @@ all: install: # install pycocotools to the Python site-packages - python setup.py build_ext install + python -m pip install --use-feature=in-tree-build . rm -rf build \ No newline at end of file diff --git a/PythonAPI/pyproject.toml b/PythonAPI/pyproject.toml new file mode 100644 index 0000000..be82c67 --- /dev/null +++ b/PythonAPI/pyproject.toml @@ -0,0 +1,8 @@ +[build-system] +requires = [ + "cython>=0.27.3", + "oldest-supported-numpy", + "setuptools>=43.0.0", + "wheel", +] +build-backend = "setuptools.build_meta" diff --git a/PythonAPI/setup.py b/PythonAPI/setup.py index 10191aa..88507c6 100644 --- a/PythonAPI/setup.py +++ b/PythonAPI/setup.py @@ -1,15 +1,8 @@ """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" +To install library to Python site-packages run "python -m pip install --use-feature=in-tree-build ." """ import platform -from setuptools import dist, setup, Extension - -setup_requires = [ - 'setuptools>=18.0', - 'cython>=0.27.3', - 'numpy', -] -dist.Distribution().fetch_build_eggs(setup_requires) +from setuptools import setup, Extension import numpy as np @@ -30,11 +23,10 @@ license="FreeBSD", packages=['pycocotools'], package_dir={'pycocotools': 'pycocotools'}, - setup_requires=setup_requires, + python_requires='>=3.5', install_requires=[ - 'setuptools>=18.0', - 'cython>=0.27.3', - 'matplotlib>=2.1.0' + 'matplotlib>=2.1.0', + 'numpy', ], version='2.0.2', ext_modules=ext_modules From 81a786a8721ddf24bdbe7eaef64589249b42d400 Mon Sep 17 00:00:00 2001 From: Yuxin Wu Date: Sat, 8 Jan 2022 14:38:46 -0800 Subject: [PATCH 2/3] Add tests to both installation methods --- .circleci/config.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.circleci/config.yml b/.circleci/config.yml index ffb1625..aa15ef3 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -11,6 +11,10 @@ jobs: - run: command: python -m pip install --use-feature=in-tree-build ./PythonAPI name: Install From Source + - run: + command: | + python tests/test_cases.py + name: Run Simple Test Cases build-from-sdist: executor: python/default From e8f907ebd91e170a0b1e8d35849cc84edeb783fa Mon Sep 17 00:00:00 2001 From: Yuxin Wu Date: Sat, 8 Jan 2022 14:40:10 -0800 Subject: [PATCH 3/3] Undo my change as CI is not running for PRs --- .circleci/config.yml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index aa15ef3..ffb1625 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -11,10 +11,6 @@ jobs: - run: command: python -m pip install --use-feature=in-tree-build ./PythonAPI name: Install From Source - - run: - command: | - python tests/test_cases.py - name: Run Simple Test Cases build-from-sdist: executor: python/default