pyinc 1.0.0__tar.gz

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 (54) hide show
  1. pyinc-1.0.0/.gitignore +8 -0
  2. pyinc-1.0.0/CHANGELOG.md +40 -0
  3. pyinc-1.0.0/LICENSE +201 -0
  4. pyinc-1.0.0/PKG-INFO +150 -0
  5. pyinc-1.0.0/README.md +122 -0
  6. pyinc-1.0.0/docs/architecture.md +84 -0
  7. pyinc-1.0.0/docs/integration-authoring.md +219 -0
  8. pyinc-1.0.0/docs/integration-contract.md +386 -0
  9. pyinc-1.0.0/docs/kernel-contract.md +188 -0
  10. pyinc-1.0.0/examples/applicable_requirements.py +66 -0
  11. pyinc-1.0.0/examples/correctness_demo.py +223 -0
  12. pyinc-1.0.0/examples/mini_analyzer.py +17 -0
  13. pyinc-1.0.0/examples/sample_module.py +3 -0
  14. pyinc-1.0.0/examples/symbol_lookup.py +60 -0
  15. pyinc-1.0.0/examples/undeclared_imports.py +56 -0
  16. pyinc-1.0.0/pyproject.toml +82 -0
  17. pyinc-1.0.0/src/pyinc/__init__.py +57 -0
  18. pyinc-1.0.0/src/pyinc/core.py +92 -0
  19. pyinc-1.0.0/src/pyinc/errors.py +21 -0
  20. pyinc-1.0.0/src/pyinc/explain.py +41 -0
  21. pyinc-1.0.0/src/pyinc/integrations/__init__.py +183 -0
  22. pyinc-1.0.0/src/pyinc/integrations/csv_data.py +246 -0
  23. pyinc-1.0.0/src/pyinc/integrations/deep_module_resolution.py +572 -0
  24. pyinc-1.0.0/src/pyinc/integrations/dependency_check.py +248 -0
  25. pyinc-1.0.0/src/pyinc/integrations/env_file.py +236 -0
  26. pyinc-1.0.0/src/pyinc/integrations/installed_packages.py +375 -0
  27. pyinc-1.0.0/src/pyinc/integrations/json_config.py +244 -0
  28. pyinc-1.0.0/src/pyinc/integrations/python_source.py +952 -0
  29. pyinc-1.0.0/src/pyinc/integrations/requirement_evaluation.py +1051 -0
  30. pyinc-1.0.0/src/pyinc/integrations/requirements_txt.py +490 -0
  31. pyinc-1.0.0/src/pyinc/integrations/symbol_resolution.py +975 -0
  32. pyinc-1.0.0/src/pyinc/integrations/toml_config.py +283 -0
  33. pyinc-1.0.0/src/pyinc/integrations/xml_config.py +289 -0
  34. pyinc-1.0.0/src/pyinc/py.typed +1 -0
  35. pyinc-1.0.0/src/pyinc/resources.py +135 -0
  36. pyinc-1.0.0/src/pyinc/runtime.py +1126 -0
  37. pyinc-1.0.0/src/pyinc/value.py +406 -0
  38. pyinc-1.0.0/tests/test_csv_data.py +265 -0
  39. pyinc-1.0.0/tests/test_deep_module_resolution.py +417 -0
  40. pyinc-1.0.0/tests/test_dependency_check.py +426 -0
  41. pyinc-1.0.0/tests/test_env_file.py +292 -0
  42. pyinc-1.0.0/tests/test_errors.py +43 -0
  43. pyinc-1.0.0/tests/test_explain.py +75 -0
  44. pyinc-1.0.0/tests/test_installed_packages.py +463 -0
  45. pyinc-1.0.0/tests/test_json_config.py +327 -0
  46. pyinc-1.0.0/tests/test_properties.py +278 -0
  47. pyinc-1.0.0/tests/test_python_source.py +972 -0
  48. pyinc-1.0.0/tests/test_requirement_evaluation.py +670 -0
  49. pyinc-1.0.0/tests/test_requirements_txt.py +497 -0
  50. pyinc-1.0.0/tests/test_runtime.py +2240 -0
  51. pyinc-1.0.0/tests/test_symbol_resolution.py +656 -0
  52. pyinc-1.0.0/tests/test_toml_config.py +248 -0
  53. pyinc-1.0.0/tests/test_value.py +451 -0
  54. pyinc-1.0.0/tests/test_xml_config.py +378 -0
pyinc-1.0.0/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ __pycache__/
2
+ .pytest_cache/
3
+ .hypothesis/
4
+ .mypy_cache/
5
+ .ruff_cache/
6
+ dist/
7
+ build/
8
+ *.egg-info/
@@ -0,0 +1,40 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file. The format
4
+ is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and the
5
+ project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
+
7
+ ## [1.0.0] — 2026-04-18
8
+
9
+ First stable release.
10
+
11
+ ### Added
12
+
13
+ - **Kernel.** Pull-based red-green verification, backdating (early cutoff),
14
+ `strict` / `checked` / `fast` value-membrane modes, LRU eviction, cycle
15
+ detection, untracked-read guards, `Database.set_many(...)` batch
16
+ invalidation, `Database.dependency_graph(...)` export,
17
+ `Database.inspect(...)` / `Database.explain(...)` provenance, and
18
+ `Database.statistics()` / `Database.query_profile()` observability.
19
+ - **Built-in resources.** `FileResource`, `FileStatResource`, `EnvResource`,
20
+ `DirectoryResource`.
21
+ - **Twelve shipped integrations** under `pyinc.integrations`:
22
+ `python_source`, `toml_config`, `requirements_txt` (including
23
+ `deep_requirements_analysis` for recursive `-r` following),
24
+ `installed_packages`, `json_config`, `dependency_check`, `env_file`,
25
+ `xml_config`, `csv_data`, `deep_module_resolution`, `requirement_evaluation`
26
+ (PEP 440 specifier satisfaction + PEP 508 marker evaluation), and
27
+ `symbol_resolution` (module- and class-level symbol tables with bounded
28
+ cross-module re-export resolution).
29
+ - **Typing.** Inline `py.typed` marker; `mypy --strict` clean.
30
+ - **Docs.** `kernel-contract.md`, `integration-contract.md`,
31
+ `integration-authoring.md`, `architecture.md`.
32
+
33
+ ### Notes
34
+
35
+ - Zero runtime dependencies; pure-Python, stdlib-only.
36
+ - Tested on CPython 3.11, 3.12, and 3.13.
37
+ - LSP wiring and push-based filesystem watchers are architectural non-goals
38
+ for v1; see `docs/architecture.md` for scope boundary.
39
+
40
+ [1.0.0]: https://github.com/Brumbelow/pyinc/releases/tag/v1.0.0
pyinc-1.0.0/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
pyinc-1.0.0/PKG-INFO ADDED
@@ -0,0 +1,150 @@
1
+ Metadata-Version: 2.4
2
+ Name: pyinc
3
+ Version: 1.0.0
4
+ Summary: A correctness-first incremental query engine for Python.
5
+ Project-URL: Homepage, https://github.com/Brumbelow/pyinc
6
+ Project-URL: Repository, https://github.com/Brumbelow/pyinc
7
+ Project-URL: Issues, https://github.com/Brumbelow/pyinc/issues
8
+ Author-email: Andrew Brumbelow <andrew@vangelder-inc.com>
9
+ License: Apache-2.0
10
+ License-File: LICENSE
11
+ Keywords: backdating,incremental-computation,provenance,query-kernel,red-green,salsa
12
+ Classifier: Development Status :: 5 - Production/Stable
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: License :: OSI Approved :: Apache Software License
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3.11
17
+ Classifier: Programming Language :: Python :: 3.12
18
+ Classifier: Programming Language :: Python :: 3.13
19
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
20
+ Requires-Python: >=3.11
21
+ Provides-Extra: dev
22
+ Requires-Dist: hypothesis>=6.0; extra == 'dev'
23
+ Requires-Dist: mypy>=1.10; extra == 'dev'
24
+ Requires-Dist: pytest-cov>=5.0; extra == 'dev'
25
+ Requires-Dist: pytest>=8.0; extra == 'dev'
26
+ Requires-Dist: ruff>=0.4; extra == 'dev'
27
+ Description-Content-Type: text/markdown
28
+
29
+ # pyinc
30
+
31
+ [![CI](https://github.com/Brumbelow/pyinc/actions/workflows/ci.yml/badge.svg)](https://github.com/Brumbelow/pyinc/actions/workflows/ci.yml)
32
+ [![PyPI](https://img.shields.io/pypi/v/pyinc.svg)](https://pypi.org/project/pyinc/)
33
+ [![Python versions](https://img.shields.io/pypi/pyversions/pyinc.svg)](https://pypi.org/project/pyinc/)
34
+ [![License](https://img.shields.io/pypi/l/pyinc.svg)](https://github.com/Brumbelow/pyinc/blob/main/LICENSE)
35
+
36
+ ```
37
+ pip install pyinc
38
+ ```
39
+
40
+ Python is mutable by default, identity-heavy, and full of hidden side effects. These properties make incremental computation unsound in practice: cached results silently depend on mutated state, untracked file reads, and object identity that the cache cannot see.
41
+
42
+ `pyinc` is a correctness-first incremental computation engine that solves this problem. It is a pure-Python, stdlib-only query kernel in the design space of Salsa, Jane Street Incremental, and Bazel/Skyframe — but designed specifically for the challenges Python creates.
43
+
44
+ v1.0.0 is the first stable release. The v1 kernel contract and public integration surface are stable under semver, within the soundness envelope documented in [docs/kernel-contract.md](docs/kernel-contract.md).
45
+
46
+ ## Quick example
47
+
48
+ ```python
49
+ from pyinc import Database, FileResource, query
50
+
51
+ _FILES = FileResource()
52
+
53
+ @query
54
+ def read_config(db, path):
55
+ return _FILES.read(db, path) # tracked file read
56
+
57
+ @query
58
+ def parse_names(db, path):
59
+ text = read_config(db, path)
60
+ return [line.strip() for line in text.splitlines() if line.strip()]
61
+
62
+ db = Database(mode="strict")
63
+ result = db.get(parse_names, "/tmp/names.txt") # computes from scratch
64
+ result = db.get(parse_names, "/tmp/names.txt") # reuses memo — file unchanged
65
+
66
+ # Edit the file: only affected queries re-execute.
67
+ # Comment-only edits can be backdated (early cutoff) with a cutoff= function.
68
+ # Raw open() inside a query raises UntrackedReadError.
69
+ # In strict mode, returned values are frozen — mutation raises TypeError.
70
+ ```
71
+
72
+ See `examples/correctness_demo.py` for a full walkthrough of backdating (early cutoff), mutation protection, untracked read enforcement, and provenance inspection. `examples/undeclared_imports.py`, `examples/applicable_requirements.py`, and `examples/symbol_lookup.py` demonstrate three of the shipped integrations end-to-end on self-contained tempdir workspaces.
73
+
74
+ ## What pyinc guarantees
75
+
76
+ pyinc guarantees **from-scratch consistency** — the result of incremental evaluation matches a fresh evaluation on the same declared inputs and resources — when:
77
+
78
+ 1. **Value boundary ownership**: all values crossing cached boundaries are snapshot-safe (frozen)
79
+ 2. **Tracked ambient reads**: all external state reads go through the Resource API
80
+ 3. **Deterministic queries**: given the same tracked dependencies, queries return semantically equal values
81
+
82
+ The full contract, including explicit limitations and escape hatches, is in [docs/kernel-contract.md](docs/kernel-contract.md).
83
+
84
+ ## Current scope
85
+
86
+ - `@query` for derived values, `Input` for explicit base leaves
87
+ - optional `eq=` and `cutoff=` policies for custom equivalence and backdating (early cutoff)
88
+ - `ValueAdapter` for custom snapshot-safe boundary types
89
+ - `FileResource`, `FileStatResource`, `EnvResource`, and `DirectoryResource` for tracked external reads
90
+ - pull-based recomputation with revisions, dependency capture, red-green verification, and backdating (early cutoff)
91
+ - `strict`, `checked`, and `fast` execution modes with explicit boundary semantics
92
+ - optional bounded query memoization via `Database(max_query_nodes=...)`
93
+ - `Database.set_many(...)` for atomic batch invalidation of multiple inputs (single revision bump)
94
+ - `Database.dependency_graph()` for machine-readable graph export of all nodes and edges
95
+ - `Database.inspect(...)` for structured provenance and `Database.explain(...)` for human-readable formatting
96
+ - `Database.statistics()` for aggregate counters and `Database.query_profile()` for per-query timing
97
+
98
+ ## Integrations
99
+
100
+ - `pyinc.integrations.python_source` — workspace-local module discovery, top-level imports/definitions, simple assignment tracking for export surfaces, conservative import resolution with `workspace`/`stdlib`/`installed`/`missing`/`ambiguous` outcomes (stdlib and installed classification via composition with `installed_packages`; installed imports' `resolved_path` is populated via `deep_module_resolution`).
101
+ - `pyinc.integrations.toml_config` — single-file TOML inspection: section/key extraction, dependency and optional-dependency discovery, tool config discovery.
102
+ - `pyinc.integrations.requirements_txt` — narrow requirements parsing: normalized requirement specs, file references, index directives, editable installs, URL requirements. Includes `deep_requirements_analysis` for recursive `-r`/`--requirement` file following with cycle detection.
103
+ - `pyinc.integrations.installed_packages` — installed package discovery via `importlib.metadata`-compatible `.dist-info` directories, stdlib module identification via `sys.stdlib_module_names`, and import name resolution (`stdlib`/`installed`/`unknown`).
104
+ - `pyinc.integrations.deep_module_resolution` — deep module path resolution: `sys.path` walking, `.pth` file processing with backdating on whitespace/comment edits, PEP 420 namespace package collection, and dotted-name → file resolution. Exposes `resolve_module_path` for per-module queries and `deep_module_resolution_analysis` for a workspace-wide snapshot.
105
+ - `pyinc.integrations.json_config` — single-file JSON inspection: section/key extraction with type detection, nested object traversal, parse error diagnostics.
106
+ - `pyinc.integrations.dependency_check` — cross-integration dependency validation: composes `installed_packages` and `python_source` to detect undeclared imports and missing packages.
107
+ - `pyinc.integrations.env_file` — `.env` file parsing: key-value extraction with quoted/unquoted values, `export` prefix handling, interpolation reference detection.
108
+ - `pyinc.integrations.xml_config` — XML file inspection via `xml.etree.ElementTree`: element/attribute extraction, dot-path traversal, namespace-aware tag normalization.
109
+ - `pyinc.integrations.csv_data` — CSV/TSV structural analysis via stdlib `csv`: header detection, column discovery, delimiter sniffing, row counting, inconsistent column diagnostics.
110
+ - `pyinc.integrations.requirement_evaluation` — PEP 440 version specifier satisfaction and PEP 508 environment marker evaluation; composes with `requirements_txt` and `installed_packages` to surface the effective applicable/satisfied requirement set for the current Python environment. Exposes `evaluate_markers`, `evaluate_version_specifier`, and `applicable_requirements`.
111
+ - `pyinc.integrations.symbol_resolution` — workspace-wide symbol tables (module-level + class-level), cross-module re-export following with cycle detection, and type-annotation text extraction via `ast.unparse` (no type evaluation). Exposes `module_symbol_table`, `resolve_symbol`, and `workspace_symbol_index`.
112
+
113
+ `pyinc.integrations` re-exports only the stable dataclass/result types and high-level entrypoints for these integrations. Low-level payload queries, decode helpers, and resource helpers remain experimental in their defining submodules.
114
+
115
+ ## Verification
116
+
117
+ - The runtime contract is summarized in [docs/kernel-contract.md](docs/kernel-contract.md).
118
+ - The repo includes dedicated test modules for value semantics, runtime behavior, provenance/explanation formatting, property-based from-scratch consistency, and each shipped integration.
119
+ - The integration suites exercise `strict`, `checked`, and `fast` modes and compare incremental results against fresh recomputation over edit sequences.
120
+
121
+ The integration boundary is summarized in [docs/integration-contract.md](docs/integration-contract.md).
122
+
123
+ ## Gotchas
124
+
125
+ - `Database.inspect(...)` is observational. It returns the last recorded provenance tree for that query key and does not force a fresh revalidation pass by itself.
126
+ - Query identity includes the function definition payload. If you capture ambient values, those captures are part of the query fingerprint, and mutable closure/global captures are rejected.
127
+ - `Database.report_untracked_read(...)` is an explicit impurity escape hatch. It marks that query as always re-executing and disables backdating for that node.
128
+ - The package ships inline typing metadata via `py.typed`.
129
+
130
+ ## Not supported
131
+
132
+ - LSP wiring
133
+ - File watchers (push-based filesystem invalidation)
134
+
135
+ These are architectural non-goals for v1. pyinc is a pull-based kernel; LSP servers
136
+ and push-based watchers belong to a consumer tool built on top of pyinc, not to the
137
+ kernel itself. See `docs/architecture.md:80-82` for the v1 scope boundary.
138
+
139
+ ## Development
140
+
141
+ ```bash
142
+ python3 -m venv .venv
143
+ . .venv/bin/activate
144
+ python3 -m pip install -e '.[dev]'
145
+ pytest -q
146
+ python3 -m mypy src tests
147
+ python3 -m ruff check src tests
148
+ ```
149
+
150
+ The runtime contract is summarized in [docs/kernel-contract.md](docs/kernel-contract.md). Integration API boundaries are summarized in [docs/integration-contract.md](docs/integration-contract.md). A guide for building new integrations is at [docs/integration-authoring.md](docs/integration-authoring.md).
pyinc-1.0.0/README.md ADDED
@@ -0,0 +1,122 @@
1
+ # pyinc
2
+
3
+ [![CI](https://github.com/Brumbelow/pyinc/actions/workflows/ci.yml/badge.svg)](https://github.com/Brumbelow/pyinc/actions/workflows/ci.yml)
4
+ [![PyPI](https://img.shields.io/pypi/v/pyinc.svg)](https://pypi.org/project/pyinc/)
5
+ [![Python versions](https://img.shields.io/pypi/pyversions/pyinc.svg)](https://pypi.org/project/pyinc/)
6
+ [![License](https://img.shields.io/pypi/l/pyinc.svg)](https://github.com/Brumbelow/pyinc/blob/main/LICENSE)
7
+
8
+ ```
9
+ pip install pyinc
10
+ ```
11
+
12
+ Python is mutable by default, identity-heavy, and full of hidden side effects. These properties make incremental computation unsound in practice: cached results silently depend on mutated state, untracked file reads, and object identity that the cache cannot see.
13
+
14
+ `pyinc` is a correctness-first incremental computation engine that solves this problem. It is a pure-Python, stdlib-only query kernel in the design space of Salsa, Jane Street Incremental, and Bazel/Skyframe — but designed specifically for the challenges Python creates.
15
+
16
+ v1.0.0 is the first stable release. The v1 kernel contract and public integration surface are stable under semver, within the soundness envelope documented in [docs/kernel-contract.md](docs/kernel-contract.md).
17
+
18
+ ## Quick example
19
+
20
+ ```python
21
+ from pyinc import Database, FileResource, query
22
+
23
+ _FILES = FileResource()
24
+
25
+ @query
26
+ def read_config(db, path):
27
+ return _FILES.read(db, path) # tracked file read
28
+
29
+ @query
30
+ def parse_names(db, path):
31
+ text = read_config(db, path)
32
+ return [line.strip() for line in text.splitlines() if line.strip()]
33
+
34
+ db = Database(mode="strict")
35
+ result = db.get(parse_names, "/tmp/names.txt") # computes from scratch
36
+ result = db.get(parse_names, "/tmp/names.txt") # reuses memo — file unchanged
37
+
38
+ # Edit the file: only affected queries re-execute.
39
+ # Comment-only edits can be backdated (early cutoff) with a cutoff= function.
40
+ # Raw open() inside a query raises UntrackedReadError.
41
+ # In strict mode, returned values are frozen — mutation raises TypeError.
42
+ ```
43
+
44
+ See `examples/correctness_demo.py` for a full walkthrough of backdating (early cutoff), mutation protection, untracked read enforcement, and provenance inspection. `examples/undeclared_imports.py`, `examples/applicable_requirements.py`, and `examples/symbol_lookup.py` demonstrate three of the shipped integrations end-to-end on self-contained tempdir workspaces.
45
+
46
+ ## What pyinc guarantees
47
+
48
+ pyinc guarantees **from-scratch consistency** — the result of incremental evaluation matches a fresh evaluation on the same declared inputs and resources — when:
49
+
50
+ 1. **Value boundary ownership**: all values crossing cached boundaries are snapshot-safe (frozen)
51
+ 2. **Tracked ambient reads**: all external state reads go through the Resource API
52
+ 3. **Deterministic queries**: given the same tracked dependencies, queries return semantically equal values
53
+
54
+ The full contract, including explicit limitations and escape hatches, is in [docs/kernel-contract.md](docs/kernel-contract.md).
55
+
56
+ ## Current scope
57
+
58
+ - `@query` for derived values, `Input` for explicit base leaves
59
+ - optional `eq=` and `cutoff=` policies for custom equivalence and backdating (early cutoff)
60
+ - `ValueAdapter` for custom snapshot-safe boundary types
61
+ - `FileResource`, `FileStatResource`, `EnvResource`, and `DirectoryResource` for tracked external reads
62
+ - pull-based recomputation with revisions, dependency capture, red-green verification, and backdating (early cutoff)
63
+ - `strict`, `checked`, and `fast` execution modes with explicit boundary semantics
64
+ - optional bounded query memoization via `Database(max_query_nodes=...)`
65
+ - `Database.set_many(...)` for atomic batch invalidation of multiple inputs (single revision bump)
66
+ - `Database.dependency_graph()` for machine-readable graph export of all nodes and edges
67
+ - `Database.inspect(...)` for structured provenance and `Database.explain(...)` for human-readable formatting
68
+ - `Database.statistics()` for aggregate counters and `Database.query_profile()` for per-query timing
69
+
70
+ ## Integrations
71
+
72
+ - `pyinc.integrations.python_source` — workspace-local module discovery, top-level imports/definitions, simple assignment tracking for export surfaces, conservative import resolution with `workspace`/`stdlib`/`installed`/`missing`/`ambiguous` outcomes (stdlib and installed classification via composition with `installed_packages`; installed imports' `resolved_path` is populated via `deep_module_resolution`).
73
+ - `pyinc.integrations.toml_config` — single-file TOML inspection: section/key extraction, dependency and optional-dependency discovery, tool config discovery.
74
+ - `pyinc.integrations.requirements_txt` — narrow requirements parsing: normalized requirement specs, file references, index directives, editable installs, URL requirements. Includes `deep_requirements_analysis` for recursive `-r`/`--requirement` file following with cycle detection.
75
+ - `pyinc.integrations.installed_packages` — installed package discovery via `importlib.metadata`-compatible `.dist-info` directories, stdlib module identification via `sys.stdlib_module_names`, and import name resolution (`stdlib`/`installed`/`unknown`).
76
+ - `pyinc.integrations.deep_module_resolution` — deep module path resolution: `sys.path` walking, `.pth` file processing with backdating on whitespace/comment edits, PEP 420 namespace package collection, and dotted-name → file resolution. Exposes `resolve_module_path` for per-module queries and `deep_module_resolution_analysis` for a workspace-wide snapshot.
77
+ - `pyinc.integrations.json_config` — single-file JSON inspection: section/key extraction with type detection, nested object traversal, parse error diagnostics.
78
+ - `pyinc.integrations.dependency_check` — cross-integration dependency validation: composes `installed_packages` and `python_source` to detect undeclared imports and missing packages.
79
+ - `pyinc.integrations.env_file` — `.env` file parsing: key-value extraction with quoted/unquoted values, `export` prefix handling, interpolation reference detection.
80
+ - `pyinc.integrations.xml_config` — XML file inspection via `xml.etree.ElementTree`: element/attribute extraction, dot-path traversal, namespace-aware tag normalization.
81
+ - `pyinc.integrations.csv_data` — CSV/TSV structural analysis via stdlib `csv`: header detection, column discovery, delimiter sniffing, row counting, inconsistent column diagnostics.
82
+ - `pyinc.integrations.requirement_evaluation` — PEP 440 version specifier satisfaction and PEP 508 environment marker evaluation; composes with `requirements_txt` and `installed_packages` to surface the effective applicable/satisfied requirement set for the current Python environment. Exposes `evaluate_markers`, `evaluate_version_specifier`, and `applicable_requirements`.
83
+ - `pyinc.integrations.symbol_resolution` — workspace-wide symbol tables (module-level + class-level), cross-module re-export following with cycle detection, and type-annotation text extraction via `ast.unparse` (no type evaluation). Exposes `module_symbol_table`, `resolve_symbol`, and `workspace_symbol_index`.
84
+
85
+ `pyinc.integrations` re-exports only the stable dataclass/result types and high-level entrypoints for these integrations. Low-level payload queries, decode helpers, and resource helpers remain experimental in their defining submodules.
86
+
87
+ ## Verification
88
+
89
+ - The runtime contract is summarized in [docs/kernel-contract.md](docs/kernel-contract.md).
90
+ - The repo includes dedicated test modules for value semantics, runtime behavior, provenance/explanation formatting, property-based from-scratch consistency, and each shipped integration.
91
+ - The integration suites exercise `strict`, `checked`, and `fast` modes and compare incremental results against fresh recomputation over edit sequences.
92
+
93
+ The integration boundary is summarized in [docs/integration-contract.md](docs/integration-contract.md).
94
+
95
+ ## Gotchas
96
+
97
+ - `Database.inspect(...)` is observational. It returns the last recorded provenance tree for that query key and does not force a fresh revalidation pass by itself.
98
+ - Query identity includes the function definition payload. If you capture ambient values, those captures are part of the query fingerprint, and mutable closure/global captures are rejected.
99
+ - `Database.report_untracked_read(...)` is an explicit impurity escape hatch. It marks that query as always re-executing and disables backdating for that node.
100
+ - The package ships inline typing metadata via `py.typed`.
101
+
102
+ ## Not supported
103
+
104
+ - LSP wiring
105
+ - File watchers (push-based filesystem invalidation)
106
+
107
+ These are architectural non-goals for v1. pyinc is a pull-based kernel; LSP servers
108
+ and push-based watchers belong to a consumer tool built on top of pyinc, not to the
109
+ kernel itself. See `docs/architecture.md:80-82` for the v1 scope boundary.
110
+
111
+ ## Development
112
+
113
+ ```bash
114
+ python3 -m venv .venv
115
+ . .venv/bin/activate
116
+ python3 -m pip install -e '.[dev]'
117
+ pytest -q
118
+ python3 -m mypy src tests
119
+ python3 -m ruff check src tests
120
+ ```
121
+
122
+ The runtime contract is summarized in [docs/kernel-contract.md](docs/kernel-contract.md). Integration API boundaries are summarized in [docs/integration-contract.md](docs/integration-contract.md). A guide for building new integrations is at [docs/integration-authoring.md](docs/integration-authoring.md).
@@ -0,0 +1,84 @@
1
+ # pyinc Architecture
2
+
3
+ ## Kernel
4
+
5
+ `pyinc` is a pull-based incremental query runtime. The database stores query memos, inputs, and resources as revisioned node records with:
6
+
7
+ - a stable node key
8
+ - a frozen boundary snapshot
9
+ - a semantic digest
10
+ - dependency edges captured dynamically at runtime
11
+ - `changed_at` and `verified_at` revisions
12
+ - the last decision: `executed`, `reused`, or `backdated`
13
+
14
+ `Database.inspect(...)` returns the last recorded provenance tree for a query key, and `Database.explain(...)` formats that tree without changing the node's recorded decision just by inspecting it.
15
+
16
+ Evaluation is top-down. `db.get()` verifies dependencies first, then either reuses the memo or re-executes the query. If a re-executed query returns a semantically equal value, the record is **backdated** (also called **early cutoff**) so downstream nodes stay clean.
17
+
18
+ `Database(max_query_nodes=...)` bounds only query memo nodes via LRU at top-level request boundaries. Inputs and resources remain resident.
19
+
20
+ ## Value Membrane
21
+
22
+ Values crossing cached boundaries are frozen snapshots.
23
+
24
+ - `strict`: expose frozen values directly.
25
+ - `checked`: expose thawed copies and verify that queries did not mutate them.
26
+ - `fast`: expose thawed copies without mutation checks.
27
+
28
+ Hidden reads are not allowed in the core. Raw `open()` inside a query raises `UntrackedReadError` unless the access is routed through a resource object or explicitly marked via `db.report_untracked_read(...)`.
29
+
30
+ The runtime also blocks raw ambient reads through `os.getenv`, `os.environ`, `os.listdir`, `os.scandir`, and `Path.iterdir` during query execution. Resource `probe`/`load` hooks run in an internal allow-scope so resource implementations can perform those reads safely.
31
+
32
+ Query definitions are also checked for ambient state. Immutable constants and explicit `Input`/resource/query handles are allowed; mutable closure or global data is rejected so memo reuse never depends on hidden Python object mutation.
33
+
34
+ Query identity includes the supported function definition payload, so ambient immutable captures contribute to the fingerprint instead of being ignored.
35
+
36
+ Resource node identity includes resource configuration. Built-in resources are snapshot-safe dataclasses, and custom resources must either be snapshot-safe themselves or expose an `identity()` payload for keying.
37
+
38
+ ## Package Shape Today
39
+
40
+ `pyinc` exposes a stable kernel surface from the top-level package:
41
+
42
+ - `Database`, `Input`, and `@query` for the query runtime
43
+ - `FileResource`, `FileStatResource`, `EnvResource`, and `DirectoryResource` for tracked external reads
44
+ - value-boundary helpers such as `freeze`, `thaw`, `semantic_equal`, and `ValueAdapter`
45
+ - structured inspection via `InspectionNode`, `Database.inspect(...)`, and `Database.explain(...)`
46
+
47
+ `pyinc.integrations` exposes the stable high-level surfaces from the four shipped integrations:
48
+
49
+ - `python_source` for narrow Python source and workspace-local module analysis
50
+ - `toml_config` for narrow `pyproject.toml` inspection
51
+ - `requirements_txt` for narrow `requirements.txt` inspection
52
+ - `installed_packages` for installed package discovery, stdlib module identification, and import name resolution
53
+
54
+ Low-level payload queries, decode helpers, and resource helpers remain module-local experimental helpers. The public integration boundary is the dataclass/result layer plus the documented high-level entrypoints in `docs/integration-contract.md`.
55
+
56
+ The repository also includes small examples under `examples/` plus dedicated tests for kernel semantics, property-based from-scratch consistency, and each shipped integration.
57
+
58
+ ## Cross-Integration Composition
59
+
60
+ Integrations can compose at the query layer by importing `@query` functions from other integration modules. The kernel's dependency tracking extends automatically across integration boundaries -- no special wiring is required. When an upstream integration's query result changes, downstream queries that depend on it are re-verified and re-executed through the normal red-green algorithm.
61
+
62
+ Currently, `python_source` composes with `installed_packages`: it imports the `environment_index` query to classify non-workspace imports as `stdlib`, `installed`, or `missing`. This means that if the installed package environment changes (e.g., a package is installed or removed), `python_source`'s import resolution results are automatically invalidated and recomputed on the next request.
63
+
64
+ Composition queries like `environment_index` are public `@query` functions exported in their module's `__all__`, but they are intentionally not re-exported from `pyinc.integrations`. They exist for query-layer composition between integrations, not as user-facing entrypoints.
65
+
66
+ ## Scope
67
+
68
+ Version 1 targets:
69
+
70
+ - module-defined `@query` functions
71
+ - explicit `Input` leaves
72
+ - explicit file, env, and directory resources
73
+ - optional file metadata resources (`FileStatResource`) for stat-level dependencies
74
+ - explanation/provenance for reuse vs recompute
75
+ - inline package typing via `py.typed`
76
+ - narrow supported integrations for Python source analysis, TOML config inspection, requirements parsing, and installed package discovery
77
+
78
+ Version 1 does not include:
79
+
80
+ - notebook integration
81
+ - push observers
82
+ - schedulers or worker pools
83
+ - content-addressed artifact storage
84
+ - arbitrary mutable object graphs across cached boundaries