Skip to content

Commit 728d0d8

Browse files
committed
DEV: work around pathlib bug affecting dev.py for Python 3.9 on Windows
Also remove a workaround in a Windows job for this issue, and clean up the code for `dev.py --win-cp-openblas` some more. Note that this doesn't always work - in particular, `openblas_support.py` will silently fail to do the right thing on Windows if the git repo checkout is on the D: drive while OpenBLAS gets downloaded to the C: drive. That is happening in a GHA CI job, and it's plagued us on Azure before too (see scipygh-11967).
1 parent d81c948 commit 728d0d8

File tree

2 files changed

+19
-13
lines changed

2 files changed

+19
-13
lines changed

.github/workflows/windows.yml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -112,11 +112,10 @@ jobs:
112112
113113
- name: Build
114114
run: |
115-
# TODO: remove the build-dir and install-prefix flags once dev.py
116-
# supplies meson with absolute paths. This is due to a pathlib bug
117-
# on cp39-win.
118-
python dev.py --build-dir=$pwd\build --install-prefix=$pwd\build-install build -j 2 --win-cp-openblas
119-
meson install -C build
115+
python dev.py build -j 2 --win-cp-openblas
116+
# Necessary because GitHub Actions checks out the repo to D:\ while OpenBLAS
117+
# got installed to C:\ higher up. The copying with `--win-cp-openblas` fails
118+
# when things are split over drives.
120119
cp C:\opt\64\bin\*.dll $pwd\build-install\Lib\site-packages\scipy\.libs\
121120
python tools\openblas_support.py --write-init $PWD\build-install\Lib\site-packages\scipy\
122121

dev.py

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -306,14 +306,22 @@ def __init__(self, args=None):
306306
self.root = Path(__file__).parent.absolute()
307307
if not args:
308308
return
309+
309310
self.build = Path(args.build_dir).resolve()
310311
if args.install_prefix:
311312
self.installed = Path(args.install_prefix).resolve()
312313
else:
313314
self.installed = self.build.parent / (self.build.stem + "-install")
315+
316+
if sys.platform == 'win32' and sys.version_info < (3, 10):
317+
# Work around a pathlib bug; these must be absolute paths
318+
self.build = Path(os.path.abspath(self.build))
319+
self.installed = Path(os.path.abspath(self.installed))
320+
314321
# relative path for site-package with py version
315322
# i.e. 'lib/python3.10/site-packages'
316323
self.site = self.get_site_packages()
324+
print(self.site)
317325

318326
def add_sys_path(self):
319327
"""Add site dir to sys.path / PYTHONPATH"""
@@ -595,7 +603,8 @@ def copy_openblas(cls, dirs):
595603
'command did not manage to find OpenBLAS '
596604
'succesfully. Try running manually on the '
597605
'command prompt for more information.')
598-
return result.returncode
606+
print("OpenBLAS copy failed!")
607+
sys.exit(result.returncode)
599608

600609
# Skip the drive letter of the path -> /c to get Windows drive
601610
# to be appended correctly to avoid "C:\c\..." from stdout.
@@ -609,6 +618,7 @@ def copy_openblas(cls, dirs):
609618
# Look in bin subdirectory for OpenBLAS binaries.
610619
bin_path = openblas_lib_path.parent / 'bin'
611620
# Locate, make output .libs directory in Scipy install directory.
621+
print(dirs.site)
612622
scipy_path = dirs.site / 'scipy'
613623
libs_path = scipy_path / '.libs'
614624
libs_path.mkdir(exist_ok=True)
@@ -623,9 +633,10 @@ def copy_openblas(cls, dirs):
623633
# so OpenBLAS gets found
624634
openblas_support = import_module_from_path(
625635
'openblas_support',
626-
dirs.root / 'tools' / 'openblas_support.py')
636+
dirs.root / 'tools' / 'openblas_support.py'
637+
)
627638
openblas_support.make_init(scipy_path)
628-
return 0
639+
print('OpenBLAS copied')
629640

630641
@classmethod
631642
def run(cls, add_path=False, **kwargs):
@@ -642,11 +653,7 @@ def run(cls, add_path=False, **kwargs):
642653
cls.build_project(dirs, args, env)
643654
cls.install_project(dirs, args)
644655
if args.win_cp_openblas and platform.system() == 'Windows':
645-
if cls.copy_openblas(dirs) == 0:
646-
print('OpenBLAS copied')
647-
else:
648-
print("OpenBLAS copy failed!")
649-
sys.exit(1)
656+
cls.copy_openblas(dirs)
650657

651658
# add site to sys.path
652659
if add_path:

0 commit comments

Comments
 (0)