From fc12654bf8915c3237ff4265e7e6889d228b5da7 Mon Sep 17 00:00:00 2001 From: Henry Schreiner Date: Mon, 26 Oct 2020 16:36:11 -0400 Subject: [PATCH] feat: use pyproject.toml instead (#64) * feat: use pyproject.toml instead * ci: travis updates * fix: just install on travis * fix: include macOS version * Update .travis.yml --- .appveyor.yml | 4 ++-- .github/workflows/wheels.yml | 6 ++---- .travis.yml | 4 ++-- pyproject.toml | 8 ++++++++ setup.py | 15 +++------------ 5 files changed, 17 insertions(+), 20 deletions(-) create mode 100644 pyproject.toml diff --git a/.appveyor.yml b/.appveyor.yml index cf8ccf8..5cbe4b8 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -16,10 +16,10 @@ install: - ps: | if ($env:PLATFORM -eq "x64") { $env:PYTHON = "$env:PYTHON-x64" } $env:PATH = "C:\Python$env:PYTHON\;C:\Python$env:PYTHON\Scripts\;$env:PATH" - python -m pip install --disable-pip-version-check --upgrade --no-warn-script-location pip setuptools + python -m pip install --disable-pip-version-check --upgrade --no-warn-script-location pip build build_script: - ps: | - python setup.py sdist + python -m build -s cd dist python -m pip install --verbose python_example-0.0.1.tar.gz cd .. diff --git a/.github/workflows/wheels.yml b/.github/workflows/wheels.yml index 94df2a6..5679998 100644 --- a/.github/workflows/wheels.yml +++ b/.github/workflows/wheels.yml @@ -12,8 +12,6 @@ on: env: CIBW_TEST_COMMAND: python {project}/tests/test.py - # This can be removed if pyproject.toml is used - CIBW_BEFORE_BUILD: pip install pybind11 jobs: @@ -25,10 +23,10 @@ jobs: - uses: actions/setup-python@v2 - name: Install deps - run: python -m pip install "setuptools>=42" "setuptools_scm[toml]>=4.1.0" twine + run: python -m pip install twine build - name: Build SDist - run: python setup.py sdist + run: python -m build -s - name: Check metadata run: twine check dist/* diff --git a/.travis.yml b/.travis.yml index 00b06da..8af5883 100644 --- a/.travis.yml +++ b/.travis.yml @@ -24,6 +24,7 @@ before_install: if [ -n "$PYTHON" ]; then if [ "$TRAVIS_OS_NAME" = "osx" ]; then export PATH="/Users/travis/Library/Python/2.7/bin:$PATH" + export MACOSX_DEPLOYMENT_TARGET="10.13" if [ "${PYTHON:0:1}" = "3" ]; then brew update; brew install python3; fi @@ -46,8 +47,7 @@ before_install: install: - | if [ -n "$PYTHON" ]; then - python setup.py sdist - python -m pip install --verbose dist/*.tar.gz + python -m pip install . elif [ -n "$CONDA" ]; then conda build conda.recipe --python $CONDA conda install --use-local python_example diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..89ae1ed --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,8 @@ +[build-system] +requires = [ + "setuptools>=42", + "wheel", + "pybind11>=2.6.0", +] + +build-backend = "setuptools.build_meta" diff --git a/setup.py b/setup.py index b494a9d..38ea7f7 100644 --- a/setup.py +++ b/setup.py @@ -1,13 +1,8 @@ from setuptools import setup -# With setup_requires, this runs twice - once without setup_requires, and once -# with. The build only happens the second time. -try: - from pybind11.setup_helpers import Pybind11Extension, build_ext - from pybind11 import get_cmake_dir -except ImportError: - from setuptools import Extension as Pybind11Extension - from setuptools.command.build_ext import build_ext +# Available at setup time due to pyproject.toml +from pybind11.setup_helpers import Pybind11Extension, build_ext +from pybind11 import get_cmake_dir import sys @@ -39,10 +34,6 @@ setup( description="A test project using pybind11", long_description="", ext_modules=ext_modules, - # Note: You have to add pybind11 to both setup and install requires to make - # it available during the build. Using PEP 518's pyproject.toml is better! - setup_requires=["pybind11==2.6.0"], - install_requires=["pybind11==2.6.0"], extras_require={"test": "pytest"}, # Currently, build_ext only provides an optional "highest supported C++ # level" feature, but in the future it may provide more features.