Skip to content

Commit

Permalink
Replace setuptools with skbuild
Browse files Browse the repository at this point in the history
Replace setuptools with scikit-build [1]

Scikit-build is a nice alternatives to raw setuptools when building
native-extensions, and a perfect fit for a project with segyio's
structure. There is a minor breaking change for some build routines -
the python setup script is moved the the python/ directory. This does
not come without benefits:

1. The python project can now be completely oblivious, save the root
   cmake file, to the fact that it's a part of a larger repository, and
   behaves like most python projects
2. cmake is used to build the extension, which means compiler options
   and configs can be set in a more ergonomic manner
3. Because cmake and scikit now manages the compiler setup and binary
   compatibility, compiler support might just be extended, even for
   Windows. segyio no longer has to maintain or deal with these details,
   and can leave it to scikit-build

[1] https://github.com/scikit-build/scikit-build
  • Loading branch information
jokva committed Jun 5, 2019
1 parent d29b731 commit 29983aa
Show file tree
Hide file tree
Showing 12 changed files with 262 additions and 192 deletions.
16 changes: 12 additions & 4 deletions .travis.yml
Expand Up @@ -73,7 +73,8 @@ install:
brew update && brew install cppcheck;
fi
- pip install -r requirements.txt
- pip install bandit setuptools setuptools-scm pytest pytest-runner sphinx
- pip install setuptools setuptools-scm scikit-build
- pip install bandit pytest pytest-runner sphinx

before_script:
- enabled="-DBUILD_PYTHON=OFF -DBUILD_MEX=OFF"
Expand Down Expand Up @@ -111,9 +112,12 @@ script:
- $SCAN make && ctest --output-on-failure
- sudo make install
- popd
- build_wheel . $PLAT
# install works, so remove the _skbuild because it having root permissions
# from make install breaks build_wheel
- sudo rm -rf python/_skbuild
- build_wheel python $PLAT
- install_run $PLAT
- mv wheelhouse dist
- mv wheelhouse python/dist

before_deploy:
# OS X ships with a tar that doesn't support --exclude-vcs, which is
Expand All @@ -128,10 +132,14 @@ before_deploy:
tar --exclude-vcs -C $TRAVIS_BUILD_DIR -czvf segyio-$VERSION.tar.gz segyio-$VERSION;
zip --exclude *.git -r segyio-$VERSION.zip $TRAVIS_BUILD_DIR/segyio-$VERSION/*;
fi
- pushd python
- if [[ $SOURCEDEPLOY ]]; then
rm -rf dist;
fi

after_deploy:
- popd

deploy:
- provider: pypi # source distribution (done from linux python 3.6 only)
skip_cleanup: true
Expand All @@ -147,7 +155,7 @@ deploy:
skip_cleanup: true
skip_upload_docs: true
user: statoil-travis
distributions: build
distributions: --skip-cmake build
password:
secure: BaPED+fUXxmk61N/RtrEWtlRKinc2d+VodwKxwlq/74n8Z6RfJKp/ZzlinbjtnpLB/1kPphxwCYLuG2N2nU2kttNJCQEw9AlPL1gnDxDVUz83KuxSsqLPj9VOdj9MI3xyUs+LC3PW2N4kw2dB+/n2pB7BIwvA+Ykx6+Z2eD2vyEV8WqndP6+vApracCbE8huNfsnbxMqr188qzXbTRnzR1pwVFYBTNJ5vfRf0z/NmHXFpRhKEUaaqazJaax1xp5FGVFg2Wy4GQVDvtn6bVpu/rV5wyWXXdXSqqAQmrwv10OZt5ROfb88yfx+ZilpYDeiHmH8YLj4BjcLpdNeNW0c/irgtejLpnd7+XTUKl2QJzDr2l2ShhuaT+ZN7W8iXXZ4xPPvgcudF9fELZXMy6sKXLPE9qhL1yo/1x2eQ662PgusyegoBcQxtJvc0I0ct7jpWUMU0YQhu6VQUDTaxluSw7kxmQ2WYIW0UJIMkn+AkPw8t/ZYa83RbteRM3I7bAthzNl0IF/t5rDUt8itb6f4eTxjP1+5QdlNkSTNG9KXIxP8wX843PtFKA1i8gcqCIppgoQAnEHHcTJ+nX/ilqXHBWIDiYX6k79B3Hflqj1IcBZjwbUdojLRsHuNb8JN0y8aNsrWyYKhV09+AmvFwo3pY543HOHq/Fuux9ZCUCTeLbo=
on:
Expand Down
30 changes: 16 additions & 14 deletions appveyor.yml
Expand Up @@ -39,38 +39,40 @@ install:
- IF DEFINED PYTHON (IF "%platform%" == "x64" SET PYTHON=%PYTHON%-x64)
- IF DEFINED PYTHON SET PATH=%PYTHON%;%PYTHON%\Scripts;%PATH%
- IF DEFINED PYTHON pip install -r requirements.txt
- IF DEFINED PYTHON pip install twine wheel pytest pytest-runner
- IF DEFINED PYTHON pip install
twine
wheel
setuptools
setuptools-scm
pytest
pytest-runner
scikit-build

before_build:
- IF DEFINED PYTHON SET LANG=%LANG% -DPYTHON_EXECUTABLE=%PYTHON%\python
- set generator="Visual Studio 14 2015"
- IF "%platform%" == "x64" set generator="Visual Studio 14 2015 Win64"
- git fetch --tags

# python extensions with setup.py typically requires building with the same
# compiler as python itself, but it seems that the extern C does a reasonable
# job of keeping it binary compatible. For python < 3.0, copy the shared lib
# into the build directory (because otherwise visual c++ 9.0 is invoked, and it
# supports no C99. For newer pythons, setup.py is capable of building segyio
build_script:
- cmake --version
- IF "%platform%" == "x64" set W64="-GVisual Studio 14 2015 Win64"
- mkdir build
- ps: pushd build
- cmake %APPVEYOR_BUILD_FOLDER%
%W64%
-G %generator%
%MEX%
%LANG%
-DCMAKE_INSTALL_PREFIX=%INSTALL_DIR%
-DBUILD_SHARED_LIBS=ON
-DCMAKE_CXX_FLAGS="/D_CRT_SECURE_NO_WARNINGS /EHsc"
- cmake --build . --config "%configuration%" --target install
- ctest -C "%configuration%" --output-on-failure
- ps: popd
- ps: pushd build/python
- IF DEFINED PYTHON python %APPVEYOR_BUILD_FOLDER%/setup.py bdist_wheel
- ps: pushd python
- IF DEFINED PYTHON python setup.py bdist_wheel -G %generator%
- ps: popd

test_script:
- set PATH=%INSTALL_DIR%\bin;%PATH%
- ps: pushd build/python
- ps: pushd python
- IF DEFINED PYTHON FOR /F "tokens=*" %%G IN ('dir /b dist\*.whl') DO
pip install dist/%%G
- ps: popd
Expand All @@ -79,7 +81,7 @@ test_script:
- IF DEFINED PYTHON python python/examples/scan_min_max.py test-data/small.sgy

before_deploy:
- ps: pushd build/python
- ps: pushd python

after_deploy:
- ps: popd
Expand Down
24 changes: 21 additions & 3 deletions config.sh
Expand Up @@ -14,13 +14,31 @@ function pre_build {

# the cmakes available in yum for centos5 are too old (latest 2.11.x), so
# fetch a newer version pypi
python -m pip install cmake
python -m pip install cmake scikit-build

mkdir build-centos5
pushd build-centos5

cmake --version
cmake .. -DBUILD_PYTHON=OFF -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=ON
make install
cmake -DBUILD_PYTHON=OFF \
-DCMAKE_BUILD_TYPE=Release \
-DBUILD_SHARED_LIBS=ON \
-DCMAKE_INSTALL_NAME_DIR=/usr/local/lib \
..

if [ -n "$IS_OSX" ]; then
sudo make install;
else
make install;
fi

popd

# clean dirty files from python/, otherwise it picks up the one built
# outside docker and symbols will be too recent for auditwheel.
# setuptools_scm really *really* expects a .git-directory. As the wheel
# building process does its work in /tmp, setuptools_scm crashes because it
# cannot find the .git dir. Leave version.py so that setuptools can obtain
# the version from it
git clean -dxf python --exclude python/segyio/version.py
}
2 changes: 2 additions & 0 deletions lib/CMakeLists.txt
@@ -1,6 +1,8 @@
cmake_minimum_required(VERSION 3.5)
project(libsegyio C CXX)

set(SEGYIO_LIB_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR} CACHE PATH "")

set(CMAKE_CXX_STANDARD 11)

add_library(segyio src/segy.c)
Expand Down

0 comments on commit 29983aa

Please sign in to comment.