-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
get python bindings working from venv/setup.py #15
- Loading branch information
1 parent
ee33561
commit add7a02
Showing
12 changed files
with
79 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,3 +33,4 @@ endif() | |
add_subdirectory(openpiv) | ||
add_subdirectory(test) | ||
add_subdirectory(examples) | ||
add_subdirectory(pybind) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
|
||
option(BUILD_PYBIND "build python bindings" OFF) | ||
|
||
if (BUILD_PYBIND) | ||
message("building python bindings") | ||
|
||
find_package(pybind11) | ||
|
||
include_directories(${CMAKE_SOURCE_DIR}/openpiv) | ||
if (pybind11_FOUND) | ||
pybind11_add_module( | ||
pyopenpivcore | ||
core/module.cpp | ||
core/point.cpp | ||
core/rect.cpp | ||
core/size.cpp | ||
core/vector.cpp | ||
) | ||
target_link_libraries( | ||
pyopenpivcore | ||
PRIVATE openpivcore) | ||
|
||
if (UNIX AND APPLE) | ||
set_target_properties(pyopenpivcore PROPERTIES SUFFIX ".so") | ||
endif() | ||
endif() | ||
endif() |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,13 @@ | ||
from glob import glob | ||
import os | ||
import re | ||
import subprocess | ||
import sys | ||
|
||
from setuptools import Extension, setup | ||
from setuptools.command.build_ext import build_ext | ||
from distutils import sysconfig as ds | ||
from setuptools import setup | ||
from setuptools import Extension as _extension | ||
from setuptools.command.build_ext import build_ext as _build_ext | ||
|
||
# Convert distutils Windows platform specifiers to CMake -A arguments | ||
PLAT_TO_CMAKE = { | ||
|
@@ -18,20 +21,21 @@ | |
# A CMakeExtension needs a sourcedir instead of a file list. | ||
# The name must be the _single_ output extension from the CMake build. | ||
# If you need multiple extensions, see scikit-build. | ||
class CMakeExtension(Extension): | ||
class CMakeExtension(_extension): | ||
def __init__(self, name, sourcedir=""): | ||
Extension.__init__(self, name, sources=[]) | ||
super().__init__(name, sources=[]) | ||
self.sourcedir = os.path.abspath(sourcedir) | ||
|
||
|
||
class CMakeBuild(build_ext): | ||
class CMakeBuild(_build_ext): | ||
def build_extension(self, ext): | ||
extdir = os.path.abspath(os.path.dirname(self.get_ext_fullpath(ext.name))) | ||
|
||
# required for auto-detection & inclusion of auxiliary "native" libs | ||
if not extdir.endswith(os.path.sep): | ||
extdir += os.path.sep | ||
|
||
# check for mode | ||
debug = int(os.environ.get("DEBUG", 0)) if self.debug is None else self.debug | ||
cfg = "Debug" if debug else "Release" | ||
|
||
|
@@ -40,22 +44,20 @@ def build_extension(self, ext): | |
cmake_generator = os.environ.get("CMAKE_GENERATOR", "") | ||
|
||
# Set Python_EXECUTABLE instead if you use PYBIND11_FINDPYTHON | ||
# EXAMPLE_VERSION_INFO shows you how to pass a value into the C++ code | ||
# from Python. | ||
cmake_args = [ | ||
f"-DCMAKE_LIBRARY_OUTPUT_DIRECTORY={extdir}", | ||
f"-DCMAKE_PREFIX_PATH={ds.get_python_lib()}", | ||
"-DBUILD_PYBIND=ON", | ||
f"-DPYTHON_EXECUTABLE={sys.executable}", | ||
f"-DCMAKE_BUILD_TYPE={cfg}", # not used on MSVC, but no harm | ||
] | ||
build_args = [] | ||
|
||
# Adding CMake arguments set as environment variable | ||
# (needed e.g. to build for ARM OSx on conda-forge) | ||
if "CMAKE_ARGS" in os.environ: | ||
cmake_args += [item for item in os.environ["CMAKE_ARGS"].split(" ") if item] | ||
|
||
# In this example, we pass in the version to C++. You might not need to. | ||
cmake_args += [f"-DEXAMPLE_VERSION_INFO={self.distribution.get_version()}"] | ||
|
||
if self.compiler.compiler_type != "msvc": | ||
# Using Ninja-build since it a) is available as a wheel and b) | ||
# multithreads automatically. MSVC would require all variables be | ||
|
@@ -111,7 +113,7 @@ def build_extension(self, ext): | |
os.makedirs(build_temp) | ||
|
||
subprocess.check_call(["cmake", ext.sourcedir] + cmake_args, cwd=build_temp) | ||
subprocess.check_call(["cmake", "--build", "."] + build_args, cwd=build_temp) | ||
subprocess.check_call(["cmake", "--build", ".", "--clean-first"] + build_args, cwd=build_temp) | ||
|
||
|
||
# The information here can also be placed in setup.cfg - better separation of | ||
|
@@ -123,7 +125,7 @@ def build_extension(self, ext): | |
author_email="[email protected]", | ||
description="Python bindings for libopenpivcore", | ||
long_description="", | ||
ext_modules=[CMakeExtension("pyopenpivcore")], | ||
ext_modules=[ CMakeExtension("pyopenpivcore") ], | ||
cmdclass={"build_ext": CMakeBuild}, | ||
zip_safe=False, | ||
extras_require={"test": ["pytest>=6.0"]}, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,6 @@ | |
"tiff", | ||
"benchmark", | ||
"asyncplusplus", | ||
"pybind11", | ||
{ "name": "mimalloc", "platform": "!(arm | uwp)" } | ||
] | ||
} |