crosshair-tool 0.0.99__cp312-cp312-macosx_10_13_x86_64.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 (176) hide show
  1. _crosshair_tracers.cpython-312-darwin.so +0 -0
  2. crosshair/__init__.py +42 -0
  3. crosshair/__main__.py +8 -0
  4. crosshair/_mark_stacks.h +790 -0
  5. crosshair/_preliminaries_test.py +18 -0
  6. crosshair/_tracers.h +94 -0
  7. crosshair/_tracers_pycompat.h +522 -0
  8. crosshair/_tracers_test.py +138 -0
  9. crosshair/abcstring.py +245 -0
  10. crosshair/auditwall.py +190 -0
  11. crosshair/auditwall_test.py +77 -0
  12. crosshair/codeconfig.py +113 -0
  13. crosshair/codeconfig_test.py +117 -0
  14. crosshair/condition_parser.py +1237 -0
  15. crosshair/condition_parser_test.py +497 -0
  16. crosshair/conftest.py +30 -0
  17. crosshair/copyext.py +155 -0
  18. crosshair/copyext_test.py +84 -0
  19. crosshair/core.py +1763 -0
  20. crosshair/core_and_libs.py +149 -0
  21. crosshair/core_regestered_types_test.py +82 -0
  22. crosshair/core_test.py +1316 -0
  23. crosshair/diff_behavior.py +314 -0
  24. crosshair/diff_behavior_test.py +261 -0
  25. crosshair/dynamic_typing.py +346 -0
  26. crosshair/dynamic_typing_test.py +210 -0
  27. crosshair/enforce.py +282 -0
  28. crosshair/enforce_test.py +182 -0
  29. crosshair/examples/PEP316/__init__.py +1 -0
  30. crosshair/examples/PEP316/bugs_detected/__init__.py +0 -0
  31. crosshair/examples/PEP316/bugs_detected/getattr_magic.py +16 -0
  32. crosshair/examples/PEP316/bugs_detected/hash_consistent_with_equals.py +31 -0
  33. crosshair/examples/PEP316/bugs_detected/shopping_cart.py +24 -0
  34. crosshair/examples/PEP316/bugs_detected/showcase.py +39 -0
  35. crosshair/examples/PEP316/correct_code/__init__.py +0 -0
  36. crosshair/examples/PEP316/correct_code/arith.py +60 -0
  37. crosshair/examples/PEP316/correct_code/chess.py +77 -0
  38. crosshair/examples/PEP316/correct_code/nesting_inference.py +17 -0
  39. crosshair/examples/PEP316/correct_code/numpy_examples.py +132 -0
  40. crosshair/examples/PEP316/correct_code/rolling_average.py +35 -0
  41. crosshair/examples/PEP316/correct_code/showcase.py +104 -0
  42. crosshair/examples/__init__.py +0 -0
  43. crosshair/examples/check_examples_test.py +146 -0
  44. crosshair/examples/deal/__init__.py +1 -0
  45. crosshair/examples/icontract/__init__.py +1 -0
  46. crosshair/examples/icontract/bugs_detected/__init__.py +0 -0
  47. crosshair/examples/icontract/bugs_detected/showcase.py +41 -0
  48. crosshair/examples/icontract/bugs_detected/wrong_sign.py +8 -0
  49. crosshair/examples/icontract/correct_code/__init__.py +0 -0
  50. crosshair/examples/icontract/correct_code/arith.py +51 -0
  51. crosshair/examples/icontract/correct_code/showcase.py +94 -0
  52. crosshair/fnutil.py +391 -0
  53. crosshair/fnutil_test.py +75 -0
  54. crosshair/fuzz_core_test.py +516 -0
  55. crosshair/libimpl/__init__.py +0 -0
  56. crosshair/libimpl/arraylib.py +161 -0
  57. crosshair/libimpl/binascii_ch_test.py +30 -0
  58. crosshair/libimpl/binascii_test.py +67 -0
  59. crosshair/libimpl/binasciilib.py +150 -0
  60. crosshair/libimpl/bisectlib_test.py +23 -0
  61. crosshair/libimpl/builtinslib.py +5228 -0
  62. crosshair/libimpl/builtinslib_ch_test.py +1191 -0
  63. crosshair/libimpl/builtinslib_test.py +3735 -0
  64. crosshair/libimpl/codecslib.py +86 -0
  65. crosshair/libimpl/codecslib_test.py +86 -0
  66. crosshair/libimpl/collectionslib.py +264 -0
  67. crosshair/libimpl/collectionslib_ch_test.py +252 -0
  68. crosshair/libimpl/collectionslib_test.py +332 -0
  69. crosshair/libimpl/copylib.py +23 -0
  70. crosshair/libimpl/copylib_test.py +18 -0
  71. crosshair/libimpl/datetimelib.py +2559 -0
  72. crosshair/libimpl/datetimelib_ch_test.py +354 -0
  73. crosshair/libimpl/datetimelib_test.py +112 -0
  74. crosshair/libimpl/decimallib.py +5257 -0
  75. crosshair/libimpl/decimallib_ch_test.py +78 -0
  76. crosshair/libimpl/decimallib_test.py +76 -0
  77. crosshair/libimpl/encodings/__init__.py +23 -0
  78. crosshair/libimpl/encodings/_encutil.py +187 -0
  79. crosshair/libimpl/encodings/ascii.py +44 -0
  80. crosshair/libimpl/encodings/latin_1.py +40 -0
  81. crosshair/libimpl/encodings/utf_8.py +93 -0
  82. crosshair/libimpl/encodings_ch_test.py +83 -0
  83. crosshair/libimpl/fractionlib.py +16 -0
  84. crosshair/libimpl/fractionlib_test.py +80 -0
  85. crosshair/libimpl/functoolslib.py +34 -0
  86. crosshair/libimpl/functoolslib_test.py +56 -0
  87. crosshair/libimpl/hashliblib.py +30 -0
  88. crosshair/libimpl/hashliblib_test.py +18 -0
  89. crosshair/libimpl/heapqlib.py +47 -0
  90. crosshair/libimpl/heapqlib_test.py +21 -0
  91. crosshair/libimpl/importliblib.py +18 -0
  92. crosshair/libimpl/importliblib_test.py +38 -0
  93. crosshair/libimpl/iolib.py +216 -0
  94. crosshair/libimpl/iolib_ch_test.py +128 -0
  95. crosshair/libimpl/iolib_test.py +19 -0
  96. crosshair/libimpl/ipaddresslib.py +8 -0
  97. crosshair/libimpl/itertoolslib.py +44 -0
  98. crosshair/libimpl/itertoolslib_test.py +44 -0
  99. crosshair/libimpl/jsonlib.py +984 -0
  100. crosshair/libimpl/jsonlib_ch_test.py +42 -0
  101. crosshair/libimpl/jsonlib_test.py +51 -0
  102. crosshair/libimpl/mathlib.py +179 -0
  103. crosshair/libimpl/mathlib_ch_test.py +44 -0
  104. crosshair/libimpl/mathlib_test.py +67 -0
  105. crosshair/libimpl/oslib.py +7 -0
  106. crosshair/libimpl/pathliblib_test.py +10 -0
  107. crosshair/libimpl/randomlib.py +178 -0
  108. crosshair/libimpl/randomlib_test.py +120 -0
  109. crosshair/libimpl/relib.py +846 -0
  110. crosshair/libimpl/relib_ch_test.py +169 -0
  111. crosshair/libimpl/relib_test.py +493 -0
  112. crosshair/libimpl/timelib.py +72 -0
  113. crosshair/libimpl/timelib_test.py +82 -0
  114. crosshair/libimpl/typeslib.py +15 -0
  115. crosshair/libimpl/typeslib_test.py +36 -0
  116. crosshair/libimpl/unicodedatalib.py +75 -0
  117. crosshair/libimpl/unicodedatalib_test.py +42 -0
  118. crosshair/libimpl/urlliblib.py +23 -0
  119. crosshair/libimpl/urlliblib_test.py +19 -0
  120. crosshair/libimpl/weakreflib.py +13 -0
  121. crosshair/libimpl/weakreflib_test.py +69 -0
  122. crosshair/libimpl/zliblib.py +15 -0
  123. crosshair/libimpl/zliblib_test.py +13 -0
  124. crosshair/lsp_server.py +261 -0
  125. crosshair/lsp_server_test.py +30 -0
  126. crosshair/main.py +973 -0
  127. crosshair/main_test.py +543 -0
  128. crosshair/objectproxy.py +376 -0
  129. crosshair/objectproxy_test.py +41 -0
  130. crosshair/opcode_intercept.py +601 -0
  131. crosshair/opcode_intercept_test.py +304 -0
  132. crosshair/options.py +218 -0
  133. crosshair/options_test.py +10 -0
  134. crosshair/patch_equivalence_test.py +75 -0
  135. crosshair/path_cover.py +209 -0
  136. crosshair/path_cover_test.py +138 -0
  137. crosshair/path_search.py +161 -0
  138. crosshair/path_search_test.py +52 -0
  139. crosshair/pathing_oracle.py +271 -0
  140. crosshair/pathing_oracle_test.py +21 -0
  141. crosshair/pure_importer.py +27 -0
  142. crosshair/pure_importer_test.py +16 -0
  143. crosshair/py.typed +0 -0
  144. crosshair/register_contract.py +273 -0
  145. crosshair/register_contract_test.py +190 -0
  146. crosshair/simplestructs.py +1165 -0
  147. crosshair/simplestructs_test.py +283 -0
  148. crosshair/smtlib.py +24 -0
  149. crosshair/smtlib_test.py +14 -0
  150. crosshair/statespace.py +1199 -0
  151. crosshair/statespace_test.py +108 -0
  152. crosshair/stubs_parser.py +352 -0
  153. crosshair/stubs_parser_test.py +43 -0
  154. crosshair/test_util.py +329 -0
  155. crosshair/test_util_test.py +26 -0
  156. crosshair/tools/__init__.py +0 -0
  157. crosshair/tools/check_help_in_doc.py +264 -0
  158. crosshair/tools/check_init_and_setup_coincide.py +119 -0
  159. crosshair/tools/generate_demo_table.py +127 -0
  160. crosshair/tracers.py +544 -0
  161. crosshair/tracers_test.py +154 -0
  162. crosshair/type_repo.py +151 -0
  163. crosshair/unicode_categories.py +589 -0
  164. crosshair/unicode_categories_test.py +27 -0
  165. crosshair/util.py +741 -0
  166. crosshair/util_test.py +173 -0
  167. crosshair/watcher.py +307 -0
  168. crosshair/watcher_test.py +107 -0
  169. crosshair/z3util.py +76 -0
  170. crosshair/z3util_test.py +11 -0
  171. crosshair_tool-0.0.99.dist-info/METADATA +144 -0
  172. crosshair_tool-0.0.99.dist-info/RECORD +176 -0
  173. crosshair_tool-0.0.99.dist-info/WHEEL +6 -0
  174. crosshair_tool-0.0.99.dist-info/entry_points.txt +3 -0
  175. crosshair_tool-0.0.99.dist-info/licenses/LICENSE +93 -0
  176. crosshair_tool-0.0.99.dist-info/top_level.txt +2 -0
@@ -0,0 +1,119 @@
1
+ #!/usr/bin/env python3
2
+
3
+ """Check that the distribution and crosshair/__init__.py are in sync."""
4
+ import subprocess
5
+ import sys
6
+ from typing import Dict, Optional
7
+
8
+ import crosshair
9
+
10
+
11
+ def main() -> int:
12
+ """Execute the main routine."""
13
+ success = True
14
+
15
+ ##
16
+ # Check basic fields
17
+ ##
18
+
19
+ setup_py = dict() # type: Dict[str, str]
20
+
21
+ fields = ["version", "author", "license", "description"]
22
+ for field in fields:
23
+ out = subprocess.check_output(
24
+ [sys.executable, "setup.py", f"--{field}"], encoding="utf-8"
25
+ ).strip()
26
+
27
+ setup_py[field] = out
28
+
29
+ if setup_py["version"] != crosshair.__version__:
30
+ print(
31
+ f"The version in the setup.py is {setup_py['version']}, "
32
+ f"while the version in crosshair/__init__.py is: "
33
+ f"{crosshair.__version__}",
34
+ file=sys.stderr,
35
+ )
36
+ success = False
37
+
38
+ if setup_py["author"] != crosshair.__author__:
39
+ print(
40
+ f"The author in the setup.py is {setup_py['author']}, "
41
+ f"while the author in crosshair/__init__.py is: "
42
+ f"{crosshair.__author__}",
43
+ file=sys.stderr,
44
+ )
45
+ success = False
46
+
47
+ if setup_py["license"] != crosshair.__license__:
48
+ print(
49
+ f"The license in the setup.py is {setup_py['license']}, "
50
+ f"while the license in crosshair/__init__.py is: "
51
+ f"{crosshair.__license__}",
52
+ file=sys.stderr,
53
+ )
54
+ success = False
55
+
56
+ if setup_py["description"] != crosshair.__doc__:
57
+ print(
58
+ f"The description in the setup.py is {setup_py['description']}, "
59
+ f"while the description in crosshair/__init__.py is: "
60
+ f"{crosshair.__doc__}",
61
+ file=sys.stderr,
62
+ )
63
+ success = False
64
+
65
+ ##
66
+ # Classifiers need special attention as there are multiple.
67
+ ##
68
+
69
+ # This is the map from the distribution to expected status in __init__.py.
70
+ status_map = {
71
+ "Development Status :: 1 - Planning": "Planning",
72
+ "Development Status :: 2 - Pre-Alpha": "Pre-Alpha",
73
+ "Development Status :: 3 - Alpha": "Alpha",
74
+ "Development Status :: 4 - Beta": "Beta",
75
+ "Development Status :: 5 - Production/Stable": "Production/Stable",
76
+ "Development Status :: 6 - Mature": "Mature",
77
+ "Development Status :: 7 - Inactive": "Inactive",
78
+ }
79
+
80
+ classifiers = (
81
+ subprocess.check_output(
82
+ [sys.executable, "setup.py", f"--classifiers"], encoding="utf-8"
83
+ )
84
+ .strip()
85
+ .splitlines()
86
+ )
87
+
88
+ status_classifier = None # type: Optional[str]
89
+ for classifier in classifiers:
90
+ if classifier in status_map:
91
+ status_classifier = classifier
92
+ break
93
+
94
+ if status_classifier is None:
95
+ print(
96
+ f"Expected a status classifier in setup.py "
97
+ f"(e.g., 'Development Status :: 3 - Alpha'), but found none.",
98
+ file=sys.stderr,
99
+ )
100
+ success = False
101
+ else:
102
+ expected_status_in_init = status_map[status_classifier]
103
+
104
+ if expected_status_in_init != crosshair.__status__:
105
+ print(
106
+ f"Expected status {expected_status_in_init} "
107
+ f"according to setup.py in crosshair/__init__.py, "
108
+ f"but found: {crosshair.__status__}"
109
+ )
110
+ success = False
111
+
112
+ if not success:
113
+ return -1
114
+
115
+ return 0
116
+
117
+
118
+ if __name__ == "__main__":
119
+ sys.exit(main())
@@ -0,0 +1,127 @@
1
+ import importlib
2
+ import inspect
3
+ import itertools
4
+ import pkgutil
5
+ import re
6
+ import sys
7
+ import textwrap
8
+ from collections import defaultdict
9
+ from pathlib import Path
10
+ from urllib.parse import quote_plus
11
+
12
+
13
+ def extract_webdemo(test_src):
14
+ match = re.fullmatch(r".*?( *def f\(.*?)\s*check_states.*", test_src, re.DOTALL)
15
+ if not match:
16
+ print("*** Unable to find demo function in this test: ***")
17
+ print(test_src)
18
+ print("*** ***")
19
+ sys.exit(1)
20
+ (fnbody,) = match.groups()
21
+ return "from typing import *\n\n" + textwrap.dedent(fnbody)
22
+
23
+
24
+ def extract_demo(module) -> list[tuple[str, str, str]]:
25
+ ret = []
26
+ for itemname in dir(module):
27
+ item = getattr(module, itemname)
28
+ if not hasattr(item, "pytestmark"):
29
+ continue
30
+ marks = [m for m in item.pytestmark if m.name == "demo"]
31
+ if not marks:
32
+ continue
33
+ color = marks[0].args[0] if marks[0].args else "green"
34
+ test_src = inspect.getsource(item)
35
+ modname = itemname.removeprefix("test_")
36
+ demo_src = extract_webdemo(test_src)
37
+ ret.append((modname, color, demo_src))
38
+ return sorted(ret)
39
+
40
+
41
+ def stdlib_demos() -> dict[str, list[tuple[str, str, str]]]:
42
+ libimpl_dir = Path(__file__).parent.parent / "libimpl"
43
+ ret = {}
44
+ testnames = [
45
+ name
46
+ for (_f, name, _p) in pkgutil.iter_modules([str(libimpl_dir)])
47
+ if name.endswith("lib_test")
48
+ ]
49
+ testnames.sort(key=lambda n: "" if n == "builtinslib_test" else n)
50
+ for name in testnames:
51
+ modname = f"crosshair.libimpl.{name}"
52
+ mod = importlib.import_module(modname)
53
+ ret[name.removesuffix("lib_test")] = extract_demo(mod)
54
+ return ret
55
+
56
+
57
+ def format_line(line: list[tuple[str, str, str]]) -> str:
58
+ return " ".join(f'[{char}]({url} "{name}")' for (char, name, url) in line)
59
+
60
+
61
+ def markdown_table(sections: dict[str, dict[str, list[tuple[str, str, str]]]]) -> str:
62
+ # table_width = max(len(line) for section in sections.values() for line in section.values())
63
+ parts = ["||||\n|-|-|-|\n"]
64
+ for section_name, section in sections.items():
65
+ if not section:
66
+ continue
67
+ section = section.copy()
68
+ parts.append(f"|{section_name}||{format_line(section.pop('', []))}|\n")
69
+ for line_header, line in section.items():
70
+ parts.append(f"||{line_header}|{format_line(line)}|\n")
71
+ return "".join(parts)
72
+
73
+
74
+ COLORS = {
75
+ "yellow": "🟡",
76
+ "green": "🟢",
77
+ "red": "🔴",
78
+ }
79
+
80
+ CH_WEB = "https://crosshair-web.org"
81
+
82
+ SPECIAL_CHARS = {
83
+ "__eq__": "==",
84
+ "__le__": "<=",
85
+ "__contains__": "in",
86
+ "__getitem__": "[]",
87
+ "__setitem__": "[]=",
88
+ "__floordiv__": "//",
89
+ "__truediv__": "/",
90
+ "__mod__": "%",
91
+ "__add__": "+",
92
+ "__mul__": "*",
93
+ "__pow__": "**",
94
+ "__sub__": "-",
95
+ }
96
+
97
+
98
+ def make_link(name: str, color: str, src: str) -> tuple[str, str, str]:
99
+ char = SPECIAL_CHARS.get(
100
+ name, f"<sub><sup><sub>{name.strip('_')}</sub></sup></sub>"
101
+ )
102
+ text = f"{char}<sup><sub><sup>{COLORS[color]}</sup></sub></sup>"
103
+ return (text, name, f"{CH_WEB}/?source={quote_plus(src)}")
104
+
105
+
106
+ def divide_stdlib_module(
107
+ modulename: str, items: list[tuple[str, str, str]]
108
+ ) -> dict[str, list[tuple[str, str, str]]]:
109
+ ret = defaultdict(list)
110
+ for name, color, src in items:
111
+ if name.endswith("_method"):
112
+ name = name.removesuffix("_method")
113
+ (classname, methodname) = name.split("_", 1)
114
+ else:
115
+ (classname, methodname) = ("", name)
116
+ ret[classname].append(
117
+ make_link(methodname, color, f"import {modulename}\n" + src)
118
+ )
119
+ return ret
120
+
121
+
122
+ stdlib = {}
123
+ for modulename, items in stdlib_demos().items():
124
+ stdlib[modulename] = divide_stdlib_module(modulename, items)
125
+
126
+
127
+ print(markdown_table(stdlib))