subsumes-benchmark 0.9.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. subsumes_benchmark/__init__.py +4 -0
  2. subsumes_benchmark/__main__.py +3 -0
  3. subsumes_benchmark/archive.py +79 -0
  4. subsumes_benchmark/build.py +656 -0
  5. subsumes_benchmark/compare/__init__.py +5 -0
  6. subsumes_benchmark/compare/__main__.py +161 -0
  7. subsumes_benchmark/compare/checkers.py +220 -0
  8. subsumes_benchmark/compare/derive.py +301 -0
  9. subsumes_benchmark/compare/diff.py +364 -0
  10. subsumes_benchmark/compare/downgrade.py +429 -0
  11. subsumes_benchmark/compare/report.py +643 -0
  12. subsumes_benchmark/compare/results.py +130 -0
  13. subsumes_benchmark/compare/run.py +270 -0
  14. subsumes_benchmark/compare/summary.py +226 -0
  15. subsumes_benchmark/compare/tasks.py +107 -0
  16. subsumes_benchmark/compare/witness.py +104 -0
  17. subsumes_benchmark/compare/words.py +43 -0
  18. subsumes_benchmark/config.py +32 -0
  19. subsumes_benchmark/convert.py +329 -0
  20. subsumes_benchmark/corpus.tar.zst +0 -0
  21. subsumes_benchmark/derived.py +82 -0
  22. subsumes_benchmark/features.py +225 -0
  23. subsumes_benchmark/generated/__init__.py +1 -0
  24. subsumes_benchmark/generated/case.py +156 -0
  25. subsumes_benchmark/generated/checker.py +54 -0
  26. subsumes_benchmark/generated/collections.py +93 -0
  27. subsumes_benchmark/generated/derived.py +71 -0
  28. subsumes_benchmark/generated/overrides.py +79 -0
  29. subsumes_benchmark/generated/ready.py +21 -0
  30. subsumes_benchmark/generated/reply.py +115 -0
  31. subsumes_benchmark/generated/request.py +34 -0
  32. subsumes_benchmark/generated/result.py +239 -0
  33. subsumes_benchmark/generated/run.py +111 -0
  34. subsumes_benchmark/testsuite.py +200 -0
  35. subsumes_benchmark/unfuse.py +124 -0
  36. subsumes_benchmark/validation.py +286 -0
  37. subsumes_benchmark-0.9.0.dist-info/METADATA +72 -0
  38. subsumes_benchmark-0.9.0.dist-info/RECORD +43 -0
  39. subsumes_benchmark-0.9.0.dist-info/WHEEL +4 -0
  40. subsumes_benchmark-0.9.0.dist-info/entry_points.txt +3 -0
  41. subsumes_benchmark-0.9.0.dist-info/licenses/LICENSE +21 -0
  42. subsumes_benchmark-0.9.0.dist-info/licenses/corpus/licenses/inclusion-artifact.txt +674 -0
  43. subsumes_benchmark-0.9.0.dist-info/licenses/corpus/licenses/json-schema-test-suite.txt +19 -0
@@ -0,0 +1,4 @@
1
+ """Builds the JSON Schema inclusion benchmark corpus under ``corpus/`` from its upstream sources."""
2
+
3
+ type Json = dict[str, Json] | list[Json] | str | int | float | bool | None
4
+ """A JSON value as ``json.load`` produces it."""
@@ -0,0 +1,3 @@
1
+ from subsumes_benchmark.build import main
2
+
3
+ main()
@@ -0,0 +1,79 @@
1
+ """The corpus as one file: ``corpus.tar.zst``, which a release and the package carry.
2
+
3
+ The file is the folder ``corpus/`` as a tar archive compressed with Zstandard. A release of
4
+ the repository has it as its file, and the package has the same file next to this module,
5
+ from where ``subsumes-benchmark corpus <folder>`` unpacks it. It is not committed: the release
6
+ packs it from the corpus of the tag, before the package is built.
7
+
8
+ ``python -m subsumes_benchmark.archive <corpus> <archive>`` packs a corpus; ``make archive``
9
+ does so for a build of the package from a checkout.
10
+ """
11
+
12
+ import sys
13
+ import tarfile
14
+ from pathlib import Path
15
+
16
+ # Where the package holds the corpus. In a checkout the file is there only after it was packed.
17
+ ARCHIVE = Path(__file__).with_name("corpus.tar.zst")
18
+ # The folder that the archive unpacks into, as `tar` unpacks it.
19
+ ROOT = "corpus"
20
+ # The strongest level that needs no more memory to unpack than a lower one.
21
+ LEVEL = 19
22
+
23
+
24
+ class ArchiveError(Exception):
25
+ pass
26
+
27
+
28
+ def pack(corpus: Path, archive: Path) -> None:
29
+ """Pack the folder of a corpus into an archive that depends on nothing but the corpus.
30
+
31
+ The entries are sorted, and have no time and no owner, so that the same corpus gives the
32
+ same file wherever it is packed.
33
+ """
34
+ if not corpus.is_dir():
35
+ raise ArchiveError(f"there is no corpus at {corpus}")
36
+ paths = sorted(corpus.rglob("*"), key=lambda path: path.relative_to(corpus).parts)
37
+ archive.parent.mkdir(parents=True, exist_ok=True)
38
+ with tarfile.TarFile.zstopen(archive, "w", level=LEVEL) as tar:
39
+ for path in [corpus, *paths]:
40
+ name = (Path(ROOT) / path.relative_to(corpus)).as_posix()
41
+ entry = tarfile.TarInfo(name)
42
+ if path.is_dir():
43
+ entry.type, entry.mode = tarfile.DIRTYPE, 0o755
44
+ tar.addfile(entry)
45
+ else:
46
+ entry.size, entry.mode = path.stat().st_size, 0o644
47
+ with path.open("rb") as content:
48
+ tar.addfile(entry, content)
49
+
50
+
51
+ def unpack(folder: Path, archive: Path = ARCHIVE) -> None:
52
+ """Unpack the corpus of an archive into a folder, which is new or empty.
53
+
54
+ The folder becomes the corpus itself: what the archive has under ``corpus/`` goes
55
+ directly into it.
56
+
57
+ Raises:
58
+ ArchiveError: There is no archive, or the folder holds something already.
59
+ """
60
+ if not archive.is_file():
61
+ raise ArchiveError(
62
+ f"there is no archive at {archive}: a checkout has the corpus as the folder corpus/, "
63
+ "and only a built package holds the archive"
64
+ )
65
+ if folder.exists() and (not folder.is_dir() or any(folder.iterdir())):
66
+ raise ArchiveError(f"{folder} is not empty")
67
+ folder.mkdir(parents=True, exist_ok=True)
68
+ with tarfile.open(archive, "r:zst") as tar:
69
+ for entry in tar:
70
+ inside = Path(entry.name).relative_to(ROOT)
71
+ if inside.parts:
72
+ tar.extract(entry.replace(name=inside.as_posix()), folder, filter="data")
73
+
74
+
75
+ if __name__ == "__main__":
76
+ try:
77
+ pack(Path(sys.argv[1]), Path(sys.argv[2]))
78
+ except ArchiveError as error:
79
+ sys.exit(str(error))