Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions openviking/pyagfs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,15 @@ def _find_ragfs_so():
try:
# The ragfs-python crate is built with PyO3's stable ABI. Do not load
# cpython-specific artifacts from older source-checkout builds.
abi3_suffix = ".abi3.so"
if sys.platform == "win32":
abi3_suffix = ".abi3.pyd"
abi3_exact = _LIB_DIR / f"ragfs_python{abi3_suffix}"
if abi3_exact.exists():
return str(abi3_exact)
for filename in ("ragfs_python.pyd", "ragfs_python.abi3.pyd"):
exact_path = _LIB_DIR / filename
if exact_path.exists():
return str(exact_path)
else:
abi3_exact = _LIB_DIR / "ragfs_python.abi3.so"
if abi3_exact.exists():
return str(abi3_exact)
# Glob fallback handles platform-tagged abi3 artifacts if any.
for pattern in ("ragfs_python.abi3.*",):
matches = glob.glob(str(_LIB_DIR / pattern))
Expand Down
13 changes: 9 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,9 +344,14 @@ def build_ragfs_python_artifact(self):
with zipfile.ZipFile(str(whl_files[0])) as zf:
for name in zf.namelist():
basename = Path(name).name
if basename.startswith("ragfs_python.abi3.") and (
basename.endswith(".so") or basename.endswith(".pyd")
):
is_ragfs_extension = (
basename == "ragfs_python.pyd"
or (
basename.startswith("ragfs_python.abi3.")
and basename.endswith((".so", ".pyd"))
)
)
if is_ragfs_extension:
target_path = ragfs_lib_dir / basename
with zf.open(name) as src, open(target_path, "wb") as dst:
dst.write(src.read())
Expand All @@ -357,7 +362,7 @@ def build_ragfs_python_artifact(self):
break

if not extracted:
message = "Could not find ragfs_python abi3 .so/.pyd in built wheel."
message = "Could not find ragfs_python stable-ABI native extension in built wheel."
if require_ragfs_artifact:
raise RuntimeError(message)
print(f"[Warning] {message}")
Expand Down
8 changes: 8 additions & 0 deletions tests/misc/test_abi3_packaging_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,14 @@ def test_build_workflow_smoke_tests_linux_and_macos_ragfs_binding_import():
assert "Loaded RAGFS binding client" in build_workflow


def test_setup_extracts_windows_ragfs_python_pyd_from_maturin_wheel():
setup_py = _read_text("setup.py")

assert 'basename == "ragfs_python.pyd"' in setup_py
assert 'basename.startswith("ragfs_python.abi3.")' in setup_py
assert "stable-ABI native extension" in setup_py


def test_windows_abi3_backend_uses_stable_python_linkage():
setup_py = _read_text("setup.py")
src_cmake = _read_text("src/CMakeLists.txt")
Expand Down
14 changes: 14 additions & 0 deletions tests/misc/test_pyagfs_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,17 @@ def test_pyagfs_loader_ignores_cpython_specific_artifact(monkeypatch, tmp_path:
monkeypatch.setattr(pyagfs, "_LIB_DIR", tmp_path)

assert pyagfs._find_ragfs_so() is None


def test_pyagfs_loader_finds_windows_maturin_abi3_pyd(monkeypatch, tmp_path: Path):
import openviking.pyagfs as pyagfs

cpython_artifact = tmp_path / "ragfs_python.cp310-win_amd64.pyd"
abi3_artifact = tmp_path / "ragfs_python.pyd"
cpython_artifact.write_bytes(b"old")
abi3_artifact.write_bytes(b"new")

monkeypatch.setattr(pyagfs, "_LIB_DIR", tmp_path)
monkeypatch.setattr(pyagfs.sys, "platform", "win32")

assert pyagfs._find_ragfs_so() == str(abi3_artifact)
Loading