Skip to content

Commit

Permalink
Migrate python buildsystem from setuptools to scikit-build-core (#160)
Browse files Browse the repository at this point in the history
Summary:
This PR updates our build system from setuptools to [scikit-build-core](https://scikit-build-core.readthedocs.io/en/latest/), a more modern tool for building CMake-based Python packages. 

Using scikit-build-core offers several benefits:
- Simplified Configuration: Easier build configuration with declarative syntax in pyproject.toml.
- Improved Error Handling: Better error reporting and handling reduce debugging time.
- Modern Build Tools: Supports Meson and CMake for faster and more efficient builds.
- Better Extension Support: Designed specifically for building Python packages with C/C++ extensions.

## Checklist:

- [x] Adheres to the [style guidelines](https://facebookincubator.github.io/momentum/docs/developer_guide/style_guide)
- [x] Codebase formatted by running `pixi run lint`


Test Plan:
```
pixi run test_py
```

Differential Revision: D66891907

Pulled By: jeongseok-meta
  • Loading branch information
jeongseok-meta authored and facebook-github-bot committed Dec 6, 2024
1 parent 8d01655 commit c1bb0a5
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 169 deletions.
5 changes: 5 additions & 0 deletions cmake/mt_defs.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,7 @@ endfunction()
function(mt_python_binding)
set(prefix _ARG)
set(options
EXCLUDE_FROM_INSTALL
)
set(oneValueArgs
NAME
Expand Down Expand Up @@ -477,4 +478,8 @@ function(mt_python_binding)
target_compile_features(${_ARG_NAME} PRIVATE cxx_std_17)
target_link_libraries(${_ARG_NAME} PRIVATE ${_ARG_LINK_LIBRARIES})
target_compile_options(${_ARG_NAME} PRIVATE ${_ARG_COMPILE_OPTIONS})

if(NOT ${_ARG_EXCLUDE_FROM_INSTALL})
set_property(GLOBAL APPEND PROPERTY PYMOMENTUM_TARGETS_TO_INSTALL ${_ARG_NAME})
endif()
endfunction()
54 changes: 12 additions & 42 deletions pixi.toml
Original file line number Diff line number Diff line change
Expand Up @@ -167,20 +167,10 @@ config_dev = { cmd = """
""", env = { FBXSDK_PATH = ".deps/fbxsdk", MOMENTUM_ENABLE_SIMD = "ON", MOMENTUM_BUILD_PYMOMENTUM = "ON" }, depends_on = [
"install_deps",
] }
build_py = { cmd = """
python setup.py build \
--build-base build/$PIXI_ENVIRONMENT_NAME/py \
build_ext \
--cmake-args='\
-DMOMENTUM_BUILD_IO_FBX=ON \
-DMOMENTUM_BUILD_EXAMPLES=OFF \
-DMOMENTUM_BUILD_TESTING=ON \
-DMOMENTUM_ENABLE_SIMD=$MOMENTUM_ENABLE_SIMD \
-DMOMENTUM_USE_SYSTEM_GOOGLETEST=ON \
-DMOMENTUM_USE_SYSTEM_PYBIND11=OFF \
-DMOMENTUM_USE_SYSTEM_RERUN_CPP_SDK=ON \
'
""", env = { FBXSDK_PATH = ".deps/fbxsdk", MOMENTUM_ENABLE_SIMD = "ON" }, depends_on = [
build_py = { cmd = "pip install . -vv", env = { FBXSDK_PATH = ".deps/fbxsdk", CMAKE_ARGS = """
-DMOMENTUM_BUILD_IO_FBX=ON \
-DMOMENTUM_ENABLE_SIMD=$MOMENTUM_ENABLE_SIMD
""", MOMENTUM_ENABLE_SIMD = "ON" }, depends_on = [
"install_deps",
] }
test_py = { cmd = """
Expand All @@ -205,20 +195,10 @@ test_py = { cmd = """
pytorch = ">=2.4.0"

[target.osx.tasks]
build_py = { cmd = """
python setup.py build \
--build-base build/$PIXI_ENVIRONMENT_NAME/py \
build_ext \
--cmake-args='\
-DMOMENTUM_BUILD_IO_FBX=$MOMENTUM_BUILD_IO_FBX \
-DMOMENTUM_BUILD_EXAMPLES=OFF \
-DMOMENTUM_BUILD_TESTING=ON \
-DMOMENTUM_ENABLE_SIMD=$MOMENTUM_ENABLE_SIMD \
-DMOMENTUM_USE_SYSTEM_GOOGLETEST=ON \
-DMOMENTUM_USE_SYSTEM_PYBIND11=ON \
-DMOMENTUM_USE_SYSTEM_RERUN_CPP_SDK=ON \
'
""", env = { MOMENTUM_BUILD_IO_FBX = "OFF", MOMENTUM_ENABLE_SIMD = "ON" } }
build_py = { cmd = "pip install . -vv", env = { CMAKE_ARGS = """
-DMOMENTUM_BUILD_IO_FBX=$MOMENTUM_BUILD_IO_FBX \
-DMOMENTUM_ENABLE_SIMD=$MOMENTUM_ENABLE_SIMD
""", MOMENTUM_BUILD_IO_FBX = "OFF", MOMENTUM_ENABLE_SIMD = "ON" } }
test_py = { cmd = """
pytest \
pymomentum/test/test_closest_points.py \
Expand All @@ -241,20 +221,10 @@ test_py = { cmd = """
pytorch = ">=2.4.0"

[target.osx-arm64.tasks]
build_py = { cmd = """
python setup.py build \
--build-base build/$PIXI_ENVIRONMENT_NAME/py \
build_ext \
--cmake-args='\
-DMOMENTUM_BUILD_IO_FBX=$MOMENTUM_BUILD_IO_FBX \
-DMOMENTUM_BUILD_EXAMPLES=OFF \
-DMOMENTUM_BUILD_TESTING=ON \
-DMOMENTUM_ENABLE_SIMD=$MOMENTUM_ENABLE_SIMD \
-DMOMENTUM_USE_SYSTEM_GOOGLETEST=ON \
-DMOMENTUM_USE_SYSTEM_PYBIND11=ON \
-DMOMENTUM_USE_SYSTEM_RERUN_CPP_SDK=ON \
'
""", env = { MOMENTUM_BUILD_IO_FBX = "OFF", MOMENTUM_ENABLE_SIMD = "ON" } }
build_py = { cmd = "pip install . -vv", env = { CMAKE_ARGS = """
-DMOMENTUM_BUILD_IO_FBX=$MOMENTUM_BUILD_IO_FBX \
-DMOMENTUM_ENABLE_SIMD=$MOMENTUM_ENABLE_SIMD
""", MOMENTUM_BUILD_IO_FBX = "OFF", MOMENTUM_ENABLE_SIMD = "ON" } }
test_py = { cmd = """
pytest \
pymomentum/test/test_closest_points.py \
Expand Down
7 changes: 7 additions & 0 deletions pymomentum/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -187,3 +187,10 @@ if(MOMENTUM_BUILD_TESTING)
LINK_LIBRARIES tensor_utility
)
endif()

#===============================================================================
# Install
#===============================================================================

get_property(pymomentum_targets_to_install GLOBAL PROPERTY PYMOMENTUM_TARGETS_TO_INSTALL)
install(TARGETS ${pymomentum_targets_to_install} DESTINATION pymomentum)
Empty file removed pymomentum/__init__.py
Empty file.
55 changes: 55 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
[build-system]
requires = ["scikit-build-core", "pybind11"]
build-backend = "scikit_build_core.build"

[project]
name = "pymomentum"
version = "0.1.0"
description = "A library providing foundational algorithms for human kinematic motion and numerical optimization solvers to apply human motion in various applications"
readme = "README.md"
requires-python = ">=3.10"
authors = [
{ name = "Meta Reality Labs Research", email = "[email protected]" },
]
classifiers = ["License :: OSI Approved :: MIT License"]
dependencies = []

[project.urls]
Homepage = "https://github.com/facebookincubator/momentum"

[tool.scikit-build]
build-dir = "build/{wheel_tag}"
cmake.args = [
"-DBUILD_SHARED_LIBS=OFF",
"-DMOMENTUM_BUILD_PYMOMENTUM=ON",
"-DMOMENTUM_BUILD_EXAMPLES=OFF",
"-DMOMENTUM_BUILD_TESTING=ON",
"-DMOMENTUM_USE_SYSTEM_GOOGLETEST=ON",
"-DMOMENTUM_USE_SYSTEM_PYBIND11=ON",
"-DMOMENTUM_USE_SYSTEM_RERUN_CPP_SDK=ON",
]
minimum-version = "0.10"
sdist.exclude = [
"cmake/",
"test/",
"*.h",
"*.cpp",
"*.cmake",
".clang-format",
"CMakeLists.txt",
]
wheel.exclude = ["geometry_test_helper.*"]
wheel.py-api = "cp310"

[[tool.scikit-build.overrides]]
if.platform-system = "^win32"
cmake.args = [
"-DBUILD_SHARED_LIBS=OFF",
"-G Visual Studio 17 2022",
"-DMOMENTUM_BUILD_PYMOMENTUM=ON",
"-DMOMENTUM_BUILD_EXAMPLES=OFF",
"-DMOMENTUM_BUILD_TESTING=ON",
"-DMOMENTUM_USE_SYSTEM_GOOGLETEST=ON",
"-DMOMENTUM_USE_SYSTEM_PYBIND11=ON",
"-DMOMENTUM_USE_SYSTEM_RERUN_CPP_SDK=ON",
]
127 changes: 0 additions & 127 deletions setup.py

This file was deleted.

0 comments on commit c1bb0a5

Please sign in to comment.