Skip to content

Commit c921217

Browse files
authored
Merge pull request #120 from mattip/pkgconfig2
redo pkgconfig file link and cflags, use RTLD_GLOBAL to load DLL, add download script
2 parents 61893b4 + 8e38875 commit c921217

File tree

6 files changed

+132
-8
lines changed

6 files changed

+132
-8
lines changed

.github/workflows/windows.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ jobs:
109109
# of a pyproject.toml project
110110
sed -e "s/openblas64/openblas32/" -i pyproject.toml
111111
sed -e "s/openblas_get_config64_/openblas_get_config/" -i local/scipy_openblas32/__init__.py
112+
sed -e "s/cflags_suffix64 =.*/cflags_suffix64 = ''/" -i local/scipy_openblas32/__init__.py
112113
sed -e "s/openblas64/openblas32/" -i local/scipy_openblas32/__init__.py
113114
sed -e "s/openblas64/openblas32/" -i local/scipy_openblas32/__main__.py
114115
fi

local/scipy_openblas64/__init__.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,12 @@ def get_pkg_config():
5656
pkg-config for build systems like meson
5757
"""
5858
if sys.platform == "win32":
59-
extralib = "-defaultlib:advapi32 -lgfortran -defaultlib:advapi32 -lgfortran"
59+
extralib = "-defaultlib:advapi32 -lgfortran -lquadmath"
60+
libs_flags = f"-L${{libdir}} -l{get_library()}"
6061
else:
61-
extralib = "-lm -lpthread -lgfortran -lm -lpthread -lgfortran"
62+
extralib = "-lm -lpthread -lgfortran -lquadmath -L${libdir} -lopenblas_python"
63+
libs_flags = ""
64+
cflags_suffix64 = "-DBLAS_SYMBOL_SUFFIX=64_ -DHAVE_BLAS_ILP64"
6265
return dedent(f"""\
6366
libdir={get_lib_dir()}
6467
includedir={get_include_dir()}
@@ -69,9 +72,9 @@ def get_pkg_config():
6972
Description: OpenBLAS is an optimized BLAS library based on GotoBLAS2 1.13 BSD version
7073
Version: ${{version}}
7174
URL: https://github.com/xianyi/OpenBLAS
72-
Libs: -L${{libdir}} -l{get_library()}
75+
Libs: {libs_flags}
7376
Libs.private: ${{extralib}}
74-
Cflags: -I${{includedir}}
77+
Cflags: -I${{includedir}} {cflags_suffix64}
7578
""")
7679

7780

@@ -108,7 +111,7 @@ def get_openblas_config():
108111
# Get openblas*
109112
libnames = [x for x in os.listdir(lib_dir) if x.startswith("libopenblas")]
110113

111-
dll = ctypes.CDLL(os.path.join(lib_dir, libnames[0]))
114+
dll = ctypes.CDLL(os.path.join(lib_dir, libnames[0]), ctypes.RTLD_GLOBAL)
112115
openblas_config = dll.openblas_get_config64_
113116
openblas_config.restype = ctypes.c_char_p
114117
bytes = openblas_config()

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ build-backend = "setuptools.build_meta"
88

99
[project]
1010
name = "scipy_openblas64"
11-
version = "0.3.23.293.1"
11+
version = "0.3.23.293.2"
1212
requires-python = ">=3.7"
1313
description = "Provides OpenBLAS for python packaging"
1414
readme = "README.md"

tools/build_wheel.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ if [ "${INTERFACE64}" != "1" ]; then
4545
rm *.bak
4646
mv local/scipy_openblas64 local/scipy_openblas32
4747
sed -e "s/openblas_get_config64_/openblas_get_config/" -i.bak local/scipy_openblas32/__init__.py
48+
sed -e "s/cflags_suffix64 =.*/cflags_suffix64 = ''/" -i.bak local/scipy_openblas32/__init__.py
4849
sed -e "s/openblas64/openblas32/" -i.bak local/scipy_openblas32/__main__.py
4950
sed -e "s/openblas64/openblas32/" -i.bak local/scipy_openblas32/__init__.py
5051
rm local/scipy_openblas32/*.bak

tools/download-wheels.py

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
#!/usr/bin/env python3
2+
"""
3+
Script to download NumPy wheels from the Anaconda staging area.
4+
5+
Usage::
6+
7+
$ ./tools/download-wheels.py <version> -w <optional-wheelhouse>
8+
9+
The default wheelhouse is ``release/installers``.
10+
11+
Dependencies
12+
------------
13+
14+
- beautifulsoup4
15+
- urllib3
16+
17+
Examples
18+
--------
19+
20+
While in the repository root::
21+
22+
$ python tools/download-wheels.py 1.19.0
23+
$ python tools/download-wheels.py 1.19.0 -w ~/wheelhouse
24+
25+
"""
26+
import os
27+
import re
28+
import shutil
29+
import argparse
30+
31+
import urllib3
32+
from bs4 import BeautifulSoup
33+
34+
__version__ = "0.1"
35+
36+
# Edit these for other projects.
37+
URL = "https://anaconda.org/scientific-python-nightly-wheels"
38+
39+
# Name endings of the files to download.
40+
WHL = r"-.*\.whl$"
41+
ZIP = r"\.zip$"
42+
GZIP = r"\.tar\.gz$"
43+
SUFFIX = rf"({WHL}|{GZIP}|{ZIP})"
44+
45+
46+
def get_wheel_names(package, version):
47+
""" Get wheel names from Anaconda HTML directory.
48+
49+
This looks in the Anaconda multibuild-wheels-staging page and
50+
parses the HTML to get all the wheel names for a release version.
51+
52+
Parameters
53+
----------
54+
version : str
55+
The release version. For instance, "1.18.3".
56+
57+
"""
58+
http = urllib3.PoolManager(cert_reqs="CERT_REQUIRED")
59+
tmpl = re.compile(rf"^.*{package.replace('-', '_')}-{version}{SUFFIX}")
60+
index_url = f"{URL}/{package}/files"
61+
index_html = http.request("GET", index_url)
62+
soup = BeautifulSoup(index_html.data, "html.parser")
63+
return soup.find_all(string=tmpl)
64+
65+
66+
def download_wheels(package, version, wheelhouse):
67+
"""Download release wheels.
68+
69+
The release wheels for the given package version are downloaded
70+
into the given directory.
71+
72+
Parameters
73+
----------
74+
package : str
75+
The package to download, scipy-openblas32 or scipy-openblas64
76+
version : str
77+
The release version. For instance, "1.18.3".
78+
wheelhouse : str
79+
Directory in which to download the wheels.
80+
81+
"""
82+
http = urllib3.PoolManager(cert_reqs="CERT_REQUIRED")
83+
wheel_names = get_wheel_names(package, version)
84+
85+
for i, wheel_name in enumerate(wheel_names):
86+
wheel_url = f"{URL}/{package}/{version}/download/{wheel_name}"
87+
wheel_path = os.path.join(wheelhouse, wheel_name)
88+
with open(wheel_path, "wb") as f:
89+
with http.request("GET", wheel_url, preload_content=False,) as r:
90+
print(f"{i + 1:<4}{wheel_name}")
91+
shutil.copyfileobj(r, f)
92+
print(f"\nTotal files downloaded: {len(wheel_names)}")
93+
94+
95+
if __name__ == "__main__":
96+
parser = argparse.ArgumentParser()
97+
parser.add_argument(
98+
"--package",
99+
required=True,
100+
help="package to download.")
101+
parser.add_argument(
102+
"--version",
103+
required=True,
104+
help="package version to download.")
105+
parser.add_argument(
106+
"-w", "--wheelhouse",
107+
default=os.path.join(os.getcwd(), "release", "installers"),
108+
help="Directory in which to store downloaded wheels\n"
109+
"[defaults to <cwd>/release/installers]")
110+
111+
args = parser.parse_args()
112+
113+
wheelhouse = os.path.expanduser(args.wheelhouse)
114+
if not os.path.isdir(wheelhouse):
115+
raise RuntimeError(
116+
f"{wheelhouse} wheelhouse directory is not present."
117+
" Perhaps you need to use the '-w' flag to specify one.")
118+
119+
download_wheels(args.package, args.version, wheelhouse)

tools/upload_to_anaconda_staging.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# Upload tar.gz and wheels to ananconda.org
33

44
upload_wheels() {
5-
set +e -x
5+
set -x
66
if [[ "$(uname -s)" == CYGWIN* ]]; then
77
our_wd=$(cygpath "$START_DIR")
88
cd $our_wd
@@ -17,7 +17,7 @@ upload_wheels() {
1717
else
1818
echo "Uploading OpenBLAS $VERSION to anaconda.org staging:"
1919

20-
tarballs=$(ls -d builds/openblas*.zip libs/openblas*.tar.gz 2>/dev/null)
20+
tarballs=$(ls -d builds/openblas*.zip libs/openblas*.tar.gz 2>/dev/null && true)
2121
anaconda -t $ANACONDA_SCIENTIFIC_PYTHON_UPLOAD upload \
2222
--no-progress --force -u scientific-python-nightly-wheels \
2323
-t file -p "openblas-libs" -v "$VERSION" \

0 commit comments

Comments
 (0)