From 8e275b3f2285d8507222a1c03612c2e6aa416fe2 Mon Sep 17 00:00:00 2001 From: CnlPepper Date: Sun, 27 Jul 2025 22:43:25 +0100 Subject: [PATCH 1/2] Added meson dist script to copy the dynamically generated _version.py into the release distribution. Moved build related scripts (run automatically as part of the build process) out of the root of dev/. --- dev/abi.py | 50 ------------------------------------------- dev/build.sh | 2 +- dev/build_docs.sh | 3 --- dev/clean.sh | 2 +- dev/root-meson.build | 5 ++++- dev/update_version.sh | 2 -- meson.build | 5 ++++- 7 files changed, 10 insertions(+), 59 deletions(-) delete mode 100755 dev/abi.py delete mode 100755 dev/update_version.sh diff --git a/dev/abi.py b/dev/abi.py deleted file mode 100755 index ba72d14a..00000000 --- a/dev/abi.py +++ /dev/null @@ -1,50 +0,0 @@ -#!/bin/env python - -import sys -import sysconfig -from typing import Union - -""" -Derived from the meson-python codebase. Original license terms: - -Copyright © 2022 the meson-python contributors -Copyright © 2021 Quansight Labs and Filipe Laíns - -Permission is hereby granted, free of charge, to any person obtaining a -copy of this software and associated documentation files (the "Software"), -to deal in the Software without restriction, including without limitation -the rights to use, copy, modify, merge, publish, distribute, sublicense, -and/or sell copies of the Software, and to permit persons to whom the -Software is furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice (including the next -paragraph) shall be included in all copies or substantial portions of the -Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -DEALINGS IN THE SOFTWARE. -""" - - -def get_cpython_abi() -> str: - version = sys.version_info - debug = pymalloc = '' - if version < (3, 8) and _get_config_var('WITH_PYMALLOC', True): - pymalloc = 'm' - return f'cp{version[0]}{version[1]}{debug}{pymalloc}' - - -def _get_config_var(name: str, default: Union[str, int, None] = None) -> Union[str, int, None]: - value: Union[str, int, None] = sysconfig.get_config_var(name) - if value is None: - return default - return value - - -if __name__ == '__main__': - print(get_cpython_abi()) diff --git a/dev/build.sh b/dev/build.sh index 0cbd4336..c5bff15a 100755 --- a/dev/build.sh +++ b/dev/build.sh @@ -1,7 +1,7 @@ #!/bin/bash set -e # exit if an error occurs -BUILD_PATH="build/`dev/abi.py`" +BUILD_PATH="build/`dev/build/abi.py`" echo Rebuilding $BUILD_PATH... meson compile -C $BUILD_PATH diff --git a/dev/build_docs.sh b/dev/build_docs.sh index a104fba8..115dd101 100755 --- a/dev/build_docs.sh +++ b/dev/build_docs.sh @@ -1,13 +1,10 @@ #!/bin/bash echo Building code... - dev/build.sh echo Building docs... - export PYTHONPATH=../:$PYTHONPATH cd docs - make html diff --git a/dev/clean.sh b/dev/clean.sh index a6a5ca57..10e86408 100755 --- a/dev/clean.sh +++ b/dev/clean.sh @@ -1,7 +1,7 @@ #!/bin/bash set -e # exit if an error occurs -BUILD_PATH="build/`dev/abi.py`" +BUILD_PATH="build/`dev/build/abi.py`" echo Cleaning $BUILD_PATH... meson compile -C $BUILD_PATH --clean diff --git a/dev/root-meson.build b/dev/root-meson.build index f77fa44a..a3034a21 100644 --- a/dev/root-meson.build +++ b/dev/root-meson.build @@ -1,8 +1,11 @@ project('raysect', 'cython', default_options: ['python.install-env=auto'], - version: run_command(['dev/update_version.sh'], check: true).stdout().strip() + version: run_command(['dev/build/update_version.sh'], check: true).stdout().strip() ) +# when building a distribution, copy the dynamically generated _version.py to the distribution folder +meson.add_dist_script('dev/build/add_version_file_to_dist.sh') + py = import('python').find_installation(pure: false) numpy = dependency('numpy', method: 'config-tool') fs = import('fs') diff --git a/dev/update_version.sh b/dev/update_version.sh deleted file mode 100755 index f167ea3a..00000000 --- a/dev/update_version.sh +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/bash -python -m setuptools_scm --force-write-version-files diff --git a/meson.build b/meson.build index 7c309e19..62bcf36f 100644 --- a/meson.build +++ b/meson.build @@ -3,9 +3,12 @@ project('raysect', 'cython', default_options: ['python.install-env=auto'], - version: run_command(['dev/update_version.sh'], check: true).stdout().strip() + version: run_command(['dev/build/update_version.sh'], check: true).stdout().strip() ) +# when building a distribution, copy the dynamically generated _version.py to the distribution folder +meson.add_dist_script('dev/build/add_version_file_to_dist.sh') + py = import('python').find_installation(pure: false) numpy = dependency('numpy', method: 'config-tool') fs = import('fs') From 8b9181d9dd745f8594b24723af0e2ee810093c0f Mon Sep 17 00:00:00 2001 From: CnlPepper Date: Sun, 27 Jul 2025 22:57:57 +0100 Subject: [PATCH 2/2] Added files accidentally excluded by .gitignore. Updated .gitignore (!). --- .gitignore | 2 +- dev/build/abi.py | 50 +++++++++++++++++++++++++++ dev/build/add_version_file_to_dist.sh | 19 ++++++++++ dev/build/update_version.sh | 2 ++ 4 files changed, 72 insertions(+), 1 deletion(-) create mode 100755 dev/build/abi.py create mode 100755 dev/build/add_version_file_to_dist.sh create mode 100755 dev/build/update_version.sh diff --git a/.gitignore b/.gitignore index 9da6040c..5438adae 100644 --- a/.gitignore +++ b/.gitignore @@ -8,10 +8,10 @@ __pycache__/ *.c # Distribution / packaging +/build/ .Python env/ venv/ -build/ develop-eggs/ dist/ downloads/ diff --git a/dev/build/abi.py b/dev/build/abi.py new file mode 100755 index 00000000..ba72d14a --- /dev/null +++ b/dev/build/abi.py @@ -0,0 +1,50 @@ +#!/bin/env python + +import sys +import sysconfig +from typing import Union + +""" +Derived from the meson-python codebase. Original license terms: + +Copyright © 2022 the meson-python contributors +Copyright © 2021 Quansight Labs and Filipe Laíns + +Permission is hereby granted, free of charge, to any person obtaining a +copy of this software and associated documentation files (the "Software"), +to deal in the Software without restriction, including without limitation +the rights to use, copy, modify, merge, publish, distribute, sublicense, +and/or sell copies of the Software, and to permit persons to whom the +Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice (including the next +paragraph) shall be included in all copies or substantial portions of the +Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +DEALINGS IN THE SOFTWARE. +""" + + +def get_cpython_abi() -> str: + version = sys.version_info + debug = pymalloc = '' + if version < (3, 8) and _get_config_var('WITH_PYMALLOC', True): + pymalloc = 'm' + return f'cp{version[0]}{version[1]}{debug}{pymalloc}' + + +def _get_config_var(name: str, default: Union[str, int, None] = None) -> Union[str, int, None]: + value: Union[str, int, None] = sysconfig.get_config_var(name) + if value is None: + return default + return value + + +if __name__ == '__main__': + print(get_cpython_abi()) diff --git a/dev/build/add_version_file_to_dist.sh b/dev/build/add_version_file_to_dist.sh new file mode 100755 index 00000000..dd95ae3b --- /dev/null +++ b/dev/build/add_version_file_to_dist.sh @@ -0,0 +1,19 @@ +#!/bin/bash +set -e # exit if an error occurs + +if [[ -z "$MESON_SOURCE_ROOT" ]]; then + echo "ERROR: Must be run inside a meson build environment where the variable MESON_SOURCE_ROOT is set." 1>&2 + exit 1 +fi + +if [[ -z "$MESON_DIST_ROOT" ]]; then + echo "ERROR: Must be run inside a meson build environment where the variable MESON_DIST_ROOT is set." 1>&2 + exit 1 +fi + +VERSION_PATH="raysect/_version.py" +SRC_PATH="$MESON_SOURCE_ROOT/$VERSION_PATH" +DIST_PATH="$MESON_DIST_ROOT/$VERSION_PATH" + +echo "Copying $VERSION_PATH to distribution path $DIST_PATH" +cp $SRC_PATH $DIST_PATH diff --git a/dev/build/update_version.sh b/dev/build/update_version.sh new file mode 100755 index 00000000..f167ea3a --- /dev/null +++ b/dev/build/update_version.sh @@ -0,0 +1,2 @@ +#!/bin/bash +python -m setuptools_scm --force-write-version-files