From 54eb85411557e619d1394eecdded7a5bf59322b0 Mon Sep 17 00:00:00 2001 From: Matthew Brett Date: Fri, 10 Nov 2023 10:43:54 +0000 Subject: [PATCH] Try standardizing build requirements --- .github/workflows/build.ps1 | 9 ++++-- .github/workflows/build.sh | 8 ++--- .github/workflows/wheels-linux.yml | 1 - .github/workflows/wheels-macos.yml | 1 - .github/workflows/wheels-windows.yml | 6 ---- config.sh | 14 ++------ get_numpy_version.py | 35 -------------------- nipy | 2 +- print_deps.py | 48 ++++++++++++++++++++++++++++ 9 files changed, 60 insertions(+), 64 deletions(-) delete mode 100755 get_numpy_version.py create mode 100755 print_deps.py diff --git a/.github/workflows/build.ps1 b/.github/workflows/build.ps1 index 75e6234..916e1b8 100644 --- a/.github/workflows/build.ps1 +++ b/.github/workflows/build.ps1 @@ -1,7 +1,10 @@ echo "::group::Build wheel" - pip install @($env:BUILD_DEPENDS.split()) - pip wheel -w "${env:WHEEL_SDIR}" --no-build-isolation ".\${env:REPO_DIR}" - ls -l "${env:GITHUB_WORKSPACE}/${env:WHEEL_SDIR}/" + $wheel_sdir = "wheelhouse" + pip install tomlkit + $build_dep = python .\print_deps.py $env:MB_PYTHON_VERSION ${env:REPO_DIR} + pip install @($build_dep.split()) + pip wheel -w "${wheel_sdir}" --no-build-isolation ".\${env:REPO_DIR}" + ls -l "${env:GITHUB_WORKSPACE}/${wheel_sdir}/" echo "::endgroup::" echo "::group::Install wheel" diff --git a/.github/workflows/build.sh b/.github/workflows/build.sh index eba9a0e..78b5209 100755 --- a/.github/workflows/build.sh +++ b/.github/workflows/build.sh @@ -4,7 +4,7 @@ if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then # if php is installed, brew tries to reinstall these after installing openblas brew remove --ignore-dependencies curl php - brew install pkg-config + brew install pkg-config openblas if [[ "$PLAT" == "arm64" ]]; then export MACOSX_DEPLOYMENT_TARGET="11.0" @@ -25,10 +25,8 @@ echo "::group::Install a virtualenv" echo "::endgroup::" echo "::group::Build wheel" - np_dep=$(python ./get_numpy_version.py $MB_PYTHON_VERSION) - export BUILD_DEPENDS="${BUILD_BASE} ${np_dep}" - echo "Build depends: ${BUILD_DEPENDS}" - echo "Build base: ${BUILD_BASE}" + pip install tomlkit + export BUILD_DEPENDS=$(python ./print_deps.py ${MB_PYTHON_VERSION} ${REPO_DIR}) clean_code build_wheel ls -l "${GITHUB_WORKSPACE}/${WHEEL_SDIR}/" diff --git a/.github/workflows/wheels-linux.yml b/.github/workflows/wheels-linux.yml index a08c910..3038f94 100644 --- a/.github/workflows/wheels-linux.yml +++ b/.github/workflows/wheels-linux.yml @@ -48,7 +48,6 @@ jobs: MB_PYTHON_VERSION: ${{ matrix.python }} MB_ML_LIBC: ${{ matrix.mb-ml-libc }} MB_ML_VER: ${{ matrix.mb-ml-ver }} - BUILD_BASE: "meson-python>=0.13 ninja cython>=3" steps: - uses: actions/checkout@v4 with: diff --git a/.github/workflows/wheels-macos.yml b/.github/workflows/wheels-macos.yml index 2034339..e7802c8 100644 --- a/.github/workflows/wheels-macos.yml +++ b/.github/workflows/wheels-macos.yml @@ -39,7 +39,6 @@ jobs: PLAT: ${{ matrix.platform }} MB_PYTHON_VERSION: ${{ matrix.python }} TRAVIS_OS_NAME: "osx" - BUILD_BASE: "meson-python>=0.13 ninja cython>=3" steps: - uses: actions/checkout@v4 with: diff --git a/.github/workflows/wheels-windows.yml b/.github/workflows/wheels-windows.yml index de248db..32744a0 100644 --- a/.github/workflows/wheels-windows.yml +++ b/.github/workflows/wheels-windows.yml @@ -29,9 +29,7 @@ jobs: ] env: BUILD_COMMIT: ${{ inputs.build-commit }} - WHEEL_SDIR: wheelhouse MB_PYTHON_VERSION: ${{ matrix.python }} - BUILD_BASE: "meson-python>=0.13 ninja cython>=3" steps: - uses: actions/checkout@v4 with: @@ -39,10 +37,6 @@ jobs: - uses: actions/setup-python@v4 with: python-version: ${{ matrix.python }} - - name: Set Numpy version - run: | - $np_dep = python .\get_numpy_version.py $env:MB_PYTHON_VERSION - echo "BUILD_DEPENDS=${env:BUILD_BASE} ${np_dep}" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append - name: Build Wheel run: .github/workflows/build.ps1 - uses: actions/upload-artifact@v3 diff --git a/config.sh b/config.sh index 99a3094..1047510 100644 --- a/config.sh +++ b/config.sh @@ -1,18 +1,8 @@ # Define custom utilities # Test for OSX with [ -n "$IS_MACOS" ] -function pre_build { - # Any stuff that you need to do before you start - # building the wheels. - # Runs in the root directory of this repository. - # Workaround for Accelerate error; only on macOS. - if [ -z "$IS_MACOS" ]; then return; fi - brew install openblas -} - -function pip_wheel_cmd { - local abs_wheelhouse=$1 - pip wheel $(pip_opts) -w $abs_wheelhouse --no-build-isolation . +function pip_opts { + echo "--no-build-isolation" } function run_tests { diff --git a/get_numpy_version.py b/get_numpy_version.py deleted file mode 100755 index fe29751..0000000 --- a/get_numpy_version.py +++ /dev/null @@ -1,35 +0,0 @@ -#!/usr/bin/env python3 -""" Echo Numpy version for given environment -""" - -import os - -from argparse import ArgumentParser, RawDescriptionHelpFormatter - - -def get_parser(): - parser = ArgumentParser(description=__doc__, # Usage from docstring - formatter_class=RawDescriptionHelpFormatter) - parser.add_argument("py_ver", - help='Python version e.g. 3.11') - parser.add_argument('-t', '--type', default='build', - help='Dependency type') - return parser - - -def main(): - parser = get_parser() - args = parser.parse_args() - major, minor, *_ = args.py_ver.split('.') - assert major == "3" - np_version = "1.22.2" - minor = int(minor) - if minor >= 12: - np_version = "1.26.0" - elif minor >= 11: - np_version = "1.23.2" - print(f'numpy=={np_version}') - - -if __name__ == '__main__': - main() diff --git a/nipy b/nipy index dc97dbf..f407de8 160000 --- a/nipy +++ b/nipy @@ -1 +1 @@ -Subproject commit dc97dbf9f46707ca62f8ad920b0f2fb0c239b10c +Subproject commit f407de8d00702f0d7abfc3f39ec62c9808b43f65 diff --git a/print_deps.py b/print_deps.py new file mode 100755 index 0000000..83a7e81 --- /dev/null +++ b/print_deps.py @@ -0,0 +1,48 @@ +#!/usr/bin/env python3 +""" Echo dependencies for given environment +""" + +from pathlib import Path +from argparse import ArgumentParser, RawDescriptionHelpFormatter + +import tomlkit + + +def get_build_requirements(repo_path): + toml = (Path(repo_path) / 'pyproject.toml').read_text() + config = tomlkit.loads(toml) + requires = config.get('build-system', {}).get('requires', []) + base_req = [R for R in requires if not 'numpy' in R] + return ' '.join(base_req) + + +def get_numpy_requirement(py_ver): + major, minor, *_ = py_ver.split('.') + assert major == "3" + np_version = "1.22.2" + minor = int(minor) + if minor >= 12: + np_version = "1.26.0" + elif minor >= 11: + np_version = "1.23.2" + return np_version + + +def get_parser(): + parser = ArgumentParser(description=__doc__, # Usage from docstring + formatter_class=RawDescriptionHelpFormatter) + parser.add_argument("py_ver", help='Python version e.g. 3.11') + parser.add_argument("repo_dir", help='Path to source repo') + return parser + + +def main(): + parser = get_parser() + args = parser.parse_args() + np_req = get_numpy_requirement(args.py_ver) + build_base = get_build_requirements(args.repo_dir) + print(f'{build_base} numpy=={np_req}') + + +if __name__ == '__main__': + main()