viv-compiler 0.1.0__tar.gz → 0.1.2__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.
- {viv_compiler-0.1.0/src/viv_compiler.egg-info → viv_compiler-0.1.2}/PKG-INFO +120 -82
- viv_compiler-0.1.2/README.md +279 -0
- {viv_compiler-0.1.0 → viv_compiler-0.1.2}/pyproject.toml +1 -1
- {viv_compiler-0.1.0/src/viv_compiler/utils → viv_compiler-0.1.2/src/viv_compiler}/_version.py +1 -1
- {viv_compiler-0.1.0 → viv_compiler-0.1.2}/src/viv_compiler/cli.py +14 -12
- {viv_compiler-0.1.0 → viv_compiler-0.1.2}/src/viv_compiler/config/config.py +17 -18
- viv_compiler-0.1.2/src/viv_compiler/core/__init__.py +5 -0
- {viv_compiler-0.1.0 → viv_compiler-0.1.2}/src/viv_compiler/core/core.py +7 -7
- viv_compiler-0.1.0/src/viv_compiler/core/importer.py → viv_compiler-0.1.2/src/viv_compiler/core/includes.py +5 -5
- viv_compiler-0.1.2/src/viv_compiler/core/metadata.py +71 -0
- viv_compiler-0.1.0/src/viv_compiler/core/postprocessor.py → viv_compiler-0.1.2/src/viv_compiler/core/postprocessing.py +6 -32
- viv_compiler-0.1.0/src/viv_compiler/core/validator.py → viv_compiler-0.1.2/src/viv_compiler/core/validation.py +203 -88
- {viv_compiler-0.1.0 → viv_compiler-0.1.2}/src/viv_compiler/core/visitor.py +184 -139
- viv_compiler-0.1.2/src/viv_compiler/grammar/viv.peg +460 -0
- {viv_compiler-0.1.0 → viv_compiler-0.1.2}/src/viv_compiler/types/content_public_schemas.py +59 -31
- {viv_compiler-0.1.0 → viv_compiler-0.1.2}/src/viv_compiler/types/dsl_public_schemas.py +84 -82
- {viv_compiler-0.1.0 → viv_compiler-0.1.2}/src/viv_compiler/utils/utils.py +93 -33
- {viv_compiler-0.1.0 → viv_compiler-0.1.2/src/viv_compiler.egg-info}/PKG-INFO +120 -82
- {viv_compiler-0.1.0 → viv_compiler-0.1.2}/src/viv_compiler.egg-info/SOURCES.txt +5 -4
- viv_compiler-0.1.0/README.md +0 -241
- viv_compiler-0.1.0/src/viv_compiler/core/__init__.py +0 -5
- viv_compiler-0.1.0/src/viv_compiler/grammar/viv.peg +0 -228
- {viv_compiler-0.1.0 → viv_compiler-0.1.2}/LICENSE +0 -0
- {viv_compiler-0.1.0 → viv_compiler-0.1.2}/setup.cfg +0 -0
- {viv_compiler-0.1.0 → viv_compiler-0.1.2}/src/viv_compiler/__init__.py +0 -0
- {viv_compiler-0.1.0 → viv_compiler-0.1.2}/src/viv_compiler/__main__.py +0 -0
- {viv_compiler-0.1.0 → viv_compiler-0.1.2}/src/viv_compiler/_samples/__init__.py +0 -0
- {viv_compiler-0.1.0 → viv_compiler-0.1.2}/src/viv_compiler/_samples/smoke-test.viv +0 -0
- {viv_compiler-0.1.0 → viv_compiler-0.1.2}/src/viv_compiler/api.py +0 -0
- {viv_compiler-0.1.0 → viv_compiler-0.1.2}/src/viv_compiler/backports/__init__.py +0 -0
- {viv_compiler-0.1.0 → viv_compiler-0.1.2}/src/viv_compiler/backports/backports.py +0 -0
- {viv_compiler-0.1.0 → viv_compiler-0.1.2}/src/viv_compiler/config/__init__.py +0 -0
- {viv_compiler-0.1.0 → viv_compiler-0.1.2}/src/viv_compiler/grammar/__init__.py +0 -0
- {viv_compiler-0.1.0 → viv_compiler-0.1.2}/src/viv_compiler/py.typed +0 -0
- {viv_compiler-0.1.0 → viv_compiler-0.1.2}/src/viv_compiler/types/__init__.py +0 -0
- {viv_compiler-0.1.0 → viv_compiler-0.1.2}/src/viv_compiler/types/internal_types.py +0 -0
- {viv_compiler-0.1.0 → viv_compiler-0.1.2}/src/viv_compiler/utils/__init__.py +0 -0
- {viv_compiler-0.1.0 → viv_compiler-0.1.2}/src/viv_compiler.egg-info/dependency_links.txt +0 -0
- {viv_compiler-0.1.0 → viv_compiler-0.1.2}/src/viv_compiler.egg-info/entry_points.txt +0 -0
- {viv_compiler-0.1.0 → viv_compiler-0.1.2}/src/viv_compiler.egg-info/requires.txt +0 -0
- {viv_compiler-0.1.0 → viv_compiler-0.1.2}/src/viv_compiler.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: viv-compiler
|
3
|
-
Version: 0.1.
|
3
|
+
Version: 0.1.2
|
4
4
|
Summary: Compiler for the DSL of Viv, an action system for emergent narrative.
|
5
5
|
Author-email: James Ryan <mail@jamesryan.ai>
|
6
6
|
License: MIT License
|
@@ -45,7 +45,7 @@ Dynamic: license-file
|
|
45
45
|
|
46
46
|
This package contains the reference compiler for the domain-specific language (DSL) at the heart of [Viv](https://github.com/james-owen-ryan/viv), an action system for emergent narrative.
|
47
47
|
|
48
|
-
The Viv compiler accepts a
|
48
|
+
The Viv compiler accepts a **Viv source file** (`.viv`) and produces a **Viv content bundle** in a JSON-serializable format conforming to the `CompiledContentBundle` schema defined [here](https://github.com/james-owen-ryan/viv/blob/main/compiler/src/viv_compiler/types/dsl_public_schemas.py), making it ready for usage in any Viv runtime with the same version number as the compiler.
|
49
49
|
|
50
50
|
Once you've installed this package, you'll have access to the two compiler interfaces that are documented below:
|
51
51
|
|
@@ -65,19 +65,17 @@ Once you've installed this package, you'll have access to the two compiler inter
|
|
65
65
|
|
66
66
|
## Installation
|
67
67
|
|
68
|
-
Install from PyPI:
|
68
|
+
* Install from PyPI:
|
69
69
|
|
70
|
-
```
|
71
|
-
pip install viv-compiler
|
72
|
-
```
|
73
|
-
|
74
|
-
This installs both the `viv_compiler` Python package and the `vivc` command-line interface.
|
70
|
+
```
|
71
|
+
pip install viv-compiler
|
72
|
+
```
|
75
73
|
|
76
|
-
|
74
|
+
* Run a smoke test to confirm your installation looks good:
|
77
75
|
|
78
|
-
```
|
79
|
-
vivc --test
|
80
|
-
```
|
76
|
+
```
|
77
|
+
vivc --test
|
78
|
+
```
|
81
79
|
|
82
80
|
|
83
81
|
## Command-Line Interface (CLI)
|
@@ -156,127 +154,167 @@ vivc --input path/to/source.viv [options]
|
|
156
154
|
|
157
155
|
### Examples
|
158
156
|
|
159
|
-
Compile a source file and write the resulting content bundle to file:
|
157
|
+
* Compile a source file and write the resulting content bundle to file:
|
160
158
|
|
161
|
-
```
|
162
|
-
vivc --input /path/to/my-actions.viv --output /path/to/myContentBundle.json
|
163
|
-
```
|
159
|
+
```
|
160
|
+
vivc --input /path/to/my-actions.viv --output /path/to/myContentBundle.json
|
161
|
+
```
|
164
162
|
|
165
|
-
Compile a source file and log the output in the console:
|
163
|
+
* Compile a source file and log the output in the console:
|
166
164
|
|
167
|
-
```
|
168
|
-
vivc --input /path/to/my-actions.viv --print
|
169
|
-
```
|
165
|
+
```
|
166
|
+
vivc --input /path/to/my-actions.viv --print
|
167
|
+
```
|
170
168
|
|
171
|
-
Log the version number for the installed Viv compiler:
|
169
|
+
* Log the version number for the installed Viv compiler:
|
172
170
|
|
173
|
-
```
|
174
|
-
vivc -v
|
175
|
-
```
|
171
|
+
```
|
172
|
+
vivc -v
|
173
|
+
```
|
176
174
|
|
177
175
|
|
178
176
|
## Python API
|
179
177
|
|
180
|
-
|
181
|
-
|
178
|
+
Once you've installed `viv-compiler`, the Viv compiler Python API can be invoked by importing `viv_compiler` into your project.
|
182
179
|
|
183
|
-
### `compile_from_path()`
|
184
180
|
|
185
|
-
|
181
|
+
### API Reference
|
186
182
|
|
187
|
-
|
183
|
+
#### `compile_from_path()`
|
188
184
|
|
189
|
-
*
|
185
|
+
* **Purpose**
|
190
186
|
|
191
|
-
*
|
187
|
+
* Invokes the compiler for a specified Viv source file.
|
192
188
|
|
193
|
-
*
|
189
|
+
* **Arguments**
|
194
190
|
|
195
|
-
*
|
191
|
+
* `source_file_path` (`Path`)
|
192
|
+
|
193
|
+
* Absolute path to a `.viv` source file.
|
196
194
|
|
197
|
-
* `
|
195
|
+
* `default_salience` (`float`)
|
198
196
|
|
199
|
-
|
197
|
+
* Default salience for actions (if unspecified).
|
200
198
|
|
201
|
-
* `
|
199
|
+
* `default_associations` `(list[str])`
|
202
200
|
|
203
|
-
|
204
|
-
|
205
|
-
* `use_memoization` (`bool`)
|
201
|
+
* Default associations for actions (if unspecified).
|
206
202
|
|
207
|
-
*
|
203
|
+
* `default_reaction_priority` (`float`)
|
204
|
+
|
205
|
+
* Default reaction priority for actions (if unspecified).
|
206
|
+
|
207
|
+
* `use_memoization` (`bool`)
|
208
|
+
|
209
|
+
* Whether to enable memoization in the underlying PEG parser (faster but uses more memory).
|
210
|
+
|
211
|
+
* `debug` (`bool`)
|
212
|
+
|
213
|
+
* Whether to enable verbose debugging for the underlying PEG parser.
|
208
214
|
|
209
|
-
*
|
215
|
+
* **Returns**
|
210
216
|
|
211
|
-
*
|
217
|
+
* The compiled Viv bundle, in a JSON-serializable format conforming to the `CompiledContentBundle` schema defined in the project code.
|
212
218
|
|
213
|
-
**
|
219
|
+
* **Raises**
|
214
220
|
|
215
|
-
*
|
221
|
+
* `VivCompileError`
|
222
|
+
|
223
|
+
* Raised when compilation fails.
|
216
224
|
|
217
|
-
**
|
225
|
+
* **Example**
|
218
226
|
|
219
|
-
|
227
|
+
```python
|
228
|
+
from pathlib import Path
|
229
|
+
from viv_compiler import compile_from_path, VivCompileError
|
230
|
+
|
231
|
+
try:
|
232
|
+
content_bundle = compile_from_path(source_file_path=Path("my-actions.viv"))
|
233
|
+
print("Compilation succeeded:", content_bundle)
|
234
|
+
except VivCompileError as e:
|
235
|
+
print("Compilation failed:", e)
|
236
|
+
```
|
220
237
|
|
221
|
-
* Raised when compilation fails.
|
222
238
|
|
239
|
+
#### `get_version()`
|
223
240
|
|
224
|
-
|
241
|
+
* **Purpose**
|
225
242
|
|
226
|
-
Returns the version string for the currently installed compiler.
|
243
|
+
* Returns the version string for the currently installed compiler. All content bundles produced by the compiler will be stamped with the same version number, making them compatible with any Viv runtime with the same version number.
|
227
244
|
|
245
|
+
* **Arguments**
|
228
246
|
|
229
|
-
|
247
|
+
* None.
|
230
248
|
|
231
|
-
|
249
|
+
* **Returns**
|
232
250
|
|
251
|
+
* A string constituting the version number of the installed Viv compiler.
|
233
252
|
|
234
|
-
|
253
|
+
* **Example**
|
235
254
|
|
236
|
-
|
255
|
+
```python
|
256
|
+
from viv_compiler import get_version
|
257
|
+
|
258
|
+
version = get_version()
|
259
|
+
print("Viv compiler version:", version)
|
260
|
+
```
|
237
261
|
|
238
|
-
```python
|
239
|
-
from pathlib import Path
|
240
|
-
from viv_compiler import compile_from_path, VivCompileError
|
241
262
|
|
242
|
-
|
243
|
-
content_bundle = compile_from_path(source_file_path=Path("my-actions.viv"))
|
244
|
-
print("Compilation succeeded:", content_bundle)
|
245
|
-
except VivCompileError as e:
|
246
|
-
print("Compilation failed:", e)
|
247
|
-
```
|
263
|
+
#### `VivCompileError`
|
248
264
|
|
249
|
-
|
265
|
+
* **Purpose**
|
250
266
|
|
251
|
-
|
252
|
-
from viv_compiler import get_version
|
253
|
-
print(get_version())
|
254
|
-
```
|
267
|
+
* Custom exception type (inherits from `Exception`) raised by the API when compilation fails.
|
255
268
|
|
256
269
|
|
257
270
|
## Running from Source
|
258
271
|
|
259
272
|
For contributors or developers working directly from a repo checkout:
|
260
273
|
|
261
|
-
|
262
|
-
# Clone the Viv monorepo
|
263
|
-
git clone https://github.com/james-owen-ryan/viv
|
264
|
-
cd viv/compiler
|
274
|
+
* Clone the Viv monorepo:
|
265
275
|
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
276
|
+
```
|
277
|
+
git clone https://github.com/james-owen-ryan/viv
|
278
|
+
cd viv/compiler
|
279
|
+
```
|
270
280
|
|
271
|
-
|
272
|
-
python -m pip install -e .
|
281
|
+
* Create a virtual environment:
|
273
282
|
|
274
|
-
|
275
|
-
python -m
|
283
|
+
```
|
284
|
+
python -m venv .venv-viv-compiler
|
285
|
+
```
|
276
286
|
|
277
|
-
|
278
|
-
|
279
|
-
|
287
|
+
* Activate the virtual environment...
|
288
|
+
|
289
|
+
* macOS/Linux:
|
290
|
+
|
291
|
+
```
|
292
|
+
source .venv-viv-compiler/bin/activate
|
293
|
+
```
|
294
|
+
|
295
|
+
* Windows PowerShell:
|
296
|
+
|
297
|
+
```
|
298
|
+
.\.venv-viv-compiler\Scripts\Activate.ps1
|
299
|
+
```
|
300
|
+
|
301
|
+
* Install the compiler package from source (editable):
|
302
|
+
|
303
|
+
```
|
304
|
+
python -m pip install -e .
|
305
|
+
```
|
306
|
+
|
307
|
+
* Invoke the CLI directly:
|
308
|
+
|
309
|
+
```
|
310
|
+
python -m viv_compiler --test
|
311
|
+
```
|
312
|
+
|
313
|
+
* Or use the installed console script:
|
314
|
+
|
315
|
+
```
|
316
|
+
vivc --test
|
317
|
+
```
|
280
318
|
|
281
319
|
|
282
320
|
## License
|
@@ -0,0 +1,279 @@
|
|
1
|
+
# Viv Compiler
|
2
|
+
|
3
|
+
This package contains the reference compiler for the domain-specific language (DSL) at the heart of [Viv](https://github.com/james-owen-ryan/viv), an action system for emergent narrative.
|
4
|
+
|
5
|
+
The Viv compiler accepts a **Viv source file** (`.viv`) and produces a **Viv content bundle** in a JSON-serializable format conforming to the `CompiledContentBundle` schema defined [here](https://github.com/james-owen-ryan/viv/blob/main/compiler/src/viv_compiler/types/dsl_public_schemas.py), making it ready for usage in any Viv runtime with the same version number as the compiler.
|
6
|
+
|
7
|
+
Once you've installed this package, you'll have access to the two compiler interfaces that are documented below:
|
8
|
+
|
9
|
+
* A **command-line interface** (`vivc`) for invoking the compiler from the command line.
|
10
|
+
|
11
|
+
* A **Python API** for invoking the compiler programmatically.
|
12
|
+
|
13
|
+
|
14
|
+
## Table of Contents
|
15
|
+
|
16
|
+
- [Installation](#installation)
|
17
|
+
- [Command-Line Interface](#command-line-interface-cli)
|
18
|
+
- [Python API](#python-api)
|
19
|
+
- [Running from Source](#running-from-source)
|
20
|
+
- [License](#license)
|
21
|
+
|
22
|
+
|
23
|
+
## Installation
|
24
|
+
|
25
|
+
* Install from PyPI:
|
26
|
+
|
27
|
+
```
|
28
|
+
pip install viv-compiler
|
29
|
+
```
|
30
|
+
|
31
|
+
* Run a smoke test to confirm your installation looks good:
|
32
|
+
|
33
|
+
```
|
34
|
+
vivc --test
|
35
|
+
```
|
36
|
+
|
37
|
+
|
38
|
+
## Command-Line Interface (CLI)
|
39
|
+
|
40
|
+
Once you've installed `viv-compiler`, the Viv compiler CLI will be exposed via the command `vivc` (and its alias `viv-compiler`).
|
41
|
+
|
42
|
+
|
43
|
+
### Usage
|
44
|
+
|
45
|
+
```
|
46
|
+
vivc --input path/to/source.viv [options]
|
47
|
+
```
|
48
|
+
|
49
|
+
|
50
|
+
### Arguments
|
51
|
+
|
52
|
+
* `-i, --input <path_to_source_file>`
|
53
|
+
|
54
|
+
* Required unless `--version` or `--test` is specified.
|
55
|
+
* Relative or absolute path to the Viv source file (`.viv`) to compile.
|
56
|
+
* If you are using `include` statements to import between files, this should be the main entrypoint file.
|
57
|
+
|
58
|
+
* `-o, --output <path_to_output_file>`
|
59
|
+
|
60
|
+
* Optional.
|
61
|
+
* Path to write the compiled JSON bundle.
|
62
|
+
|
63
|
+
|
64
|
+
### Flags and Options (Optional)
|
65
|
+
|
66
|
+
* `-h, --help`
|
67
|
+
|
68
|
+
* Show help message and exit.
|
69
|
+
|
70
|
+
* `-s, --default_salience <float>`
|
71
|
+
|
72
|
+
* Sets the default salience (floating-point number) for actions when unspecified.
|
73
|
+
* Default: value from `viv_compiler.config.DEFAULT_SALIENCE_VALUE`.
|
74
|
+
|
75
|
+
* `-a, --default_associations <string ...>`
|
76
|
+
|
77
|
+
* Sets the default associations (zero or more strings) for actions when unspecified.
|
78
|
+
* Default: value from `viv_compiler.config.DEFAULT_ASSOCIATIONS_VALUE`.
|
79
|
+
|
80
|
+
* `-r, --default_reaction_priority <float>`
|
81
|
+
|
82
|
+
* Sets the default reaction priority (floating-point number) for actions when unspecified.
|
83
|
+
* Default: value from `viv_compiler.config.DEFAULT_REACTION_PRIORITY_VALUE`.
|
84
|
+
|
85
|
+
* `-m, --memoization, --no-memoization`
|
86
|
+
|
87
|
+
* Enable/disable memoization in the underlying PEG parser (slower but uses less memory).
|
88
|
+
* Default: enabled.
|
89
|
+
|
90
|
+
* `-p, --print`
|
91
|
+
|
92
|
+
* After compilation, pretty-print the compiled bundle JSON.
|
93
|
+
|
94
|
+
* `-l, --list`
|
95
|
+
|
96
|
+
* After compilation, print out a list of compiled action names.
|
97
|
+
|
98
|
+
* `-d, --debug`
|
99
|
+
|
100
|
+
* Enable verbose debugging for the underlying PEG parser.
|
101
|
+
|
102
|
+
* `-t, --test`
|
103
|
+
|
104
|
+
* Run a smoke test using a sample Viv file to confirm the installation works.
|
105
|
+
* Ignores `--input`.
|
106
|
+
|
107
|
+
* `-v, --version`
|
108
|
+
|
109
|
+
* Print the current compiler version and exit.
|
110
|
+
|
111
|
+
|
112
|
+
### Examples
|
113
|
+
|
114
|
+
* Compile a source file and write the resulting content bundle to file:
|
115
|
+
|
116
|
+
```
|
117
|
+
vivc --input /path/to/my-actions.viv --output /path/to/myContentBundle.json
|
118
|
+
```
|
119
|
+
|
120
|
+
* Compile a source file and log the output in the console:
|
121
|
+
|
122
|
+
```
|
123
|
+
vivc --input /path/to/my-actions.viv --print
|
124
|
+
```
|
125
|
+
|
126
|
+
* Log the version number for the installed Viv compiler:
|
127
|
+
|
128
|
+
```
|
129
|
+
vivc -v
|
130
|
+
```
|
131
|
+
|
132
|
+
|
133
|
+
## Python API
|
134
|
+
|
135
|
+
Once you've installed `viv-compiler`, the Viv compiler Python API can be invoked by importing `viv_compiler` into your project.
|
136
|
+
|
137
|
+
|
138
|
+
### API Reference
|
139
|
+
|
140
|
+
#### `compile_from_path()`
|
141
|
+
|
142
|
+
* **Purpose**
|
143
|
+
|
144
|
+
* Invokes the compiler for a specified Viv source file.
|
145
|
+
|
146
|
+
* **Arguments**
|
147
|
+
|
148
|
+
* `source_file_path` (`Path`)
|
149
|
+
|
150
|
+
* Absolute path to a `.viv` source file.
|
151
|
+
|
152
|
+
* `default_salience` (`float`)
|
153
|
+
|
154
|
+
* Default salience for actions (if unspecified).
|
155
|
+
|
156
|
+
* `default_associations` `(list[str])`
|
157
|
+
|
158
|
+
* Default associations for actions (if unspecified).
|
159
|
+
|
160
|
+
* `default_reaction_priority` (`float`)
|
161
|
+
|
162
|
+
* Default reaction priority for actions (if unspecified).
|
163
|
+
|
164
|
+
* `use_memoization` (`bool`)
|
165
|
+
|
166
|
+
* Whether to enable memoization in the underlying PEG parser (faster but uses more memory).
|
167
|
+
|
168
|
+
* `debug` (`bool`)
|
169
|
+
|
170
|
+
* Whether to enable verbose debugging for the underlying PEG parser.
|
171
|
+
|
172
|
+
* **Returns**
|
173
|
+
|
174
|
+
* The compiled Viv bundle, in a JSON-serializable format conforming to the `CompiledContentBundle` schema defined in the project code.
|
175
|
+
|
176
|
+
* **Raises**
|
177
|
+
|
178
|
+
* `VivCompileError`
|
179
|
+
|
180
|
+
* Raised when compilation fails.
|
181
|
+
|
182
|
+
* **Example**
|
183
|
+
|
184
|
+
```python
|
185
|
+
from pathlib import Path
|
186
|
+
from viv_compiler import compile_from_path, VivCompileError
|
187
|
+
|
188
|
+
try:
|
189
|
+
content_bundle = compile_from_path(source_file_path=Path("my-actions.viv"))
|
190
|
+
print("Compilation succeeded:", content_bundle)
|
191
|
+
except VivCompileError as e:
|
192
|
+
print("Compilation failed:", e)
|
193
|
+
```
|
194
|
+
|
195
|
+
|
196
|
+
#### `get_version()`
|
197
|
+
|
198
|
+
* **Purpose**
|
199
|
+
|
200
|
+
* Returns the version string for the currently installed compiler. All content bundles produced by the compiler will be stamped with the same version number, making them compatible with any Viv runtime with the same version number.
|
201
|
+
|
202
|
+
* **Arguments**
|
203
|
+
|
204
|
+
* None.
|
205
|
+
|
206
|
+
* **Returns**
|
207
|
+
|
208
|
+
* A string constituting the version number of the installed Viv compiler.
|
209
|
+
|
210
|
+
* **Example**
|
211
|
+
|
212
|
+
```python
|
213
|
+
from viv_compiler import get_version
|
214
|
+
|
215
|
+
version = get_version()
|
216
|
+
print("Viv compiler version:", version)
|
217
|
+
```
|
218
|
+
|
219
|
+
|
220
|
+
#### `VivCompileError`
|
221
|
+
|
222
|
+
* **Purpose**
|
223
|
+
|
224
|
+
* Custom exception type (inherits from `Exception`) raised by the API when compilation fails.
|
225
|
+
|
226
|
+
|
227
|
+
## Running from Source
|
228
|
+
|
229
|
+
For contributors or developers working directly from a repo checkout:
|
230
|
+
|
231
|
+
* Clone the Viv monorepo:
|
232
|
+
|
233
|
+
```
|
234
|
+
git clone https://github.com/james-owen-ryan/viv
|
235
|
+
cd viv/compiler
|
236
|
+
```
|
237
|
+
|
238
|
+
* Create a virtual environment:
|
239
|
+
|
240
|
+
```
|
241
|
+
python -m venv .venv-viv-compiler
|
242
|
+
```
|
243
|
+
|
244
|
+
* Activate the virtual environment...
|
245
|
+
|
246
|
+
* macOS/Linux:
|
247
|
+
|
248
|
+
```
|
249
|
+
source .venv-viv-compiler/bin/activate
|
250
|
+
```
|
251
|
+
|
252
|
+
* Windows PowerShell:
|
253
|
+
|
254
|
+
```
|
255
|
+
.\.venv-viv-compiler\Scripts\Activate.ps1
|
256
|
+
```
|
257
|
+
|
258
|
+
* Install the compiler package from source (editable):
|
259
|
+
|
260
|
+
```
|
261
|
+
python -m pip install -e .
|
262
|
+
```
|
263
|
+
|
264
|
+
* Invoke the CLI directly:
|
265
|
+
|
266
|
+
```
|
267
|
+
python -m viv_compiler --test
|
268
|
+
```
|
269
|
+
|
270
|
+
* Or use the installed console script:
|
271
|
+
|
272
|
+
```
|
273
|
+
vivc --test
|
274
|
+
```
|
275
|
+
|
276
|
+
|
277
|
+
## License
|
278
|
+
|
279
|
+
MIT License © 2025 James Ryan
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
4
4
|
|
5
5
|
[project]
|
6
6
|
name = "viv-compiler"
|
7
|
-
version = "0.1.
|
7
|
+
version = "0.1.2" # This gets updated programmatically by `viv/scripts/bump_version.sh`
|
8
8
|
description = "Compiler for the DSL of Viv, an action system for emergent narrative."
|
9
9
|
license = { file = "LICENSE" }
|
10
10
|
authors = [{ name = "James Ryan", email = "mail@jamesryan.ai" }]
|
{viv_compiler-0.1.0/src/viv_compiler/utils → viv_compiler-0.1.2/src/viv_compiler}/_version.py
RENAMED
@@ -1,2 +1,2 @@
|
|
1
1
|
# This is programmatically updated by viv/scripts/bump_version.sh
|
2
|
-
__version__ = "0.1.
|
2
|
+
__version__ = "0.1.2"
|
@@ -10,6 +10,8 @@ import traceback
|
|
10
10
|
import viv_compiler.config
|
11
11
|
from pathlib import Path
|
12
12
|
from importlib import resources
|
13
|
+
|
14
|
+
from viv_compiler import VivCompileError
|
13
15
|
from .api import compile_from_path, get_version
|
14
16
|
from viv_compiler.types import CompiledContentBundle
|
15
17
|
|
@@ -22,16 +24,17 @@ def main() -> None:
|
|
22
24
|
args = parser.parse_args()
|
23
25
|
# If the user has requested the compiler version, print it and exit
|
24
26
|
if args.version:
|
25
|
-
print(
|
27
|
+
print(get_version())
|
26
28
|
sys.exit(0)
|
29
|
+
# If test mode is not engaged and no source file was provided, error and exit
|
30
|
+
if not args.test and not args.input:
|
31
|
+
parser.error("Unless the 'test' flag is engaged, an action file must be provided")
|
27
32
|
# If test mode is engaged, invoke the compiler on a test file and exit
|
33
|
+
print("\nCompiling...\n", file=sys.stderr)
|
28
34
|
if args.test:
|
29
35
|
_run_smoke_test(args=args)
|
30
36
|
sys.exit(0)
|
31
|
-
elif not args.input:
|
32
|
-
parser.error("Unless the 'test' flag is engaged, an action file must be provided")
|
33
37
|
# Otherwise, it's showtime, so let's invoke the compiler
|
34
|
-
print("\nCompiling...\n", file=sys.stderr)
|
35
38
|
if args.output:
|
36
39
|
path_to_output_file = Path(args.output).expanduser().resolve()
|
37
40
|
if not path_to_output_file.parent.exists():
|
@@ -152,7 +155,7 @@ def _run_smoke_test(args: argparse.Namespace) -> None:
|
|
152
155
|
source_file_path=sample_path,
|
153
156
|
default_salience=float(args.default_salience),
|
154
157
|
default_associations=args.default_associations,
|
155
|
-
default_reaction_priority=float(args.
|
158
|
+
default_reaction_priority=float(args.default_reaction_priority),
|
156
159
|
debug=False,
|
157
160
|
use_memoization=True,
|
158
161
|
)
|
@@ -174,7 +177,7 @@ def _invoke_compiler(args: argparse.Namespace) -> CompiledContentBundle:
|
|
174
177
|
source_file_path=source_file_path,
|
175
178
|
default_salience=float(args.default_salience),
|
176
179
|
default_associations=args.default_associations,
|
177
|
-
default_reaction_priority=float(args.
|
180
|
+
default_reaction_priority=float(args.default_reaction_priority),
|
178
181
|
debug=args.debug,
|
179
182
|
use_memoization=args.memoization,
|
180
183
|
)
|
@@ -188,10 +191,9 @@ def _invoke_compiler(args: argparse.Namespace) -> CompiledContentBundle:
|
|
188
191
|
except Exception:
|
189
192
|
pass
|
190
193
|
sys.exit(1)
|
191
|
-
except
|
192
|
-
|
193
|
-
|
194
|
-
traceback.print_exc()
|
194
|
+
except VivCompileError as e:
|
195
|
+
cause = e.__cause__ or e
|
196
|
+
print(f"Error encountered during compilation:\n\n{cause}\n", file=sys.stderr)
|
195
197
|
sys.exit(1)
|
196
198
|
|
197
199
|
|
@@ -211,7 +213,7 @@ def _emit_results(
|
|
211
213
|
"""
|
212
214
|
# If we're to print out the result, let's do so now, via `stdout` (with headers piped to `stderr`)
|
213
215
|
if args.print:
|
214
|
-
print("
|
216
|
+
print(" == Result ==\n", file=sys.stderr)
|
215
217
|
sys.stdout.write(json.dumps(compiled_content_bundle, indent=2, sort_keys=True))
|
216
218
|
sys.stdout.write("\n\n")
|
217
219
|
# If we're to list out the compiled actions, let's do so now (again via
|
@@ -223,7 +225,7 @@ def _emit_results(
|
|
223
225
|
lines.append(action_name)
|
224
226
|
if not action_names:
|
225
227
|
lines.append("N/A")
|
226
|
-
print(f"
|
228
|
+
print(f" == Actions ({len(action_names)}) ==\n", file=sys.stderr)
|
227
229
|
print("\n".join(f"- {line}" for line in lines), file=sys.stderr)
|
228
230
|
print("", file=sys.stderr)
|
229
231
|
# If an output file path has been provided, write the output file to the specified path
|