Content-Length: 341332 | pFad | http://github.com/scikit-beam/scikit-beam/commit/2269ebb56905df0ac70ffc441984262d4d8f0d5f

86 setup: use scikit-build to building of histogram and ctrans extensions · scikit-beam/scikit-beam@2269ebb · GitHub
Skip to content

Commit

Permalink
setup: use scikit-build to building of histogram and ctrans extensions
Browse files Browse the repository at this point in the history
This commit introduces a new dependencies to "scikit-built" and CMake.

scikit-build is a drop-in replacement to setuptools.setup function
allowing to easily compile and package extensions (C/C++/Cython) by
bridging CMake and setuptools. See http://scikit-build.org

CMake is is an open-source, cross-platform family of tools designed
to build, test and package software. See https://cmake.org


Currently, scikit-build and CMake have to be explicitly installed
on the system. Since CMake wheels (allowing to pip install CMake)
will be published shortly, initial will be simplified.


How does it work ?

In addition to simplifying setup.py, three new files have been added:

<root>
  |
  |---- CMakeLists.txt                          (1)
  .
  .
  .
  |--- src
  |     |--- CMakeLists.txt                     (2)
  .
  .
  |--- skbeam
  |     |---core
  .     |     |---accumulators
  .     .     .       |--------- CMakeLists.txt (3)



The first CMakeLists.txt specifies requirements for

* Python interpreter,

* the associated python libraries

* and a "PythonExtension" modules containing convenience CMake
  functions allowing to easily build extension by encapsulating
  system introspection and platform specific logic.

and include the subdirectory associated with the two other CMakeLists.txt.



The second CMakeLists.txt is specific to "ctrans" extension and
it specifies:

* requirement for NumPy

* optional dependency on OpenMP. If it is not found on a given platform,
  nothing is changed, the macro _OPENMP will NOT be defined and a regular
  implementation will be compiled in.

Then, it declares:

* a library, associate pytho extension specific properties

* and finally add an install rule specifying where in the package
  hierarchy the extension should be installed.



Finally, the third CMakeLists.txt is specific to the "histogram" extension
and it specifies:

* requirements for NumPy

Then, it adds "cythonizing" target for the pyx file using the CMake
function "add_cython_target", and proceed to the declaration
of the extension like it was done in the previous case.


Et voila,
  • Loading branch information
jcfr committed Sep 16, 2016
1 parent 0ad46c8 commit 2269ebb
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 27 deletions.
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,8 @@ generated/
# Generated cython files in any subdirectory of /skbeam/
/skbeam/**/*.c

**/_as_gen/*.rst
**/_as_gen/*.rst

# scikit-build
_skbuild
MANIFEST
10 changes: 10 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
cmake_minimum_required(VERSION 3.6.2)

project(skbeam)

find_package(PythonInterp REQUIRED)
find_package(PythonLibs REQUIRED)
find_package(PythonExtensions REQUIRED)

add_subdirectory(skbeam/core/accumulators)
add_subdirectory(src)
1 change: 1 addition & 0 deletions dev-requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
cython
#scikit-build>=0.3.0
27 changes: 1 addition & 26 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,31 +1,9 @@
#!/usr/bin/env python

import setuptools
from distutils.core import setup, Extension
import versioneer
import numpy as np
import sys
from Cython.Build import cythonize

def c_ext():
if os.name == 'nt':
# we are on windows. Do not compile the extension. Tons of errors are
# spit out when we compile on AppVeyor.
# https://gist.github.com/ericdill/bdc86eb81e338ca4624b
return []

# compile for MacOS without openmp
if sys.platform == 'darwin':
return [Extension('skbeam.ext.ctrans', ['src/ctrans.c'])]
# compile the extension on Linux.
return [Extension('skbeam.ext.ctrans', ['src/ctrans.c'],
extra_compile_args=['-fopenmp'],
extra_link_args=['-lgomp'])]


def cython_ext():
return cythonize("**/*.pyx")

from skbuild import setup

setup(
name='scikit-beam',
Expand All @@ -47,9 +25,6 @@ def cython_ext():
'numpy'
], # essential dependencies only

include_dirs=[np.get_include()],
ext_modules=c_ext() + cython_ext(),

url='http://github.com/scikit-beam/scikit-beam',

keywords='Xray Analysis',
Expand Down
11 changes: 11 additions & 0 deletions skbeam/core/accumulators/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@


find_package(Cython REQUIRED)
find_package(NumPy REQUIRED)

add_cython_target(histogram CXX)
add_library(histogram MODULE ${histogram})
python_extension_module(histogram)
target_include_directories(histogram PRIVATE ${NUMPY_INCLUDE_DIRS})

install(TARGETS histogram LIBRARY DESTINATION skbeam/core/accumulators)
12 changes: 12 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@

find_package(NumPy REQUIRED)
find_package(OpenMP)

add_library(ctrans MODULE ctrans.c)
python_extension_module(ctrans)
if(OPENMP_FOUND)
target_compile_options(ctrans PRIVATE ${OpenMP_C_FLAGS})
endif()
target_include_directories(ctrans PRIVATE ${NUMPY_INCLUDE_DIRS})

install(TARGETS ctrans LIBRARY DESTINATION skbeam/ext)

0 comments on commit 2269ebb

Please sign in to comment.








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/scikit-beam/scikit-beam/commit/2269ebb56905df0ac70ffc441984262d4d8f0d5f

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy