yamlscript 0.1.97__tar.gz → 0.2.1__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.1.97/lib/yamlscript.egg-info → yamlscript-0.2.1}/PKG-INFO +1 -1
- {yamlscript-0.1.97 → yamlscript-0.2.1}/ReadMe.md +4 -4
- {yamlscript-0.1.97 → yamlscript-0.2.1}/lib/yamlscript/__init__.py +26 -26
- {yamlscript-0.1.97 → yamlscript-0.2.1/lib/yamlscript.egg-info}/PKG-INFO +1 -1
- {yamlscript-0.1.97 → yamlscript-0.2.1}/setup.py +1 -1
- {yamlscript-0.1.97 → yamlscript-0.2.1}/.long_description.md +0 -0
- {yamlscript-0.1.97 → yamlscript-0.2.1}/MANIFEST.in +0 -0
- {yamlscript-0.1.97 → yamlscript-0.2.1}/lib/yamlscript.egg-info/SOURCES.txt +0 -0
- {yamlscript-0.1.97 → yamlscript-0.2.1}/lib/yamlscript.egg-info/dependency_links.txt +0 -0
- {yamlscript-0.1.97 → yamlscript-0.2.1}/lib/yamlscript.egg-info/requires.txt +0 -0
- {yamlscript-0.1.97 → yamlscript-0.2.1}/lib/yamlscript.egg-info/top_level.txt +0 -0
- {yamlscript-0.1.97 → yamlscript-0.2.1}/setup.cfg +0 -0
- {yamlscript-0.1.97 → yamlscript-0.2.1}/test/test.py +0 -0
|
@@ -20,7 +20,7 @@ names-url =:
|
|
|
20
20
|
name-list =: names-url:curl:json/load
|
|
21
21
|
|
|
22
22
|
# Data object with literal keys and generated values:
|
|
23
|
-
name::
|
|
23
|
+
name:: name-list:shuffle:first
|
|
24
24
|
aka:: name-list:rand-nth
|
|
25
25
|
age:: &num 2 * 3 * 7
|
|
26
26
|
color:: &hue
|
|
@@ -63,7 +63,7 @@ This makes YS a complete functional programming language right out of the box.
|
|
|
63
63
|
|
|
64
64
|
Even though YS compiles to Clojure, and Clojure compiles to Java, there is no
|
|
65
65
|
dependency on Java or the JVM.
|
|
66
|
-
YS is compiled to a native shared library (`
|
|
66
|
+
YS is compiled to a native shared library (`libys.so`) that can be used
|
|
67
67
|
by any programming language that can load shared libraries.
|
|
68
68
|
|
|
69
69
|
To see the Clojure code that YS compiles to, you can use the YS
|
|
@@ -128,7 +128,7 @@ You can install this module like any other Python module:
|
|
|
128
128
|
pip install yamlscript
|
|
129
129
|
```
|
|
130
130
|
|
|
131
|
-
but you will need to have a system install of `
|
|
131
|
+
but you will need to have a system install of `libys.so`.
|
|
132
132
|
|
|
133
133
|
One simple way to do that is with:
|
|
134
134
|
|
|
@@ -137,7 +137,7 @@ curl https://yamlscript.org/install | bash
|
|
|
137
137
|
```
|
|
138
138
|
|
|
139
139
|
> Note: The above command will install the latest version of the YAMLScript
|
|
140
|
-
command line utility, `ys`, and the shared library, `
|
|
140
|
+
command line utility, `ys`, and the shared library, `libys.so`, into
|
|
141
141
|
`~/local/bin` and `~/.local/lib` respectively.
|
|
142
142
|
|
|
143
143
|
See <https://yamlscript.org/doc/install/> for more info.
|
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
# This code is licensed under MIT license (See License for details)
|
|
3
3
|
|
|
4
4
|
"""
|
|
5
|
-
Python binding/API for the
|
|
5
|
+
Python binding/API for the libys shared library.
|
|
6
6
|
|
|
7
7
|
This module can be considered the reference implementation for YAMLScript
|
|
8
|
-
FFI bindings to
|
|
8
|
+
FFI bindings to libys.
|
|
9
9
|
|
|
10
10
|
The current user facing API consists of a single class, `YAMLScript`, which
|
|
11
11
|
has a single method: `.load(string)`.
|
|
@@ -15,8 +15,8 @@ object that the YAMLScript code evaluates to.
|
|
|
15
15
|
|
|
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
|
-
# We currently only support binding to an exact version of
|
|
19
|
-
yamlscript_version = '0.1
|
|
18
|
+
# We currently only support binding to an exact version of libys.
|
|
19
|
+
yamlscript_version = '0.2.1'
|
|
20
20
|
|
|
21
21
|
import os, sys
|
|
22
22
|
import ctypes
|
|
@@ -26,8 +26,8 @@ import json
|
|
|
26
26
|
assert sys.version_info >= (3, 6), \
|
|
27
27
|
"Python 3.6 or greater required for 'yamlscript'."
|
|
28
28
|
|
|
29
|
-
# Find the
|
|
30
|
-
def
|
|
29
|
+
# Find the libys shared library file path:
|
|
30
|
+
def find_libys_path():
|
|
31
31
|
# We currently only support platforms that GraalVM supports.
|
|
32
32
|
# And Windows is not yet implemented...
|
|
33
33
|
# Confirm platform and determine file extension:
|
|
@@ -39,47 +39,47 @@ def find_libyamlscript_path():
|
|
|
39
39
|
raise Exception(
|
|
40
40
|
"Unsupported platform '%s' for yamlscript." % sys.platform)
|
|
41
41
|
|
|
42
|
-
# We currently bind to an exact version of
|
|
43
|
-
# eg '
|
|
44
|
-
|
|
45
|
-
"
|
|
42
|
+
# We currently bind to an exact version of libys.
|
|
43
|
+
# eg 'libys.so.0.2.1'
|
|
44
|
+
libys_name = \
|
|
45
|
+
"libys.%s.%s" % (so, yamlscript_version)
|
|
46
46
|
|
|
47
|
-
# Use LD_LIBRARY_PATH to find
|
|
47
|
+
# Use LD_LIBRARY_PATH to find libys shared library, or default to
|
|
48
48
|
# '/usr/local/lib' (where it is installed by default):
|
|
49
49
|
ld_library_path = os.environ.get('LD_LIBRARY_PATH')
|
|
50
50
|
ld_library_paths = ld_library_path.split(':') if ld_library_path else []
|
|
51
51
|
ld_library_paths.append('/usr/local/lib')
|
|
52
52
|
ld_library_paths.append(os.environ.get('HOME') + '/.local/lib')
|
|
53
53
|
|
|
54
|
-
|
|
54
|
+
libys_path = None
|
|
55
55
|
for path in ld_library_paths:
|
|
56
|
-
path = path + '/' +
|
|
56
|
+
path = path + '/' + libys_name
|
|
57
57
|
if os.path.isfile(path):
|
|
58
|
-
|
|
58
|
+
libys_path = path
|
|
59
59
|
break
|
|
60
60
|
|
|
61
|
-
if not
|
|
61
|
+
if not libys_path:
|
|
62
62
|
raise Exception(
|
|
63
63
|
"""\
|
|
64
64
|
Shared library file '%s' not found
|
|
65
65
|
Try: curl https://yamlscript.org/install | VERSION=%s LIB=1 bash
|
|
66
66
|
See: https://github.com/yaml/yamlscript/wiki/Installing-YAMLScript
|
|
67
|
-
""" % (
|
|
67
|
+
""" % (libys_name, yamlscript_version))
|
|
68
68
|
|
|
69
|
-
return
|
|
69
|
+
return libys_path
|
|
70
70
|
|
|
71
|
-
# Load
|
|
72
|
-
|
|
71
|
+
# Load libys shared library:
|
|
72
|
+
libys = ctypes.CDLL(find_libys_path())
|
|
73
73
|
|
|
74
74
|
# Create binding to 'load_ys_to_json' function:
|
|
75
|
-
load_ys_to_json =
|
|
75
|
+
load_ys_to_json = libys.load_ys_to_json
|
|
76
76
|
load_ys_to_json.restype = ctypes.c_char_p
|
|
77
77
|
|
|
78
78
|
|
|
79
79
|
# The YAMLScript class is the main user facing API for this module.
|
|
80
80
|
class YAMLScript():
|
|
81
81
|
"""
|
|
82
|
-
Interface with the
|
|
82
|
+
Interface with the libys shared library.
|
|
83
83
|
|
|
84
84
|
Usage:
|
|
85
85
|
import yamlscript
|
|
@@ -96,7 +96,7 @@ class YAMLScript():
|
|
|
96
96
|
self.isolatethread = ctypes.c_void_p()
|
|
97
97
|
|
|
98
98
|
# Create a new GraalVM isolate:
|
|
99
|
-
rc =
|
|
99
|
+
rc = libys.graal_create_isolate(
|
|
100
100
|
None,
|
|
101
101
|
None,
|
|
102
102
|
ctypes.byref(self.isolatethread),
|
|
@@ -110,7 +110,7 @@ class YAMLScript():
|
|
|
110
110
|
# Reset any previous error:
|
|
111
111
|
self.error = None
|
|
112
112
|
|
|
113
|
-
# Call 'load_ys_to_json' function in
|
|
113
|
+
# Call 'load_ys_to_json' function in libys shared library:
|
|
114
114
|
data_json = load_ys_to_json(
|
|
115
115
|
self.isolatethread,
|
|
116
116
|
ctypes.c_char_p(bytes(input, "utf8")),
|
|
@@ -119,14 +119,14 @@ class YAMLScript():
|
|
|
119
119
|
# Decode the JSON response:
|
|
120
120
|
resp = json.loads(data_json)
|
|
121
121
|
|
|
122
|
-
# Check for
|
|
122
|
+
# Check for libys error in JSON response:
|
|
123
123
|
self.error = resp.get('error')
|
|
124
124
|
if self.error:
|
|
125
125
|
raise Exception(self.error['cause'])
|
|
126
126
|
|
|
127
127
|
# Get the response object from evaluating the YAMLScript string:
|
|
128
128
|
if not 'data' in resp:
|
|
129
|
-
raise Exception("Unexpected response from '
|
|
129
|
+
raise Exception("Unexpected response from 'libys'")
|
|
130
130
|
data = resp.get('data')
|
|
131
131
|
|
|
132
132
|
# Return the response object:
|
|
@@ -135,6 +135,6 @@ class YAMLScript():
|
|
|
135
135
|
# YAMLScript instance destructor:
|
|
136
136
|
def __del__(self):
|
|
137
137
|
# Tear down the isolate thread to free resources:
|
|
138
|
-
rc =
|
|
138
|
+
rc = libys.graal_tear_down_isolate(self.isolatethread)
|
|
139
139
|
if rc != 0:
|
|
140
140
|
raise Exception("Failed to tear down isolate")
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|