unittests: Unbreak Python bytecompile tests with Xcode Python

Apple sets sys.pycache_prefix to an user-wide cache folder, so it needs
to be prepended to the root for the glob to work correctly.
This commit is contained in:
L. E. Segovia 2025-01-31 01:06:55 +00:00 committed by Nirbheek Chauhan
parent f75e45887c
commit e793b1bc1a
1 changed files with 7 additions and 2 deletions

View File

@ -1,7 +1,7 @@
# SPDX-License-Identifier: Apache-2.0
# Copyright 2016-2021 The Meson development team
import glob, os, pathlib, shutil, subprocess, unittest
import glob, os, pathlib, shutil, subprocess, sys, unittest
from run_tests import (
Backend
@ -64,7 +64,12 @@ python = pymod.find_installation('python3', required: true)
for file in files:
realfile = os.path.join(root, file)
if file.endswith('.py'):
cached = glob.glob(realfile+'?') + glob.glob(os.path.join(root, '__pycache__', os.path.splitext(file)[0] + '*.pyc'))
# FIXME: relpath must be adjusted for windows path behaviour
if hasattr(sys, "pycache_prefix"):
root = os.path.join(sys.pycache_prefix, os.path.relpath(root, '/'))
else:
root = os.path.join(root, '__pycache__')
cached = glob.glob(realfile+'?') + glob.glob(os.path.join(root, os.path.splitext(file)[0] + '*.pyc'))
if py2 and cc.get_id() == 'msvc':
# MSVC python installs python2/python3 into the same directory
self.assertLength(cached, 4)