From 6c87cef423c56610ccd75cdb960432ec28b3f917 Mon Sep 17 00:00:00 2001 From: Sunanda Bose Date: Wed, 21 Feb 2024 18:19:15 +0100 Subject: [PATCH 1/4] - added `scripts` --- python-wheel.cmake | 18 ++++++++++++++++-- setup.py.in | 14 ++++++++++++-- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/python-wheel.cmake b/python-wheel.cmake index fe7cc49..f7b4871 100644 --- a/python-wheel.cmake +++ b/python-wheel.cmake @@ -40,10 +40,11 @@ function (add_wheel WHEEL_TARGET) # Parse arguments cmake_parse_arguments(WHEEL "" - "NAME;AUTHOR;URL;PYTHON_REQUIRES;VERSION;DESCRIPTION;README_PATH;LICENSE_PATH" - "TARGET_DEPENDENCIES;MODULE_DEPENDENCIES;DEPLOY_FILES;SUBMODULES" ${ARGN}) + "NAME;AUTHOR;URL;EMAIL;PYTHON_REQUIRES;VERSION;DESCRIPTION;README_PATH;LICENSE_PATH" + "TARGET_DEPENDENCIES;MODULE_DEPENDENCIES;DEPLOY_FILES;SUBMODULES;SCRIPTS" ${ARGN}) to_python_list_string(WHEEL_MODULE_DEPENDENCIES WHEEL_MODULE_DEPENDENCIES_PYLIST) + to_python_list_string(WHEEL_SCRIPTS WHEEL_SCRIPTS_PYLIST) if (NOT WHEEL_VERSION) message(FATAL_ERROR "Missing wheel version.") @@ -57,6 +58,10 @@ function (add_wheel WHEEL_TARGET) set(WHEEL_URL "") endif() + if (NOT WHEEL_URL) + set(WHEEL_URL "") + endif() + if (NOT WHEEL_PYTHON_REQUIRES) set(WHEEL_PYTHON_REQUIRES ">=3.8") endif() @@ -131,6 +136,15 @@ function (add_wheel WHEEL_TARGET) endforeach() endif() + if (WHEEL_SCRIPTS) + foreach (file IN LISTS WHEEL_SCRIPTS) + add_custom_command(TARGET ${WHEEL_TARGET}-copy-files + POST_BUILD + COMMAND ${CMAKE_COMMAND} -E echo "Copying script from ${file} to ${WHEEL_PACKAGE_DIR}" + COMMAND ${CMAKE_COMMAND} -E copy "${file}" "${WHEEL_PACKAGE_DIR}/") + endforeach() + endif() + set(SETUP_FILE "${CMAKE_CURRENT_BINARY_DIR}/setup.py") configure_file("${PY_WHEEL_SETUP_FILE}" "${SETUP_FILE}") diff --git a/setup.py.in b/setup.py.in index 83cb952..18ef1f8 100644 --- a/setup.py.in +++ b/setup.py.in @@ -1,6 +1,6 @@ #!/usr/bin/env python3 -import os, sys, platform +import os, sys, platform, stat import zipfile import subprocess import re @@ -56,11 +56,12 @@ class install_lib(_install_lib): self.build_dir = '@WHEEL_LIB_DIR@' -setup( +kwargs = dict( name = "@WHEEL_NAME@", version = "@WHEEL_VERSION@", description = "@WHEEL_DESCRIPTION@", author = "@WHEEL_AUTHOR@", + author_email='@WHEEL_EMAIL@', url = "@WHEEL_URL@", ext_modules = [CMakeExtension("@WHEEL_TARGET@")], @@ -74,6 +75,9 @@ setup( package_data = { "@WHEEL_NAME@": ["*"] }, + scripts = [ + @WHEEL_SCRIPTS_PYLIST@ + ], cmdclass = { 'bdist': bdist, @@ -82,3 +86,9 @@ setup( 'build_ext': cmake_build_ext, }, ) + +for script in kwargs['scripts']: + st = os.stat(script) + os.chmod(script, st.st_mode | stat.S_IEXEC) + +setup(**kwargs) From 2b4bd8750e9ce7a40282f1166395079acf7134d1 Mon Sep 17 00:00:00 2001 From: Sunanda Bose Date: Thu, 22 Feb 2024 11:50:35 +0100 Subject: [PATCH 2/4] - corrected --- python-wheel.cmake | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/python-wheel.cmake b/python-wheel.cmake index f7b4871..dd275de 100644 --- a/python-wheel.cmake +++ b/python-wheel.cmake @@ -58,8 +58,8 @@ function (add_wheel WHEEL_TARGET) set(WHEEL_URL "") endif() - if (NOT WHEEL_URL) - set(WHEEL_URL "") + if (NOT WHEEL_EMAIL) + set(WHEEL_EMAIL "") endif() if (NOT WHEEL_PYTHON_REQUIRES) From 0fbbf091ff53d25a9b29b2174630b5aa1a4eb816 Mon Sep 17 00:00:00 2001 From: Sunanda Bose Date: Thu, 22 Feb 2024 11:55:18 +0100 Subject: [PATCH 3/4] - Updated README with EMAIL and SCRIPTS --- README.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index d043caa..4117912 100644 --- a/README.md +++ b/README.md @@ -48,6 +48,7 @@ add_wheel(mylib-python-bindings NAME mylib VERSION "0.0.1" AUTHOR "Bob Ross" + EMAIL "email@address.com" URL "http://python.org" PYTHON_REQUIRES ">=3.8" DESCRIPTION "Binary Python wheel." @@ -55,7 +56,11 @@ add_wheel(mylib-python-bindings TARGET_DEPENDENCIES dependency-lib MODULE_DEPENDENCIES - pypi-dependency1 pypi-dependency2) + pypi-dependency1 pypi-dependency2 + SCRIPTS + /path/to/python/script1 + /path/to/python/script2 +) ``` The `add_wheel` command will create a temporary `setup.py` for your project in the build folder, which bundles the necessary files. The execution of this `setup.py` is attached to the custom target `wheelname-setup-py`. It will be executed when you run `cmake --build .` in your build directory. From 101450622106a7a211a5c2b6ffcdffee5863bf6b Mon Sep 17 00:00:00 2001 From: Sunanda Bose Date: Thu, 22 Feb 2024 11:59:23 +0100 Subject: [PATCH 4/4] - docs --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index 4117912..90302e2 100644 --- a/README.md +++ b/README.md @@ -28,6 +28,8 @@ add_library(mylib ...) # Python package version. # AUTHOR # Package author name. +# EMAIL +# Package author email address. # URL # Package website. # PYTHON_REQUIRES @@ -40,6 +42,8 @@ add_library(mylib ...) # CMake targets which belong into the same wheel. # MODULE_DEPENDENCIES # Python module dependencies (requirements.txt content) +# SCRIPTS +# Additional scripts that should be part of the wheel. # SUBMODULES # Any pybind11 submodules must be listed here to support imports like # "from mod.sub import x". A nested submodule must be listed like