Skip to content
3 changes: 3 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@
depend on how OpenBLAS was compiled with OpenMP.
https://github.com/joblib/threadpoolctl/pull/228

- Fix OpenBLAS detection for conda package on Windows
https://github.com/joblib/threadpoolctl/pull/240

3.6.0 (2025-03-13)
==================

Expand Down
38 changes: 38 additions & 0 deletions tests/test_threadpoolctl.py
Original file line number Diff line number Diff line change
Expand Up @@ -913,3 +913,41 @@ def num_threads_created(limit: int) -> int:
nmc_1 = num_threads_created(1)
nmc_4 = num_threads_created(4)
assert nmc_4 - nmc_1 == 6


@pytest.mark.skipif(os.getenv("CONDA_PREFIX") is None, reason="conda-specific test")
@pytest.mark.parametrize("module", ["numpy", "scipy.linalg"])
def test_conda_blas_detection_after_import(module):
pytest.importorskip(module)

info = threadpool_info_from_subprocess(module)

conda = which("conda") or which("micromamba") or which("mamba")
conda_list_output = subprocess.check_output([conda, "list", "--json"], text=True)
conda_list_items = json.loads(conda_list_output)
blas_names_from_conda = [
each["name"]
for each in conda_list_items
if any(blas_lib in each["name"] for blas_lib in ["openblas", "mkl"])
]
blas_names_from_conda = [each.replace("lib", "") for each in blas_names_from_conda]

if "accelerate" in conda_list_output:
pytest.skip("threadpoolctl does not know how to inspect Accelerate")

if not blas_names_from_conda:
pytest.skip(
f"{module} has been installed with pip, this is a conda-specific test"
)

blas_info = select(info, user_api="blas")
assert len(blas_info) > 0

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should inspect the output of pip freeze and/or conda list to set expectations on the presence of openblas.


# Flexiblas is built from source on our CI. At the time of writing, it is not
# available in the conda-forge channel.
blas_names_from_threadpoolctl = [
each["internal_api"]
for each in blas_info
if each["internal_api"] != "flexiblas"
]
assert set(blas_names_from_threadpoolctl).issubset(blas_names_from_conda)
1 change: 1 addition & 0 deletions threadpoolctl.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,7 @@ class OpenBLASController(LibController):
"libopenblas",
"libblas", # legacy conda-forge Windows shim, see _make_controller_from_path
"libscipy_openblas",
"openblas", # Windows conda package use openblas.dll
)

_symbol_prefixes = ("", "scipy_")
Expand Down
Loading