Skip to content

Commit

Permalink
Try standardizing build requirements
Browse files Browse the repository at this point in the history
  • Loading branch information
matthew-brett committed Nov 10, 2023
1 parent 8a93604 commit 54eb854
Show file tree
Hide file tree
Showing 9 changed files with 60 additions and 64 deletions.
9 changes: 6 additions & 3 deletions .github/workflows/build.ps1
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
8 changes: 3 additions & 5 deletions .github/workflows/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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}/"
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/wheels-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/wheels-macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
6 changes: 0 additions & 6 deletions .github/workflows/wheels-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,14 @@ 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:
submodules: true
- 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
Expand Down
14 changes: 2 additions & 12 deletions config.sh
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
35 changes: 0 additions & 35 deletions get_numpy_version.py

This file was deleted.

2 changes: 1 addition & 1 deletion nipy
48 changes: 48 additions & 0 deletions print_deps.py
Original file line number Diff line number Diff line change
@@ -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()

0 comments on commit 54eb854

Please sign in to comment.