mirror of
https://github.com/RustPython/RustPython.git
synced 2026-10-28 18:59:04 +08:00
Align JSON array hooks and libraries with Python 3.15 (#9135)
Generate the JSON library and selected tests with update_lib from CPython d220409a13b77de7a6c30abe16ea90db01528edc, preserving native bootstrap workarounds and test markers. Exclude generated cache directories at the library copy boundary. Assisted-by: OpenAI Codex:model version unavailable
This commit is contained in:
1 parent
8a9d66cfb3
commit
498adff3a9
14 files changed
+327
-65
No files matched your search
@@ -16,6 +16,14 @@ import shutil
|
||||
import sys
|
||||
|
||||
|
||||
def _ignore_bytecode_caches(directory: str, names: list[str]) -> set[str]:
|
||||
return {
|
||||
name
|
||||
for name in names
|
||||
if name == "__pycache__" and (pathlib.Path(directory) / name).is_dir()
|
||||
}
|
||||
|
||||
|
||||
def _copy_single(
|
||||
src_path: pathlib.Path,
|
||||
lib_path: pathlib.Path,
|
||||
@@ -38,7 +46,7 @@ def _copy_single(
|
||||
if verbose:
|
||||
print(f"Copying directory: {src_path} -> {lib_path}")
|
||||
lib_path.parent.mkdir(parents=True, exist_ok=True)
|
||||
shutil.copytree(src_path, lib_path)
|
||||
shutil.copytree(src_path, lib_path, ignore=_ignore_bytecode_caches)
|
||||
else:
|
||||
if verbose:
|
||||
print(f"Copying file: {src_path} -> {lib_path}")
|
||||
|
||||
@@ -57,6 +57,45 @@ class TestCopySingle(unittest.TestCase):
|
||||
|
||||
self.assertEqual(dst.read_text(), "new content")
|
||||
|
||||
def test_directory_copy_excludes_bytecode_cache_directories(self):
|
||||
from update_lib.cmd_copy_lib import _copy_single
|
||||
|
||||
with tempfile.TemporaryDirectory() as tmpdir:
|
||||
root = pathlib.Path(tmpdir)
|
||||
src = root / "source"
|
||||
dst = root / "destination"
|
||||
for relative in ("__pycache__", "package/__pycache__", "assets"):
|
||||
(src / relative).mkdir(parents=True)
|
||||
files = {
|
||||
"__init__.py": b"source\n",
|
||||
"package/module.py": b"nested source\n",
|
||||
"assets/data.bin": b"\x00\xffasset",
|
||||
"assets/__pycache__": b"ordinary file, not a directory",
|
||||
"assets/fixture.pyc": b"canonical bytecode fixture",
|
||||
"__pycache__/module.cpython-315.pyc": b"stale cache",
|
||||
"package/__pycache__/module.cpython-315.pyc": b"nested cache",
|
||||
}
|
||||
for relative, content in files.items():
|
||||
(src / relative).write_bytes(content)
|
||||
|
||||
_copy_single(src, dst, verbose=False)
|
||||
|
||||
expected = {
|
||||
relative: content
|
||||
for relative, content in files.items()
|
||||
if "__pycache__" not in pathlib.Path(relative).parts[:-1]
|
||||
}
|
||||
actual = {
|
||||
path.relative_to(dst).as_posix(): path.read_bytes()
|
||||
for path in dst.rglob("*")
|
||||
if path.is_file()
|
||||
}
|
||||
self.assertEqual(actual, expected)
|
||||
self.assertFalse((dst / "__pycache__").exists())
|
||||
self.assertFalse((dst / "package/__pycache__").exists())
|
||||
for relative, content in files.items():
|
||||
self.assertEqual((src / relative).read_bytes(), content)
|
||||
|
||||
|
||||
class TestCopyLib(unittest.TestCase):
|
||||
"""Tests for copy_lib function."""
|
||||
|
||||
Reference in new issue
Block a user