yamlscript 0.2.3__tar.gz → 0.2.4__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.
- {yamlscript-0.2.3/lib/yamlscript.egg-info → yamlscript-0.2.4}/PKG-INFO +1 -1
- yamlscript-0.2.4/ReadMe.md +178 -0
- {yamlscript-0.2.3 → yamlscript-0.2.4}/lib/yamlscript/__init__.py +2 -2
- {yamlscript-0.2.3 → yamlscript-0.2.4/lib/yamlscript.egg-info}/PKG-INFO +1 -1
- {yamlscript-0.2.3 → yamlscript-0.2.4}/setup.py +1 -1
- yamlscript-0.2.3/ReadMe.md +0 -166
- {yamlscript-0.2.3 → yamlscript-0.2.4}/.long_description.md +0 -0
- {yamlscript-0.2.3 → yamlscript-0.2.4}/MANIFEST.in +0 -0
- {yamlscript-0.2.3 → yamlscript-0.2.4}/lib/yamlscript.egg-info/SOURCES.txt +0 -0
- {yamlscript-0.2.3 → yamlscript-0.2.4}/lib/yamlscript.egg-info/dependency_links.txt +0 -0
- {yamlscript-0.2.3 → yamlscript-0.2.4}/lib/yamlscript.egg-info/requires.txt +0 -0
- {yamlscript-0.2.3 → yamlscript-0.2.4}/lib/yamlscript.egg-info/top_level.txt +0 -0
- {yamlscript-0.2.3 → yamlscript-0.2.4}/setup.cfg +0 -0
- {yamlscript-0.2.3 → yamlscript-0.2.4}/test/test.py +0 -0
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
<!-- DO NOT EDIT — THIS FILE WAS GENERATED -->
|
|
2
|
+
|
|
3
|
+
YAMLScript
|
|
4
|
+
==========
|
|
5
|
+
|
|
6
|
+
Add Logic to Your YAML Files
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
## Quick Start
|
|
10
|
+
|
|
11
|
+
This library lets you load YAML files that may or may not contain
|
|
12
|
+
[YAMLScript](https://yamlscript.org) functional programming logic.
|
|
13
|
+
You can use it as a drop-in replacement for your current YAML loader.
|
|
14
|
+
|
|
15
|
+
Here's an example `config.yaml` that makes use of YAMLScript functions.
|
|
16
|
+
|
|
17
|
+
```yaml
|
|
18
|
+
# config.yaml with YAMLScript:
|
|
19
|
+
!YS-v0:
|
|
20
|
+
|
|
21
|
+
# Define variables
|
|
22
|
+
db-host =: ENV.DB_HOST || 'localhost'
|
|
23
|
+
db-port =: ENV.DB_PORT || 5432
|
|
24
|
+
deploy =: ENV.DEPLOYMENT || 'dev'
|
|
25
|
+
:when deploy !~ /^(dev|stage|prod)/:
|
|
26
|
+
die: |
|
|
27
|
+
Invalid deployment value '$deploy'.
|
|
28
|
+
Must be one of: dev | stage | prod
|
|
29
|
+
|
|
30
|
+
# Normal YAML data
|
|
31
|
+
description: Dynamic application configuration
|
|
32
|
+
|
|
33
|
+
# Dynamic data values
|
|
34
|
+
database:
|
|
35
|
+
host:: db-host
|
|
36
|
+
port:: db-port:num
|
|
37
|
+
name:: "app_$deploy"
|
|
38
|
+
|
|
39
|
+
# Import external data
|
|
40
|
+
features:: load('common.yaml').features
|
|
41
|
+
|
|
42
|
+
# Use logic and conditions
|
|
43
|
+
cache:
|
|
44
|
+
# Variable scoped to this mapping
|
|
45
|
+
enabled =: deploy == 'production'
|
|
46
|
+
|
|
47
|
+
directory: .cache
|
|
48
|
+
enabled:: enabled
|
|
49
|
+
limit: 100
|
|
50
|
+
# Conditional key/value pairs
|
|
51
|
+
:when enabled::
|
|
52
|
+
limit:: 1000
|
|
53
|
+
ttl:: 60 * 60 # 3600
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
## What is YAMLScript?
|
|
58
|
+
|
|
59
|
+
YAMLScript is a functional programming language that can be embedded in YAML.
|
|
60
|
+
Its syntax is 100% YAML so files that embed it are still valid YAML files.
|
|
61
|
+
|
|
62
|
+
The YAMLScript project provides YAML loader libraries for many programming
|
|
63
|
+
languages.
|
|
64
|
+
They can be used to load any YAML config files properly, whether or not they
|
|
65
|
+
contain functional programming logic.
|
|
66
|
+
|
|
67
|
+
It's perfect for:
|
|
68
|
+
|
|
69
|
+
* **Configuration files** that need logic, variables, and dynamic values
|
|
70
|
+
* **Data transformation** with built-in functions for JSON, YAML, and text
|
|
71
|
+
processing
|
|
72
|
+
* **Templating** with powerful string interpolation and data manipulation
|
|
73
|
+
* **Scripting** as a complete functional programming language
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
## Key Features
|
|
77
|
+
|
|
78
|
+
* **Drop-in YAML replacement** – Works with your existing YAML files
|
|
79
|
+
* **Variables & functions** – Define and reuse values throughout your files
|
|
80
|
+
* **External data loading** – Import JSON, YAML, or data from URLs
|
|
81
|
+
* **Conditional logic** – Use if/then/else and pattern matching
|
|
82
|
+
* **Data transformation** – Built-ins for transforming & manipulating data
|
|
83
|
+
* **String interpolation** – Embed expressions/variables directly in strings
|
|
84
|
+
* **No JVM required** – Runs as a native library despite compiling to Clojure
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
## How It Works
|
|
88
|
+
|
|
89
|
+
YAMLScript extends YAML with a simple, elegant syntax:
|
|
90
|
+
|
|
91
|
+
```yaml
|
|
92
|
+
# file.yaml
|
|
93
|
+
!YS-v0: # Enable YAMLScript
|
|
94
|
+
|
|
95
|
+
name =: 'World' # Variable assignment
|
|
96
|
+
nums =:: [1, 2, 3] # Any YAML value
|
|
97
|
+
|
|
98
|
+
# Literal YAML with ':'
|
|
99
|
+
a key: a value
|
|
100
|
+
|
|
101
|
+
# Evaluated expressions with '::'
|
|
102
|
+
message:: "Hello, $name!"
|
|
103
|
+
sum:: nums.reduce(+)
|
|
104
|
+
timestamp:: now():str
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
You can load this file from a program as described below, or you can use the
|
|
108
|
+
`ys` YAMLScript binary to load the file from the command line:
|
|
109
|
+
|
|
110
|
+
```bash
|
|
111
|
+
$ ys -Y file.yaml
|
|
112
|
+
a key: a value
|
|
113
|
+
message: Hello, World!
|
|
114
|
+
sum: 6
|
|
115
|
+
timestamp: '2025-09-14T22:35:42.832470203Z'
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
Under the hood, YAMLScript compiles YAML to Clojure and evaluates it, giving
|
|
119
|
+
you access to a rich functional programming environment.
|
|
120
|
+
|
|
121
|
+
## Python Usage
|
|
122
|
+
|
|
123
|
+
Use `yamlscript.py` as a drop-in replacement for your current YAML loader:
|
|
124
|
+
|
|
125
|
+
```python
|
|
126
|
+
# program.py
|
|
127
|
+
from yamlscript import YAMLScript
|
|
128
|
+
import json
|
|
129
|
+
|
|
130
|
+
ys = YAMLScript()
|
|
131
|
+
|
|
132
|
+
# Load from file
|
|
133
|
+
input = open('config.yaml').read()
|
|
134
|
+
config = ys.load(input)
|
|
135
|
+
|
|
136
|
+
# Convert to JSON
|
|
137
|
+
print(json.dumps(config, indent=2))
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
## Installation
|
|
142
|
+
|
|
143
|
+
Install YAMLScript for Python and the `libys.so` shared library:
|
|
144
|
+
|
|
145
|
+
```bash
|
|
146
|
+
pip install yamlscript
|
|
147
|
+
curl -sSL https://yamlscript.org/install | bash
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
See <https://yamlscript.org/doc/install/> for more info.
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
### Requirements
|
|
154
|
+
|
|
155
|
+
* Python 3.8 or higher
|
|
156
|
+
|
|
157
|
+
## See Also
|
|
158
|
+
|
|
159
|
+
* [YAMLScript Web Site](https://yamlscript.org)
|
|
160
|
+
* [Learn YAMLScript](https://exercism.org/tracks/yamlscript)
|
|
161
|
+
* [YAMLScript Blog](https://yamlscript.org/blog)
|
|
162
|
+
* [YAMLScript Source Code](https://github.com/yaml/yamlscript)
|
|
163
|
+
* [YAMLScript Programs](https://rosettacode.org/wiki/Category:YAMLScript)
|
|
164
|
+
* [YAML](https://yaml.org)
|
|
165
|
+
* [Clojure](https://clojure.org)
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
## Authors
|
|
169
|
+
|
|
170
|
+
* [Ingy döt Net](https://github.com/ingydotnet)
|
|
171
|
+
|
|
172
|
+
## License & Copyright
|
|
173
|
+
|
|
174
|
+
Copyright 2022-2025 Ingy döt Net <ingy@ingy.net>
|
|
175
|
+
|
|
176
|
+
This project is licensed under the terms of the `MIT` license.
|
|
177
|
+
See [LICENSE](https://github.com/yaml/yamlscript/blob/main/License) for more
|
|
178
|
+
details.
|
|
@@ -16,7 +16,7 @@ object that the YAMLScript code evaluates to.
|
|
|
16
16
|
# This value is automatically updated by 'make bump'.
|
|
17
17
|
# The version number is used to find the correct shared library file.
|
|
18
18
|
# We currently only support binding to an exact version of libys.
|
|
19
|
-
yamlscript_version = '0.2.
|
|
19
|
+
yamlscript_version = '0.2.4'
|
|
20
20
|
|
|
21
21
|
import os, sys
|
|
22
22
|
import ctypes
|
|
@@ -40,7 +40,7 @@ def find_libys_path():
|
|
|
40
40
|
"Unsupported platform '%s' for yamlscript." % sys.platform)
|
|
41
41
|
|
|
42
42
|
# We currently bind to an exact version of libys.
|
|
43
|
-
# eg 'libys.so.0.2.
|
|
43
|
+
# eg 'libys.so.0.2.4'
|
|
44
44
|
libys_name = \
|
|
45
45
|
"libys.%s.%s" % (so, yamlscript_version)
|
|
46
46
|
|
yamlscript-0.2.3/ReadMe.md
DELETED
|
@@ -1,166 +0,0 @@
|
|
|
1
|
-
<!-- DO NOT EDIT — THIS FILE WAS GENERATED -->
|
|
2
|
-
|
|
3
|
-
YS / YAMLScript
|
|
4
|
-
===============
|
|
5
|
-
|
|
6
|
-
Add Logic to Your YAML Files
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
## Synopsis
|
|
10
|
-
|
|
11
|
-
Load `file.yaml` with YS:
|
|
12
|
-
|
|
13
|
-
```yaml
|
|
14
|
-
!YS-v0:
|
|
15
|
-
|
|
16
|
-
# Get data from external sources:
|
|
17
|
-
names-url =:
|
|
18
|
-
'github:dominictarr/random-name/first-names.json'
|
|
19
|
-
|
|
20
|
-
name-list =: names-url:curl:json/load
|
|
21
|
-
|
|
22
|
-
# Data object with literal keys and generated values:
|
|
23
|
-
name:: name-list:shuffle:first
|
|
24
|
-
aka:: name-list:rand-nth
|
|
25
|
-
age:: &num 2 * 3 * 7
|
|
26
|
-
color:: &hue
|
|
27
|
-
rand-nth: qw(red green blue yellow)
|
|
28
|
-
title:: "$(*num) shades of $(*hue)."
|
|
29
|
-
```
|
|
30
|
-
|
|
31
|
-
and get:
|
|
32
|
-
```json
|
|
33
|
-
{
|
|
34
|
-
"name": "Dolores",
|
|
35
|
-
"aka": "Anita",
|
|
36
|
-
"age": 42,
|
|
37
|
-
"color": "green",
|
|
38
|
-
"title": "42 shades of green."
|
|
39
|
-
}
|
|
40
|
-
```
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
## Description
|
|
44
|
-
|
|
45
|
-
[YS](https://yamlscript.org) is a functional programming language with a clean
|
|
46
|
-
YAML syntax.
|
|
47
|
-
|
|
48
|
-
YS can be used for enhancing ordinary [YAML](https://yaml.org) files with
|
|
49
|
-
functional operations, such as:
|
|
50
|
-
|
|
51
|
-
* Import (parts of) other YAML files to any node
|
|
52
|
-
* String interpolation including function calls
|
|
53
|
-
* Data transforms including ones defined by you
|
|
54
|
-
|
|
55
|
-
This YS library should be a drop-in replacement for your current YAML loader!
|
|
56
|
-
|
|
57
|
-
Most existing YAML files are already valid YS files.
|
|
58
|
-
This means that YS works as a normal YAML loader, but can also evaluate
|
|
59
|
-
functional expressions if asked to.
|
|
60
|
-
|
|
61
|
-
Under the hood, YS code compiles to the Clojure programming language.
|
|
62
|
-
This makes YS a complete functional programming language right out of the box.
|
|
63
|
-
|
|
64
|
-
Even though YS compiles to Clojure, and Clojure compiles to Java, there is no
|
|
65
|
-
dependency on Java or the JVM.
|
|
66
|
-
YS is compiled to a native shared library (`libys.so`) that can be used
|
|
67
|
-
by any programming language that can load shared libraries.
|
|
68
|
-
|
|
69
|
-
To see the Clojure code that YS compiles to, you can use the YS
|
|
70
|
-
CLI binary `ys` to run:
|
|
71
|
-
|
|
72
|
-
```text
|
|
73
|
-
$ ys --compile file.ys
|
|
74
|
-
(let
|
|
75
|
-
[names-url "https://raw.githubusercontent.com/dominictarr/random-name/master/first-names.json"
|
|
76
|
-
name-list (json/load (curl names-url))]
|
|
77
|
-
(%
|
|
78
|
-
"name" (first (shuffle name-list))
|
|
79
|
-
"aka" (rand-nth name-list)
|
|
80
|
-
"age" (_& 'num (mul+ 2 3 7))
|
|
81
|
-
"color" (_& 'hue (rand-nth (qw red green blue yellow)))
|
|
82
|
-
"title" (str (_** 'num) " shades of " (_** 'hue) ".")))
|
|
83
|
-
```
|
|
84
|
-
|
|
85
|
-
## Python Usage
|
|
86
|
-
|
|
87
|
-
File `prog.py`:
|
|
88
|
-
|
|
89
|
-
```python
|
|
90
|
-
from yamlscript import YAMLScript
|
|
91
|
-
ys = YAMLScript()
|
|
92
|
-
input = open('file.ys').read()
|
|
93
|
-
data = ys.load(input)
|
|
94
|
-
print(data)
|
|
95
|
-
```
|
|
96
|
-
|
|
97
|
-
File `file.ys`:
|
|
98
|
-
|
|
99
|
-
```yaml
|
|
100
|
-
!YS-v0:
|
|
101
|
-
|
|
102
|
-
name =: "World"
|
|
103
|
-
|
|
104
|
-
foo: [1, 2, ! inc(41)]
|
|
105
|
-
bar:: load("other.yaml")
|
|
106
|
-
baz:: "Hello, $name!"
|
|
107
|
-
```
|
|
108
|
-
|
|
109
|
-
File `other.yaml`:
|
|
110
|
-
|
|
111
|
-
```yaml
|
|
112
|
-
oh: Hello
|
|
113
|
-
```
|
|
114
|
-
|
|
115
|
-
Run:
|
|
116
|
-
|
|
117
|
-
```text
|
|
118
|
-
$ python prog.py
|
|
119
|
-
{'foo': [1, 2, 42], 'bar': {'oh': 'Hello'}, 'baz': 'Hello, World!'}
|
|
120
|
-
```
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
## Installation
|
|
124
|
-
|
|
125
|
-
You can install this module like any other Python module:
|
|
126
|
-
|
|
127
|
-
```bash
|
|
128
|
-
pip install yamlscript
|
|
129
|
-
```
|
|
130
|
-
|
|
131
|
-
but you will need to have a system install of `libys.so`.
|
|
132
|
-
|
|
133
|
-
One simple way to do that is with:
|
|
134
|
-
|
|
135
|
-
```bash
|
|
136
|
-
curl https://yamlscript.org/install | bash
|
|
137
|
-
```
|
|
138
|
-
|
|
139
|
-
> Note: The above command will install the latest version of the YAMLScript
|
|
140
|
-
command line utility, `ys`, and the shared library, `libys.so`, into
|
|
141
|
-
`~/local/bin` and `~/.local/lib` respectively.
|
|
142
|
-
|
|
143
|
-
See <https://yamlscript.org/doc/install/> for more info.
|
|
144
|
-
|
|
145
|
-
## See Also
|
|
146
|
-
|
|
147
|
-
* [YS Web Site](https://yamlscript.org)
|
|
148
|
-
* [YS Blog](https://yamlscript.org/blog)
|
|
149
|
-
* [YS Source Code](https://github.com/yaml/yamlscript)
|
|
150
|
-
* [YS Samples](https://github.com/yaml/yamlscript/tree/main/sample)
|
|
151
|
-
* [YS Programs](https://rosettacode.org/wiki/Category:YAMLScript)
|
|
152
|
-
* [YAML](https://yaml.org)
|
|
153
|
-
* [Clojure](https://clojure.org)
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
## Authors
|
|
157
|
-
|
|
158
|
-
* [Ingy döt Net](https://github.com/ingydotnet)
|
|
159
|
-
|
|
160
|
-
## License & Copyright
|
|
161
|
-
|
|
162
|
-
Copyright 2022-2025 Ingy döt Net <ingy@ingy.net>
|
|
163
|
-
|
|
164
|
-
This project is licensed under the terms of the `MIT` license.
|
|
165
|
-
See [LICENSE](https://github.com/yaml/yamlscript/blob/main/License) for
|
|
166
|
-
more details.
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|