From f21613c19b3ed90a1ebdde613694bfe2ff27207c Mon Sep 17 00:00:00 2001 From: Alexander Condello Date: Tue, 5 May 2026 13:57:14 -0700 Subject: [PATCH] Try to use pkgconf-pypi for blas dependency --- README.rst | 2 +- dwave/optimization/_build/_find_openblas.py | 33 -------------- meson.build | 30 +++---------- pyproject.toml | 50 ++++++++++----------- 4 files changed, 31 insertions(+), 84 deletions(-) delete mode 100644 dwave/optimization/_build/_find_openblas.py diff --git a/README.rst b/README.rst index 81454dacc..a0e768b31 100644 --- a/README.rst +++ b/README.rst @@ -86,7 +86,7 @@ for more details. .. code-block:: bash pip install --group dev --group blas - pip install --editable . \ + FORCE_PKGCONF_PYPI=1 pip install --editable . \ --no-build-isolation \ --config-settings=editable-verbose=true \ --config-settings=setup-args="-Dblas=enabled" diff --git a/dwave/optimization/_build/_find_openblas.py b/dwave/optimization/_build/_find_openblas.py deleted file mode 100644 index 255a701fa..000000000 --- a/dwave/optimization/_build/_find_openblas.py +++ /dev/null @@ -1,33 +0,0 @@ -#!/usr/bin/env python3 - -# Copyright 2025 D-Wave -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import os -import os.path -import sys - -try: - import scipy_openblas64 -except ImportError: - sys.exit() - -# meson needs the include_dir to be relative -print(os.path.relpath(scipy_openblas64.get_include_dir(), os.getcwd())) - -# But the actual library path needs to be absolute -print(scipy_openblas64.get_lib_dir()) - -# This one isn't a path at all -print(scipy_openblas64.get_library()) diff --git a/meson.build b/meson.build index 690d71652..94dfda4df 100644 --- a/meson.build +++ b/meson.build @@ -60,30 +60,12 @@ dwave_optimization_dependencies = [] # Set up BLAS. _find_openblas.py will return the include directory, the library # directory and the library name. if not get_option('blas').disabled() - blasinfo = run_command( - ['dwave/optimization/_build/_find_openblas.py'], - capture: true, - check: true - ).stdout().splitlines() - if blasinfo.length() != 0 - assert(blasinfo.length() == 3, '_find_openblas.py returned an unexpected value') - - dwave_optimization_dependencies += [ - declare_dependency( - dependencies: cpp.find_library( - blasinfo[2], - dirs: blasinfo[1], - required: true, - ), - include_directories: blasinfo[0], - ) - ] - elif get_option('blas').enabled() - error( - 'No BLAS available.' + - 'Install scipy_openblas64 into the build environment or disable the blas user option' - ) - endif + blas = dependency( + 'scipy-openblas', + method: 'pkg-config', + required: get_option('blas').enabled(), + ) + dwave_optimization_dependencies += [blas] endif if host_machine.system() == 'windows' diff --git a/pyproject.toml b/pyproject.toml index e2067a8a1..c129d8bc2 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -55,6 +55,7 @@ Documentation = "https://docs.dwavequantum.com" [dependency-groups] blas = [ # Optional build requirement, last refreshed April 2026 + "pkgconf==2.5.1.post2", "scipy_openblas64==0.3.31.188.0", ] build = [ @@ -93,20 +94,18 @@ test = [ [tool.cibuildwheel] build-verbosity = "1" -skip = "pp* *musllinux*" +skip = "*musllinux*" -# When building with cibuildwheel, we want scipy_openblas64 available to the -# build step. There isn't (as of Dec 2025) a way to override the -# build-system.requires so we need to build without isolation -before-build = "pip install --group blas-build" +before-build = "pip install --group build" build-frontend = { name = "build", args = ["--no-isolation"] } +# Customize the test running by installing our test requirements and by turning +# on -Werror before-test = "pip install --group test" test-command = "python -Werror -m unittest discover {project}/tests/" [tool.cibuildwheel.config-settings] compile-args = ["-v"] -setup-args = ["-Dblas=enabled"] # require BLAS [tool.cibuildwheel.linux] archs = "x86_64 aarch64" @@ -115,11 +114,11 @@ archs = "x86_64 aarch64" # We follow NumPy and don't build universal wheels, see https://github.com/numpy/numpy/pull/20787 archs = "x86_64 arm64" -# Lowest version that has the C++ features we want, see https://cibuildwheel.pypa.io/en/stable/cpp_standards/ -environment = "MACOSX_DEPLOYMENT_TARGET=10.13" +environment = { MACOSX_DEPLOYMENT_TARGET = "10.13" } [tool.cibuildwheel.windows] archs = "AMD64" + repair-wheel-command = [ "pip install delvewheel", # We put the commands in an .sh so we can use bash @@ -130,7 +129,10 @@ repair-wheel-command = [ # For Python3.12+, rather than building individual wheels we build an abi3 # wheel. 313t and 314t do not support abi wheels yet. select = "cp31[!01]-*" # uses fnmatch, will fail for 3.20+ but good enough for now -build-frontend = { name = "build", args = ["-Csetup-args=-Dpython.allow_limited_api=true", "--no-isolation"] } + +inherit.config-settings = "append" +config-settings = { "setup-args" = ["-Dpython.allow_limited_api=true"] } + inherit.repair-wheel-command = "append" repair-wheel-command = [ "pip install abi3audit", @@ -138,26 +140,22 @@ repair-wheel-command = [ ] [[tool.cibuildwheel.overrides]] -select = "*-????linux_*" -inherit.repair-wheel-command = "prepend" -repair-wheel-command = "python /project/dwave/optimization/_build/_fix_rpath.py {wheel}" +# For everything we build except macosx_x86_64, we want to include scipy-openblas +select = "*-{????linux_*,macosx_arm64,win_*}" -[[tool.cibuildwheel.overrides]] -select = "*-macosx_*" -inherit.repair-wheel-command = "prepend" -repair-wheel-command = "python ./dwave/optimization/_build/_fix_rpath.py {wheel}" +inherit.environent = "append" +environment = { FORCE_PKGCONF_PYPI = "1" } + +inherit.before-build = "append" +before-build = "pip install --group blas" + +inhert.test-command = "append" +test-command = "python -c \"from dwave.optimization.symbols import MatrixMultiply; assert(MatrixMultiply.implementation() == 'blas')\"" [[tool.cibuildwheel.overrides]] -# We need a universal build of scipy_openblas so we need to make one on the fly -select = "*-macosx_*" -before-build = [ - "pip download --group blas -d .openblas_arm64 --platform macosx_11_0_arm64 --no-deps", - "pip download --group blas -d .openblas_x86_64 --platform macosx_11_0_x86_64 --no-deps", - "pip install delocate", - "delocate-merge .openblas_x86_64/scipy_openblas*.whl .openblas_arm64/scipy_openblas*.whl -w .openblas", - "pip install .openblas/scipy_openblas*.whl", - "pip install --group build", -] +select = "*-{????linux,macosx}_*" +inherit.repair-wheel-command = "prepend" +repair-wheel-command = "python {project}/dwave/optimization/_build/_fix_rpath.py {wheel}" [tool.coverage.run] source = ["dwave/optimization"]