Skip to content

Commit 23a815b

Browse files
authored
fix(conda): read conda-forge's CFEP-27 Windows layout in the smoke check (#2126) (#2127)
- util/conda_vendor.py: built_for recognises lib/python/site-packages, the layout conda-forge's CPython 3.15 uses on Windows (CFEP-27), beside Lib/site-packages, and reads the version from the pyXY build string for either. It returned the bare `python` before, failing the win-64 3.15 smoke. - tests/project/test_conda_windows_leg_2060.py: TestTheWindowsLayout covers the CFEP-27 path for built_for and end to end through smoke(). tests/project/test_conda_windows_leg_2060.py: 22 passed; the 2 new tests fail without the fix.
1 parent 93a6173 commit 23a815b

2 files changed

Lines changed: 30 additions & 6 deletions

File tree

‎tests/project/test_conda_windows_leg_2060.py‎

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
previous ``FOR`` loop wrote ``%A``, a syntax error in a batch file.
1919
* :class:`TestPortableExecutable` and :class:`TestTheWindowsLayout`:
2020
:file:`util/conda_vendor.py` reads a ``.pyd``'s PE machine, and ``--smoke``
21-
takes a Windows package's ``Lib/site-packages``, whose path names no Python.
21+
takes a Windows package's ``Lib/site-packages``, or from Python 3.15 its
22+
``lib/python/site-packages`` (conda-forge's CFEP-27), whose path names no Python.
2223
2324
Nothing here runs on Windows; what a real Conda Update run shows is the rest.
2425
@@ -318,14 +319,25 @@ def test_the_python_is_read_from_the_build_string(self) -> None:
318319
posix = pathlib.Path('root') / 'lib' / 'python3.14' / 'site-packages'
319320
self.assertEqual(vendor.built_for(posix, {'build': 'py39_0'}), 'python3.14')
320321

321-
def smoke(self, build: 'str') -> 'tuple[int, str]':
322+
def test_the_cfep_27_layout_is_read_from_the_build_string(self) -> None:
323+
"""conda-forge's Python 3.15 on Windows has ``lib/python/site-packages``, naming no version."""
324+
vendor = load('conda_vendor')
325+
site = pathlib.Path('root') / 'lib' / 'python' / 'site-packages'
326+
self.assertEqual(vendor.built_for(site, {'build': 'py315_0'}), 'python3.15')
327+
self.assertEqual(vendor.built_for(site, {'build': 'h1a2b3c4_0'}),
328+
"lib/python/site-packages with build string 'h1a2b3c4_0'")
329+
# Only under lib: anything else named python is not the layout.
330+
other = pathlib.Path('root') / 'opt' / 'python' / 'site-packages'
331+
self.assertEqual(vendor.built_for(other, {'build': 'py315_0'}), 'python')
332+
333+
def smoke(self, build: 'str', site: 'str' = 'Lib/site-packages') -> 'tuple[int, str]':
322334
vendor = load('conda_vendor')
323335
files = dict({'pcapkit/__init__.py': SHIM.encode()}, **DISTRIBUTION)
324336
files['pcapkit/_extern/native/_speedups.pyd'] = pe(0x8664)
325337
files['pcapkit/_extern/native-1.0.dist-info/RECORD'] = (
326338
b'native/__init__.py,,\nnative/_speedups.pyd,,\nnative-1.0.dist-info/METADATA,,\n'
327339
b'native-1.0.dist-info/RECORD,,\n')
328-
members = {f'Lib/site-packages/{name}': data for name, data in files.items()}
340+
members = {f'{site}/{name}': data for name, data in files.items()}
329341
members['info/index.json'] = json.dumps({'name': 'pypcapkit', 'subdir': 'win-64', 'build': build}).encode()
330342
with tempfile.TemporaryDirectory() as temp:
331343
package = pathlib.Path(temp) / 'pypcapkit-0-py_0.tar.bz2'
@@ -347,6 +359,11 @@ def test_a_windows_package_for_this_python_passes(self) -> None:
347359
self.assertEqual(status, 0, log)
348360
self.assertIn('win-64: 1 native binaries read, none failing', log)
349361

362+
def test_a_cfep_27_windows_package_for_this_python_passes(self) -> None:
363+
status, log = self.smoke(f'py{self.PYTHON.replace(".", "")}h0_0', site='lib/python/site-packages')
364+
self.assertEqual(status, 0, log)
365+
self.assertIn('win-64: 1 native binaries read, none failing', log)
366+
350367
def test_a_windows_package_for_another_python_fails(self) -> None:
351368
status, log = self.smoke('py27_0')
352369
self.assertEqual(status, 1, log)

‎util/conda_vendor.py‎

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -906,19 +906,26 @@ def runner_platform() -> 'Optional[str]':
906906
None)
907907

908908

909+
#: The ``site-packages`` of a Windows package, which names no Python: conda-forge's
910+
#: up to 3.14, and its CFEP-27 one from 3.15 on.
911+
WINDOWS_SITES = (('Lib', 'site-packages'), ('lib', 'python', 'site-packages'))
912+
913+
909914
def built_for(site: 'pathlib.Path', index: 'dict[str, Any]') -> 'str':
910915
"""The ``pythonX.Y`` a package's ``site-packages`` at ``site`` is for, or what it is if not that.
911916
912917
A POSIX package names it in the path, ``lib/pythonX.Y/site-packages``. A
913-
Windows one has ``Lib/site-packages`` for every version (#2060), so it is read
918+
Windows one does not (#2060): ``Lib/site-packages`` up to 3.14, and from 3.15
919+
``lib/python/site-packages``, conda-forge's CFEP-27 layout. So that is read
914920
from the ``pyXY`` that starts the build string in ``info/index.json``.
915921
916922
"""
917-
if site.parent.name != 'Lib':
923+
layout = next((parts for parts in WINDOWS_SITES if site.parts[-len(parts):] == parts), None)
924+
if layout is None:
918925
return site.parent.name
919926
match = re.match(r'py(\d)(\d+)(?![0-9])', str(index.get('build', '')))
920927
if match is None:
921-
return f'Lib/site-packages with build string {index.get("build")!r}'
928+
return f'{"/".join(layout)} with build string {index.get("build")!r}'
922929
return f'python{match.group(1)}.{match.group(2)}'
923930

924931

0 commit comments

Comments
 (0)