Skip to content
Snippets Groups Projects
Commit ee0e63cf authored by Hkorb's avatar Hkorb
Browse files

switch to skbuild-core for python build

parent bbf614ed
No related branches found
No related tags found
1 merge request!246Refactor python bindings
......@@ -130,16 +130,16 @@ gcc_12_python:
artifacts:
expire_in: 1 hrs
paths:
- build/
- dist/
- _skbuild/
- pybuild/ # build in separate folder to avoid conflicts with c++ build
before_script:
- export CCACHE_BASEDIR=$CI_PROJECT_DIR
- export CCACHE_DIR=$CI_PROJECT_DIR/cache
script:
- python3 setup.py bdist_wheel build_ext --build-temp=_skbuild -- -DBUILD_VF_CPU=ON -DBUILD_VF_DOUBLE_ACCURACY=ON -DCMAKE_CXX_COMPILER_LAUNCHER=ccache -DCMAKE_CUDA_COMPILER_LAUNCHER=ccache -DCMAKE_C_COMPILER_LAUNCHER=ccache
- export SKBUILD_BUILD_DIR="pybuild"
- export SKBUILD_CMAKE_ARGS="-DBUILD_VF_CPU=ON;-DBUILD_VF_DOUBLE_ACCURACY=ON;-DCMAKE_CXX_COMPILER_LAUNCHER=ccache;-DCMAKE_CUDA_COMPILER_LAUNCHER=ccache;-DCMAKE_C_COMPILER_LAUNCHER=ccache;-G=Ninja"
- pip install . -v
###############################################################################
## Container Upload ##
......@@ -208,9 +208,6 @@ gcc_12_python_bindings_test:
needs: ["gcc_12_python"]
before_script:
- export PYTHONPATH="Python"
- export VF_WHEEL=$(find dist/*.whl)
- pip3 install $VF_WHEEL
- pip3 install -r Python/requirements.txt
script:
......
include pythonbindings/*/bindings*
\ No newline at end of file
include pythonbindings/*/*.cpython*
\ No newline at end of file
[build-system]
requires = [
"setuptools>=42",
"scikit-build",
"cmake",
"ninja; platform_system!='Windows'"
requires = ["scikit-build-core"]
build-backend = "scikit_build_core.build"
[project]
name = "pyfluids"
version = "0.1.0"
description = "Python bindings for VirtualFluids"
readme = "README.md"
requires-python = ">=3.6"
classifiers = [
"Programming Language :: Python :: 3 :: Only",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
]
build-backend = "setup_builder"
backend-path = ["utilities"]
\ No newline at end of file
url = "https://git.rz.tu-bs.de/irmb/virtualfluids"
[tool.cmake]
jobs = 8
[tool.scikit-build]
build-dir = "build"
strict-config = true
logging.level = "INFO"
[tool.scikit-build.wheel]
packages = ["pythonbindings/pyfluids", "pythonbindings/pyfluids-stubs", "pythonbindings/pymuparser"]
[tool.scikit_build.cmake]
verbose = true
build-type = "Release"
[tool.scikit-build.cmake.define]
BUILD_VF_PYTHON_BINDINGS = "ON"
BUILD_SHARED_LIBS = "OFF"
BUILD_VF_UNIT_TESTS = "OFF"
BUILD_WARNINGS_AS_ERRORS = "OFF"
[mypy]
plugins = "numpy.typing.mypy_plugin"
[metadata]
name = pyfluids
description = Python binding for VirtualFluids
long_description = file: README.md
long_description_content_type = text/markdown
platforms = any
url = https://git.rz.tu-bs.de/irmb/virtualfluids
version = 0.1.0
[options]
python_requires = >=3.6
import sys
from pathlib import Path
from typing import List
import skbuild
"""
Install python wrapper of Virtual Fluids
install via python:
python setup.py install
set CMAKE Flags via -DBUILD_VF_GPU:BOOL=ON
CMAKE flags have to be separated by --
example: python setup.py install -- -DBUILD_VF_CPU:BOOL=ON
or install via pip:
pip install .
for pip>21:
set CMAKE Flags via --config-settings "-DBUILD_VF_GPU=ON"
example: pip install . --config-settings="-DBUILD_VF_GPU=ON"
each option has to be passed in individually i.e --config-settings="-DOPT1=ON" --config-settings="-DOPT2=OFF"
for pip <21:
set CMAKE Flags via --global-option ="-DBUILD_VF_GPU=ON"
example: pip install . --global-option="-DBUILD_VF_GPU=ON"
"""
package_name = "pyfluids"
target = "python_bindings"
src_dir = "pythonbindings"
stub_package = package_name+"-stubs"
stub_dir = Path(src_dir)/stub_package
def add_subfiles(dir_path: Path, suffix: str, root_dir: Path) -> List[str]:
files = []
for f in dir_path.iterdir():
if f.is_dir():
files.extend(add_subfiles(f, suffix, root_dir))
if f.is_file():
if f.suffix != suffix:
continue
files.append(str(f.relative_to(root_dir)))
return files
def add_directory(dir_path: Path, suffix: str):
return add_subfiles(dir_path, suffix, dir_path)
stub_files = add_directory(stub_dir, ".pyi")
# hack to get config-args for installation with pip>21
cmake_args = []
if "config_args" in locals():
cmake_args.extend([f"{k}={v}" for k, v in locals()["config_args"].items()])
cmake_args += [
f"-DPython3_ROOT_DIR={Path(sys.prefix)}",
"-DBUILD_VF_PYTHON_BINDINGS=ON",
"-DBUILD_SHARED_LIBS=OFF",
"-DBUILD_VF_DOUBLE_ACCURACY=OFF",
"-DBUILD_VF_UNIT_TESTS:BOOL=OFF",
"-DBUILD_WARNINGS_AS_ERRORS=OFF",
]
skbuild.setup(
name=package_name,
packages=[package_name, "pymuparser", "pyfluids-stubs"],
package_dir={"": src_dir},
cmake_args=cmake_args,
cmake_install_target=target,
package_data={ "pyfluids": ["py.typed"],
"pyfluids-stubs": stub_files},
include_package_data=True,
)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment