Skip to content

Commit 54eb854

Browse files
committed
Try standardizing build requirements
1 parent 8a93604 commit 54eb854

File tree

9 files changed

+60
-64
lines changed

9 files changed

+60
-64
lines changed

.github/workflows/build.ps1

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
echo "::group::Build wheel"
2-
pip install @($env:BUILD_DEPENDS.split())
3-
pip wheel -w "${env:WHEEL_SDIR}" --no-build-isolation ".\${env:REPO_DIR}"
4-
ls -l "${env:GITHUB_WORKSPACE}/${env:WHEEL_SDIR}/"
2+
$wheel_sdir = "wheelhouse"
3+
pip install tomlkit
4+
$build_dep = python .\print_deps.py $env:MB_PYTHON_VERSION ${env:REPO_DIR}
5+
pip install @($build_dep.split())
6+
pip wheel -w "${wheel_sdir}" --no-build-isolation ".\${env:REPO_DIR}"
7+
ls -l "${env:GITHUB_WORKSPACE}/${wheel_sdir}/"
58
echo "::endgroup::"
69

710
echo "::group::Install wheel"

.github/workflows/build.sh

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then
44
# if php is installed, brew tries to reinstall these after installing openblas
55
brew remove --ignore-dependencies curl php
66

7-
brew install pkg-config
7+
brew install pkg-config openblas
88

99
if [[ "$PLAT" == "arm64" ]]; then
1010
export MACOSX_DEPLOYMENT_TARGET="11.0"
@@ -25,10 +25,8 @@ echo "::group::Install a virtualenv"
2525
echo "::endgroup::"
2626

2727
echo "::group::Build wheel"
28-
np_dep=$(python ./get_numpy_version.py $MB_PYTHON_VERSION)
29-
export BUILD_DEPENDS="${BUILD_BASE} ${np_dep}"
30-
echo "Build depends: ${BUILD_DEPENDS}"
31-
echo "Build base: ${BUILD_BASE}"
28+
pip install tomlkit
29+
export BUILD_DEPENDS=$(python ./print_deps.py ${MB_PYTHON_VERSION} ${REPO_DIR})
3230
clean_code
3331
build_wheel
3432
ls -l "${GITHUB_WORKSPACE}/${WHEEL_SDIR}/"

.github/workflows/wheels-linux.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ jobs:
4848
MB_PYTHON_VERSION: ${{ matrix.python }}
4949
MB_ML_LIBC: ${{ matrix.mb-ml-libc }}
5050
MB_ML_VER: ${{ matrix.mb-ml-ver }}
51-
BUILD_BASE: "meson-python>=0.13 ninja cython>=3"
5251
steps:
5352
- uses: actions/checkout@v4
5453
with:

.github/workflows/wheels-macos.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ jobs:
3939
PLAT: ${{ matrix.platform }}
4040
MB_PYTHON_VERSION: ${{ matrix.python }}
4141
TRAVIS_OS_NAME: "osx"
42-
BUILD_BASE: "meson-python>=0.13 ninja cython>=3"
4342
steps:
4443
- uses: actions/checkout@v4
4544
with:

.github/workflows/wheels-windows.yml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,20 +29,14 @@ jobs:
2929
]
3030
env:
3131
BUILD_COMMIT: ${{ inputs.build-commit }}
32-
WHEEL_SDIR: wheelhouse
3332
MB_PYTHON_VERSION: ${{ matrix.python }}
34-
BUILD_BASE: "meson-python>=0.13 ninja cython>=3"
3533
steps:
3634
- uses: actions/checkout@v4
3735
with:
3836
submodules: true
3937
- uses: actions/setup-python@v4
4038
with:
4139
python-version: ${{ matrix.python }}
42-
- name: Set Numpy version
43-
run: |
44-
$np_dep = python .\get_numpy_version.py $env:MB_PYTHON_VERSION
45-
echo "BUILD_DEPENDS=${env:BUILD_BASE} ${np_dep}" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append
4640
- name: Build Wheel
4741
run: .github/workflows/build.ps1
4842
- uses: actions/upload-artifact@v3

config.sh

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,8 @@
11
# Define custom utilities
22
# Test for OSX with [ -n "$IS_MACOS" ]
33

4-
function pre_build {
5-
# Any stuff that you need to do before you start
6-
# building the wheels.
7-
# Runs in the root directory of this repository.
8-
# Workaround for Accelerate error; only on macOS.
9-
if [ -z "$IS_MACOS" ]; then return; fi
10-
brew install openblas
11-
}
12-
13-
function pip_wheel_cmd {
14-
local abs_wheelhouse=$1
15-
pip wheel $(pip_opts) -w $abs_wheelhouse --no-build-isolation .
4+
function pip_opts {
5+
echo "--no-build-isolation"
166
}
177

188
function run_tests {

get_numpy_version.py

Lines changed: 0 additions & 35 deletions
This file was deleted.

print_deps.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#!/usr/bin/env python3
2+
""" Echo dependencies for given environment
3+
"""
4+
5+
from pathlib import Path
6+
from argparse import ArgumentParser, RawDescriptionHelpFormatter
7+
8+
import tomlkit
9+
10+
11+
def get_build_requirements(repo_path):
12+
toml = (Path(repo_path) / 'pyproject.toml').read_text()
13+
config = tomlkit.loads(toml)
14+
requires = config.get('build-system', {}).get('requires', [])
15+
base_req = [R for R in requires if not 'numpy' in R]
16+
return ' '.join(base_req)
17+
18+
19+
def get_numpy_requirement(py_ver):
20+
major, minor, *_ = py_ver.split('.')
21+
assert major == "3"
22+
np_version = "1.22.2"
23+
minor = int(minor)
24+
if minor >= 12:
25+
np_version = "1.26.0"
26+
elif minor >= 11:
27+
np_version = "1.23.2"
28+
return np_version
29+
30+
31+
def get_parser():
32+
parser = ArgumentParser(description=__doc__, # Usage from docstring
33+
formatter_class=RawDescriptionHelpFormatter)
34+
parser.add_argument("py_ver", help='Python version e.g. 3.11')
35+
parser.add_argument("repo_dir", help='Path to source repo')
36+
return parser
37+
38+
39+
def main():
40+
parser = get_parser()
41+
args = parser.parse_args()
42+
np_req = get_numpy_requirement(args.py_ver)
43+
build_base = get_build_requirements(args.repo_dir)
44+
print(f'{build_base} numpy=={np_req}')
45+
46+
47+
if __name__ == '__main__':
48+
main()

0 commit comments

Comments
 (0)