hydra-python 0.15.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.
@@ -0,0 +1,247 @@
1
+ Metadata-Version: 2.4
2
+ Name: hydra-python
3
+ Version: 0.15.0
4
+ Summary: Python coder for Hydra: generates idiomatic Python code from Hydra type and term modules
5
+ Project-URL: Homepage, https://github.com/CategoricalData/hydra
6
+ Project-URL: Repository, https://github.com/CategoricalData/hydra
7
+ Author-email: Joshua Shinavier <josh@fortytwo.net>
8
+ License: Apache-2.0
9
+ Requires-Python: >=3.12
10
+ Requires-Dist: hydra-kernel==0.15.0
11
+ Description-Content-Type: text/markdown
12
+
13
+ # Hydra-Python
14
+
15
+ This package contains the **Python coder DSL sources**: Haskell modules that describe
16
+ how to translate Hydra modules into Python source code. The runnable Python head
17
+ (hand-written primitives, DSL runtime, pyproject.toml, test runner) lives in
18
+ [`heads/python/`](https://github.com/CategoricalData/hydra/tree/main/heads/python).
19
+ The generated Python kernel lives in
20
+ [`dist/python/hydra-kernel/`](https://github.com/CategoricalData/hydra/tree/main/dist/python/hydra-kernel).
21
+
22
+ Hydra is a type-aware data transformation toolkit which aims to be highly flexible and portable.
23
+ It has its roots in graph databases and type theory, and provides APIs in Haskell, Java, Python, Scala, and Lisp.
24
+ See the main Hydra [README](https://github.com/CategoricalData/hydra) for more details.
25
+
26
+ ## Getting started
27
+
28
+ Hydra-Python requires Python 3.12 or later.
29
+
30
+ Install [uv](https://github.com/astral-sh/uv):
31
+
32
+ ```bash
33
+ curl -LsSf https://astral.sh/uv/install.sh | sh
34
+ ```
35
+
36
+ Create the Python virtual environment in the Python head directory:
37
+
38
+ ```bash
39
+ cd heads/python
40
+ uv venv --python 3.12
41
+ source .venv/bin/activate
42
+ ```
43
+
44
+ Install the dependencies:
45
+
46
+ ```bash
47
+ uv sync
48
+ ```
49
+
50
+ ## Documentation
51
+
52
+ For comprehensive documentation about Hydra's architecture and usage, see:
53
+
54
+ - **[Concepts](https://github.com/CategoricalData/hydra/wiki/Concepts)** - Core concepts and type system
55
+ - **[Implementation](https://github.com/CategoricalData/hydra/blob/main/docs/implementation.md)** - Implementation guide
56
+ - **[Code Organization](https://github.com/CategoricalData/hydra/wiki/Code-organization)** -
57
+ The `packages/`, `heads/`, `dist/` layout
58
+ - **[Testing](https://github.com/CategoricalData/hydra/wiki/Testing)** -
59
+ Common test suite documentation
60
+ - **[Developer Recipes](https://github.com/CategoricalData/hydra/blob/main/docs/recipes/index.md)** -
61
+ Step-by-step guides
62
+ - **[Syncing Hydra-Python](https://github.com/CategoricalData/hydra/blob/main/docs/recipes/syncing-python.md)** -
63
+ Regenerating Python from Haskell
64
+
65
+ ## Testing
66
+
67
+ Hydra-Python has two types of tests: the **common test suite** (shared across all Hydra implementations)
68
+ and **Python-specific tests**.
69
+ See the [Testing wiki page](https://github.com/CategoricalData/hydra/wiki/Testing)
70
+ for comprehensive documentation.
71
+
72
+ ### Common test suite
73
+
74
+ The common test suite (`hydra.test.testSuite`) ensures parity across all Hydra implementations.
75
+ **Passing all common test suite cases is the criterion for a true Hydra implementation.**
76
+
77
+ To run all tests (from `heads/python/`):
78
+
79
+ ```bash
80
+ cd heads/python && pytest
81
+ ```
82
+
83
+ To run only the common test suite:
84
+
85
+ ```bash
86
+ cd heads/python && pytest src/test/python/test_suite_runner.py
87
+ ```
88
+
89
+ The test suite is generated from Hydra DSL sources and includes:
90
+ - Primitive function tests (lists, strings, math, etc.)
91
+ - Case conversion tests (camelCase, snake_case, etc.)
92
+ - Type inference tests
93
+ - Type checking tests
94
+ - Evaluation tests
95
+ - JSON coder tests
96
+ - Rewriting and hoisting tests
97
+
98
+ ### Python-specific tests
99
+
100
+ Python-specific tests validate implementation details and Python-specific functionality.
101
+ These are located in `heads/python/src/test/python/` alongside the common test suite runner.
102
+
103
+ To run a specific test file:
104
+
105
+ ```bash
106
+ cd heads/python && pytest src/test/python/test_grammar.py
107
+ ```
108
+
109
+ To match a specific test by name:
110
+
111
+ ```bash
112
+ cd heads/python && pytest -k test_grammar
113
+ ```
114
+
115
+ To see printed outputs, use the `-s` flag:
116
+
117
+ ```bash
118
+ cd heads/python && pytest -s
119
+ ```
120
+
121
+ ## Code organization
122
+
123
+ In 0.15, Hydra's Python code is split across three locations
124
+ (see [Code organization wiki page](https://github.com/CategoricalData/hydra/wiki/Code-organization) for the full picture):
125
+
126
+ - **This package** (`packages/hydra-python/src/main/haskell/`) — the Python coder DSL sources
127
+ (written in Haskell): `Hydra/Sources/Python/` contains `Syntax`, `Language`, `Coder`, `Serde`,
128
+ `Names`, `Utils`, `Environment`, and `Testing` modules.
129
+
130
+ - **Python head** ([`heads/python/src/main/python/`](https://github.com/CategoricalData/hydra/tree/main/heads/python/src/main/python))
131
+ — hand-written Python runtime
132
+ - `hydra/lib/` — primitive function implementations
133
+ - `hydra/dsl/` — DSL utilities (FrozenDict, Maybe, ...)
134
+ - `hydra/sources/libraries.py` — primitive registration
135
+ - `pyproject.toml` lives in `heads/python/`
136
+
137
+ - **Generated Python kernel** ([`dist/python/hydra-kernel/src/main/python/`](https://github.com/CategoricalData/hydra/tree/main/dist/python/hydra-kernel/src/main/python))
138
+ - `hydra/core.py` — core types (Term, Type, Literal, ...)
139
+ - `hydra/graph.py`, `hydra/packaging.py` — graph and packaging structures
140
+ - `hydra/coders.py` — type adapters and coder framework
141
+ - `hydra/reduction.py`, `hydra/rewriting.py`, `hydra/hoisting.py` — term transformations
142
+ - `hydra/inference.py`, `hydra/checking.py` — type inference and checking
143
+ - Generated from the kernel DSL sources using the Python coder
144
+
145
+ - **Generated Python test suite** (`dist/python/hydra-kernel/src/test/python/`)
146
+ - Common tests ensuring parity with Haskell, Java, Scala, and Lisp
147
+
148
+ ## Generate Python code
149
+
150
+ Python code is generated from the Haskell head. See the
151
+ [Hydra-Haskell README](https://github.com/CategoricalData/hydra/tree/main/packages/hydra-haskell)
152
+ for background on code generation.
153
+
154
+ The recommended way to regenerate all Python code is the sync script (from the repo root):
155
+
156
+ ```bash
157
+ bin/sync-python.sh
158
+ ```
159
+
160
+ (equivalent to `bin/sync.sh --hosts python --targets python`)
161
+
162
+ This will:
163
+ 1. Generate the kernel modules into `dist/python/hydra-kernel/src/main/python`
164
+ 2. Generate the kernel tests into `dist/python/hydra-kernel/src/test/python`
165
+ 3. Run the pytest suite
166
+
167
+ For manual generation, enter GHCi from `heads/haskell/`:
168
+
169
+ ```bash
170
+ cd heads/haskell && stack ghci
171
+ ```
172
+
173
+ And run in the REPL:
174
+
175
+ ```haskell
176
+ import Hydra.Generation
177
+ import Hydra.Sources.All
178
+
179
+ -- Generate the kernel
180
+ writePython "../../dist/python/hydra-kernel/src/main/python" kernelModules kernelModules
181
+
182
+ -- Generate the test suite
183
+ let allModules = mainModules ++ testModules
184
+ writePython "../../dist/python/hydra-kernel/src/test/python" allModules baseTestModules
185
+ ```
186
+
187
+ ### Validate generated code
188
+
189
+ ```bash
190
+ find dist/python/hydra-kernel/src -name "*.py" -exec python3 -m py_compile {} +
191
+ ```
192
+
193
+ ## Formatting, linting, and type checking
194
+
195
+ Install [Ruff](https://github.com/astral-sh/ruff),
196
+ [pyright](https://github.com/microsoft/pyright), and
197
+ [pytest](https://docs.pytest.org/en/stable), e.g. on macOS:
198
+
199
+ ```bash
200
+ brew install ruff
201
+ brew install pyright
202
+ brew install pytest
203
+ ```
204
+
205
+ All of these commands run from the `heads/python/` directory
206
+ (files/directories can also be specified as arguments).
207
+
208
+ ### Formatting
209
+
210
+ Format the hand-written Python code:
211
+
212
+ ```bash
213
+ ruff format
214
+ ```
215
+
216
+ ### Linting
217
+
218
+ Run the linter:
219
+
220
+ ```bash
221
+ ruff check
222
+ ```
223
+
224
+ Fix fixable linting errors (e.g. removing unused imports):
225
+
226
+ ```bash
227
+ ruff check --fix
228
+ ```
229
+
230
+ ### Static type checking
231
+
232
+ Run the type checker:
233
+
234
+ ```bash
235
+ pyright
236
+ ```
237
+
238
+ ## Numeric types
239
+
240
+ Hydra's `decimal` type is implemented as Python `decimal.Decimal` with the
241
+ default 28-digit context precision.
242
+ Operations exceeding this precision round per the active context;
243
+ users requiring higher precision should adjust `decimal.getcontext().prec`
244
+ before performing arithmetic.
245
+ This differs from Haskell `Scientific` and Java `BigDecimal`
246
+ (which are effectively unbounded for exact operations)
247
+ but matches Python's standard decimal behavior.
@@ -0,0 +1,11 @@
1
+ hydra/python/coder.py,sha256=QI8ENG16OC6tSMQq-yNUA-CPfL3VysmXzZuIBvXICmI,164279
2
+ hydra/python/environment.py,sha256=UUdulVC3YVrjcYa4M1bLvAyp61tDtwGTx9wQDWfSVJM,4341
3
+ hydra/python/language.py,sha256=LOS7zs3bwJJfwG7PWPyB5cjVnVe5FMytC0G6AdmzTAA,4459
4
+ hydra/python/names.py,sha256=nMKjynnaLXTGtktrtS-ddO9sYNeARCmnrKR-iCfFFkU,9727
5
+ hydra/python/serde.py,sha256=07v1k8dBjwb2d3dtAi2YN05gDf1jGjzD-UUB9RRPKGA,50237
6
+ hydra/python/syntax.py,sha256=K8kuEZBDmFUINlqbRXjdWubMaCCtFVxEvX_BHDh_ngc,68822
7
+ hydra/python/testing.py,sha256=W2tYRTYvnLm3DSAz6BRRMoPlNbGx9Kt3jWTrI3x9x5U,4824
8
+ hydra/python/utils.py,sha256=9j-emEdPv8kfpRlAgUfol21oYpbAHLIAYWaoQJWvIks,38721
9
+ hydra_python-0.15.0.dist-info/METADATA,sha256=SSSVpTxFGW-5-GkW_TwOKSqC3BtXcEUqO9GolA9pSvU,7840
10
+ hydra_python-0.15.0.dist-info/WHEEL,sha256=QccIxa26bgl1E6uMy58deGWi-0aeIkkangHcxk2kWfw,87
11
+ hydra_python-0.15.0.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: hatchling 1.29.0
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any