Skip to content

Commit

Permalink
Use scikit-build-core to create a PyPI package (wheels + sdist)
Browse files Browse the repository at this point in the history
Signed-off-by: Jean-Christophe Morin <[email protected]>
  • Loading branch information
JeanChristopheMorinPerso committed Jun 3, 2023
1 parent 83f9380 commit 37d9190
Show file tree
Hide file tree
Showing 32 changed files with 316 additions and 213 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
build
/dist
55 changes: 32 additions & 23 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,13 @@ set(MATERIALX_OSL_BINARY_OSLC "" CACHE FILEPATH "Full path to the OSL compiler b
set(MATERIALX_OSL_BINARY_TESTRENDER "" CACHE FILEPATH "Full path to the OSL test render binary.")
set(MATERIALX_OSL_INCLUDE_PATH "" CACHE PATH "Full path to OSL shader includes (e.g. 'stdosl.h').")

set(MATERIALX_PYTHON_FOLDER_NAME "python/MaterialX" CACHE INTERNAL "Folder name to user for installing the Python library.")

if(SKBUILD)
set(MATERIALX_INSTALL_STDLIB_PATH "${SKBUILD_PLATLIB_DIR}/MaterialX/libraries")
set(MATERIALX_PYTHON_FOLDER_NAME "MaterialX")
endif()

# Helpers for MDL validation
if (MATERIALX_BUILD_GEN_MDL)
set(MATERIALX_MDLC_EXECUTABLE "" CACHE FILEPATH "Full path to the mdlc binary.")
Expand Down Expand Up @@ -309,26 +316,28 @@ if(${CMAKE_VERSION} VERSION_GREATER "3.6.2")
endif()

# Install root-level documents
install(FILES LICENSE CHANGELOG.md README.md THIRD-PARTY.md
DESTINATION .)

set(MATERIALX_GEN_CONFIG_PATH "${MATERIALX_INSTALL_LIB_PATH}/cmake/${CMAKE_PROJECT_NAME}")

include(CMakePackageConfigHelpers)
configure_package_config_file(cmake/modules/MaterialXConfig.cmake.in
${CMAKE_BINARY_DIR}/cmake/${CMAKE_PROJECT_NAME}Config.cmake
INSTALL_DESTINATION "${MATERIALX_GEN_CONFIG_PATH}"
PATH_VARS CMAKE_INSTALL_PREFIX CMAKE_PROJECT_NAME)
write_basic_package_version_file(${CMAKE_BINARY_DIR}/cmake/${CMAKE_PROJECT_NAME}ConfigVersion.cmake
VERSION ${MATERIALX_LIBRARY_VERSION}
COMPATIBILITY AnyNewerVersion)

# Install the auto-generated CMake configuration files:

install(EXPORT MaterialX
DESTINATION "${MATERIALX_GEN_CONFIG_PATH}"
FILE ${CMAKE_PROJECT_NAME}Targets.cmake)

install(FILES "${CMAKE_BINARY_DIR}/cmake/${CMAKE_PROJECT_NAME}ConfigVersion.cmake"
"${CMAKE_BINARY_DIR}/cmake/${CMAKE_PROJECT_NAME}Config.cmake"
DESTINATION "${MATERIALX_GEN_CONFIG_PATH}")
if(NOT SKBUILD)
install(FILES LICENSE CHANGELOG.md README.md THIRD-PARTY.md
DESTINATION .)

set(MATERIALX_GEN_CONFIG_PATH "${MATERIALX_INSTALL_LIB_PATH}/cmake/${CMAKE_PROJECT_NAME}")

include(CMakePackageConfigHelpers)
configure_package_config_file(cmake/modules/MaterialXConfig.cmake.in
${CMAKE_BINARY_DIR}/cmake/${CMAKE_PROJECT_NAME}Config.cmake
INSTALL_DESTINATION "${MATERIALX_GEN_CONFIG_PATH}"
PATH_VARS CMAKE_INSTALL_PREFIX CMAKE_PROJECT_NAME)
write_basic_package_version_file(${CMAKE_BINARY_DIR}/cmake/${CMAKE_PROJECT_NAME}ConfigVersion.cmake
VERSION ${MATERIALX_LIBRARY_VERSION}
COMPATIBILITY AnyNewerVersion)

# Install the auto-generated CMake configuration files:

install(EXPORT MaterialX
DESTINATION "${MATERIALX_GEN_CONFIG_PATH}"
FILE ${CMAKE_PROJECT_NAME}Targets.cmake)

install(FILES "${CMAKE_BINARY_DIR}/cmake/${CMAKE_PROJECT_NAME}ConfigVersion.cmake"
"${CMAKE_BINARY_DIR}/cmake/${CMAKE_PROJECT_NAME}Config.cmake"
DESTINATION "${MATERIALX_GEN_CONFIG_PATH}")
endif()
4 changes: 2 additions & 2 deletions libraries/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/pbrlib/genosl/pbrlib_genosl_impl.${PB
DESTINATION "${MATERIALX_INSTALL_STDLIB_PATH}/pbrlib/genosl/" RENAME pbrlib_genosl_impl.mtlx)

install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/
DESTINATION "python/MaterialX/${MATERIALX_INSTALL_STDLIB_PATH}"
DESTINATION "${MATERIALX_INSTALL_STDLIB_PATH}"
PATTERN "CMakeLists.txt" EXCLUDE
PATTERN "pbrlib_genosl_impl.*" EXCLUDE)
install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/pbrlib/genosl/pbrlib_genosl_impl.${PBRLIB_SUFFIX}"
DESTINATION "python/MaterialX/${MATERIALX_INSTALL_STDLIB_PATH}/pbrlib/genosl/" RENAME pbrlib_genosl_impl.mtlx)
DESTINATION "${MATERIALX_INSTALL_STDLIB_PATH}/pbrlib/genosl/" RENAME pbrlib_genosl_impl.mtlx)
78 changes: 78 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
[build-system]
requires = ["scikit-build-core"]
build-backend = "scikit_build_core.build"

[project]
name = "MaterialX"
version = "0.0.0.dev1" # TODO: Change version
authors = [
{ name="Contributors to the MaterialX project", email="[email protected]" },
]
readme = "README.md"

# TODO: Should it also support Python 2?
requires-python = ">=3.7"

# OCIO is not required. But if you want to eventually add it,
# uncomment this, bundle the OCIO config and python/MaterialX/colorspace.py
# will just work.
# dependencies = [
# "opencolorio"
# ]

# TODO: Add more classifier.
classifiers = [
"Programming Language :: Python :: 3",
"License :: OSI Approved :: Apache Software License",
"Operating System :: OS Independent",
]

[project.urls]
"Homepage" = "https://materialx.org"
"Source" = "https://github.com/AcademySoftwareFoundation/MaterialX"
"Bug Tracker" = "https://github.com/AcademySoftwareFoundation/MaterialX/issues"

[project.scripts]
baketextures = "MaterialX._scripts.baketextures:main"
generateshader = "MaterialX._scripts.generateshader:main"
genmdl = "MaterialX._scripts.genmdl:main"
mxdoc = "MaterialX._scripts.mxdoc:main"
mxupdate = "MaterialX._scripts.mxupdate:main"
mxvalidate = "MaterialX._scripts.mxvalidate:main"
translateshader = "MaterialX._scripts.translateshader:main"
writenodegraphs = "MaterialX._scripts.writenodegraphs:main"

[tool.scikit-build]
cmake.minimum-version = "3.18"
cmake.verbose = false
cmake.build-type = "Release"

# Uncoment when developing locally to enable inplace builds.
# build-dir = "build/"

logging.level = "INFO"

# Since the python package doesn't live in a standard directory
# in the source (i.e ./src or ./), we need to manually specify
# where the package is.
wheel.packages = ["python/MaterialX"]

sdist.exclude = [
"/build",
"/dist",
"/resources",
"/javascript",
"/documents",
"/.github",
"MANIFEST.in"

]

[tool.scikit-build.cmake.define]
MATERIALX_BUILD_SHARED_LIBS = 'OFF' # Be explicit
MATERIALX_BUILD_PYTHON = 'ON'
MATERIALX_TEST_RENDER = 'OFF'
MATERIALX_WARNINGS_AS_ERRORS = 'ON'

# TODO: How could we harmonize this variable with SKBUILD?
MATERIALX_INSTALL_PYTHON = 'OFF'
25 changes: 16 additions & 9 deletions python/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,18 +1,25 @@
set(SETUP_PY_IN "${CMAKE_CURRENT_SOURCE_DIR}/setup.py.in")
set(SETUP_PY "${CMAKE_INSTALL_PREFIX}/python/setup.py")

configure_file(${SETUP_PY_IN} ${SETUP_PY})
if(NOT SKBUILD)
install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/MaterialX" DESTINATION "python" MESSAGE_NEVER)
install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/Scripts" DESTINATION "python" MESSAGE_NEVER)
endif()

install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/MaterialX" DESTINATION "python" MESSAGE_NEVER)
install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/Scripts" DESTINATION "python" MESSAGE_NEVER)
if(SKBUILD)
install(
DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/Scripts/"
DESTINATION "${MATERIALX_PYTHON_FOLDER_NAME}/_scripts"
PATTERN "README.md" EXCLUDE
)
endif()

if(MATERIALX_PYTHON_OCIO_DIR)
if(NOT EXISTS "${MATERIALX_PYTHON_OCIO_DIR}/config.ocio")
message(WARNING "No file named config.ocio was found in the given OCIO directory.")
endif()
install(DIRECTORY "${MATERIALX_PYTHON_OCIO_DIR}/" DESTINATION "python/MaterialX/config/" MESSAGE_NEVER)
install(DIRECTORY "${MATERIALX_PYTHON_OCIO_DIR}/" DESTINATION "${MATERIALX_PYTHON_FOLDER_NAME}/config/" MESSAGE_NEVER)
endif()

if(MATERIALX_INSTALL_PYTHON AND PYTHON_EXECUTABLE)
install(CODE "execute_process(COMMAND ${PYTHON_EXECUTABLE} ${SETUP_PY} install clean --all)" MESSAGE_NEVER)
if(MATERIALX_INSTALL_PYTHON AND PYTHON_EXECUTABLE AND NOT SKBUILD)
set(SETUP_PY "${CMAKE_INSTALL_PREFIX}/python/setup.py")
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/setup.py.in" "${SETUP_PY}")
install(CODE "execute_process(COMMAND ${PYTHON_EXECUTABLE} ${SETUP_PY} install clean --all)")
endif()
2 changes: 2 additions & 0 deletions python/MaterialX/_scripts/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
This directory is empty buit it's used when packaging the Python library.
the files in ../../Scripts will be copied inside.
1 change: 1 addition & 0 deletions python/MaterialX/_scripts/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Only required for entry-points.
6 changes: 4 additions & 2 deletions resources/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/
DESTINATION "resources" MESSAGE_NEVER)
if(NOT SKBUILD)
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/
DESTINATION "resources" MESSAGE_NEVER)
endif()
24 changes: 13 additions & 11 deletions source/MaterialXCore/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,16 @@ target_include_directories(MaterialXCore
PRIVATE
${EXTERNAL_INCLUDE_DIRS})

install(TARGETS MaterialXCore
EXPORT MaterialX
ARCHIVE DESTINATION ${MATERIALX_INSTALL_LIB_PATH}
LIBRARY DESTINATION ${MATERIALX_INSTALL_LIB_PATH}
RUNTIME DESTINATION bin)

install(FILES ${materialx_headers}
DESTINATION ${MATERIALX_INSTALL_INCLUDE_PATH}/MaterialXCore/)

install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_BUILD_TYPE}/MaterialXCore.pdb"
DESTINATION "${MATERIALX_INSTALL_LIB_PATH}/" OPTIONAL)
if(NOT SKBUILD)
install(TARGETS MaterialXCore
EXPORT MaterialX
ARCHIVE DESTINATION ${MATERIALX_INSTALL_LIB_PATH}
LIBRARY DESTINATION ${MATERIALX_INSTALL_LIB_PATH}
RUNTIME DESTINATION bin)

install(FILES ${materialx_headers}
DESTINATION ${MATERIALX_INSTALL_INCLUDE_PATH}/MaterialXCore/)

install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_BUILD_TYPE}/MaterialXCore.pdb"
DESTINATION "${MATERIALX_INSTALL_LIB_PATH}/" OPTIONAL)
endif()
26 changes: 14 additions & 12 deletions source/MaterialXFormat/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,17 @@ target_include_directories(MaterialXFormat
PRIVATE
${EXTERNAL_INCLUDE_DIRS})

install(TARGETS MaterialXFormat
EXPORT MaterialX
ARCHIVE DESTINATION ${MATERIALX_INSTALL_LIB_PATH}
LIBRARY DESTINATION ${MATERIALX_INSTALL_LIB_PATH}
RUNTIME DESTINATION bin)

install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/"
DESTINATION ${MATERIALX_INSTALL_INCLUDE_PATH}/MaterialXFormat/ MESSAGE_NEVER
FILES_MATCHING PATTERN "*.h*")

install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_BUILD_TYPE}/MaterialXFormat.pdb"
DESTINATION "${MATERIALX_INSTALL_LIB_PATH}/" OPTIONAL)
if(NOT SKBUILD)
install(TARGETS MaterialXFormat
EXPORT MaterialX
ARCHIVE DESTINATION ${MATERIALX_INSTALL_LIB_PATH}
LIBRARY DESTINATION ${MATERIALX_INSTALL_LIB_PATH}
RUNTIME DESTINATION bin)

install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/"
DESTINATION ${MATERIALX_INSTALL_INCLUDE_PATH}/MaterialXFormat/ MESSAGE_NEVER
FILES_MATCHING PATTERN "*.h*")

install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_BUILD_TYPE}/MaterialXFormat.pdb"
DESTINATION "${MATERIALX_INSTALL_LIB_PATH}/" OPTIONAL)
endif()
26 changes: 14 additions & 12 deletions source/MaterialXGenGlsl/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,17 @@ target_include_directories(MaterialXGenGlsl
PRIVATE
${EXTERNAL_INCLUDE_DIRS})

install(TARGETS MaterialXGenGlsl
EXPORT MaterialX
ARCHIVE DESTINATION ${MATERIALX_INSTALL_LIB_PATH}
LIBRARY DESTINATION ${MATERIALX_INSTALL_LIB_PATH}
RUNTIME DESTINATION bin)

install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/"
DESTINATION ${MATERIALX_INSTALL_INCLUDE_PATH}/MaterialXGenGlsl/ MESSAGE_NEVER
FILES_MATCHING PATTERN "*.h*")

install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_BUILD_TYPE}/MaterialXGenGlsl.pdb"
DESTINATION "${MATERIALX_INSTALL_LIB_PATH}/" OPTIONAL)
if(NOT SKBUILD)
install(TARGETS MaterialXGenGlsl
EXPORT MaterialX
ARCHIVE DESTINATION ${MATERIALX_INSTALL_LIB_PATH}
LIBRARY DESTINATION ${MATERIALX_INSTALL_LIB_PATH}
RUNTIME DESTINATION bin)

install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/"
DESTINATION ${MATERIALX_INSTALL_INCLUDE_PATH}/MaterialXGenGlsl/ MESSAGE_NEVER
FILES_MATCHING PATTERN "*.h*")

install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_BUILD_TYPE}/MaterialXGenGlsl.pdb"
DESTINATION "${MATERIALX_INSTALL_LIB_PATH}/" OPTIONAL)
endif()
32 changes: 17 additions & 15 deletions source/MaterialXGenMdl/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,20 @@ target_include_directories(MaterialXGenMdl
PRIVATE
${EXTERNAL_INCLUDE_DIRS})

install(TARGETS MaterialXGenMdl
EXPORT MaterialX
ARCHIVE DESTINATION ${MATERIALX_INSTALL_LIB_PATH}
LIBRARY DESTINATION ${MATERIALX_INSTALL_LIB_PATH}
RUNTIME DESTINATION bin)

install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/"
DESTINATION ${MATERIALX_INSTALL_INCLUDE_PATH}/MaterialXGenMdl/ MESSAGE_NEVER
FILES_MATCHING PATTERN "*.h*")

install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/mdl
DESTINATION "${MATERIALX_INSTALL_MDL_MODULE_PATH}")

install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_BUILD_TYPE}/MaterialXGenMdl.pdb"
DESTINATION "${MATERIALX_INSTALL_LIB_PATH}/" OPTIONAL)
if(NOT SKBUILD)
install(TARGETS MaterialXGenMdl
EXPORT MaterialX
ARCHIVE DESTINATION ${MATERIALX_INSTALL_LIB_PATH}
LIBRARY DESTINATION ${MATERIALX_INSTALL_LIB_PATH}
RUNTIME DESTINATION bin)

install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/"
DESTINATION ${MATERIALX_INSTALL_INCLUDE_PATH}/MaterialXGenMdl/ MESSAGE_NEVER
FILES_MATCHING PATTERN "*.h*")

install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/mdl
DESTINATION "${MATERIALX_INSTALL_MDL_MODULE_PATH}")

install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_BUILD_TYPE}/MaterialXGenMdl.pdb"
DESTINATION "${MATERIALX_INSTALL_LIB_PATH}/" OPTIONAL)
endif()
26 changes: 14 additions & 12 deletions source/MaterialXGenMsl/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,17 @@ target_include_directories(MaterialXGenMsl
PRIVATE
${EXTERNAL_INCLUDE_DIRS})

install(TARGETS MaterialXGenMsl
EXPORT MaterialX
ARCHIVE DESTINATION ${MATERIALX_INSTALL_LIB_PATH}
LIBRARY DESTINATION ${MATERIALX_INSTALL_LIB_PATH}
RUNTIME DESTINATION bin)

install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/"
DESTINATION ${MATERIALX_INSTALL_INCLUDE_PATH}/MaterialXGenMsl/ MESSAGE_NEVER
FILES_MATCHING PATTERN "*.h*")

install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_BUILD_TYPE}/MaterialXGenMsl.pdb"
DESTINATION "${MATERIALX_INSTALL_LIB_PATH}/" OPTIONAL)
if(NOT SKBUILD)
install(TARGETS MaterialXGenMsl
EXPORT MaterialX
ARCHIVE DESTINATION ${MATERIALX_INSTALL_LIB_PATH}
LIBRARY DESTINATION ${MATERIALX_INSTALL_LIB_PATH}
RUNTIME DESTINATION bin)

install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/"
DESTINATION ${MATERIALX_INSTALL_INCLUDE_PATH}/MaterialXGenMsl/ MESSAGE_NEVER
FILES_MATCHING PATTERN "*.h*")

install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_BUILD_TYPE}/MaterialXGenMsl.pdb"
DESTINATION "${MATERIALX_INSTALL_LIB_PATH}/" OPTIONAL)
endif()
27 changes: 14 additions & 13 deletions source/MaterialXGenOsl/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,17 @@ target_include_directories(MaterialXGenOsl
PRIVATE
${EXTERNAL_INCLUDE_DIRS})

install(TARGETS MaterialXGenOsl
EXPORT MaterialX
ARCHIVE DESTINATION ${MATERIALX_INSTALL_LIB_PATH}
LIBRARY DESTINATION ${MATERIALX_INSTALL_LIB_PATH}
RUNTIME DESTINATION bin)

install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/"
DESTINATION ${MATERIALX_INSTALL_INCLUDE_PATH}/MaterialXGenOsl/ MESSAGE_NEVER
FILES_MATCHING PATTERN "*.h*")

install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_BUILD_TYPE}/MaterialXGenOsl.pdb"
DESTINATION "${MATERIALX_INSTALL_LIB_PATH}/" OPTIONAL)

if(NOT SKBUILD)
install(TARGETS MaterialXGenOsl
EXPORT MaterialX
ARCHIVE DESTINATION ${MATERIALX_INSTALL_LIB_PATH}
LIBRARY DESTINATION ${MATERIALX_INSTALL_LIB_PATH}
RUNTIME DESTINATION bin)

install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/"
DESTINATION ${MATERIALX_INSTALL_INCLUDE_PATH}/MaterialXGenOsl/ MESSAGE_NEVER
FILES_MATCHING PATTERN "*.h*")

install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_BUILD_TYPE}/MaterialXGenOsl.pdb"
DESTINATION "${MATERIALX_INSTALL_LIB_PATH}/" OPTIONAL)
endif()
Loading

0 comments on commit 37d9190

Please sign in to comment.