yamlscript 0.2.19__py3-none-macosx_14_0_arm64.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.
- yamlscript-0.2.19.data/purelib/yamlscript/__init__.py +147 -0
- yamlscript-0.2.19.data/purelib/yamlscript/libys/libys.dylib.0.2.19 +0 -0
- yamlscript-0.2.19.dist-info/METADATA +31 -0
- yamlscript-0.2.19.dist-info/RECORD +6 -0
- yamlscript-0.2.19.dist-info/WHEEL +5 -0
- yamlscript-0.2.19.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
# Copyright 2023-2026 Ingy dot Net
|
|
2
|
+
# This code is licensed under MIT license (See License for details)
|
|
3
|
+
|
|
4
|
+
"""
|
|
5
|
+
Python binding/API for the libys shared library.
|
|
6
|
+
|
|
7
|
+
This module can be considered the reference implementation for YAMLScript
|
|
8
|
+
FFI bindings to libys.
|
|
9
|
+
|
|
10
|
+
The current user facing API consists of a single class, `YAMLScript`, which
|
|
11
|
+
has a single method: `.load(string)`.
|
|
12
|
+
The load() method takes a YAMLScript string as input and returns the Python
|
|
13
|
+
object that the YAMLScript code evaluates to.
|
|
14
|
+
"""
|
|
15
|
+
|
|
16
|
+
# This value is automatically updated by 'make bump'.
|
|
17
|
+
# The version number is used to find the correct shared library file.
|
|
18
|
+
# We currently only support binding to an exact version of libys.
|
|
19
|
+
yamlscript_version = '0.2.19'
|
|
20
|
+
|
|
21
|
+
import os, sys
|
|
22
|
+
import ctypes
|
|
23
|
+
import json
|
|
24
|
+
from pathlib import Path
|
|
25
|
+
|
|
26
|
+
# Require Python 3.6 or greater:
|
|
27
|
+
assert sys.version_info >= (3, 6), \
|
|
28
|
+
"Python 3.6 or greater required for 'yamlscript'."
|
|
29
|
+
|
|
30
|
+
# Find the libys shared library file path:
|
|
31
|
+
def find_libys_path():
|
|
32
|
+
# We currently only support platforms that GraalVM supports.
|
|
33
|
+
# And Windows is not yet implemented...
|
|
34
|
+
# Confirm platform and determine file extension:
|
|
35
|
+
if sys.platform == 'linux':
|
|
36
|
+
so = 'so'
|
|
37
|
+
elif sys.platform == 'darwin':
|
|
38
|
+
so = 'dylib'
|
|
39
|
+
else:
|
|
40
|
+
raise Exception(
|
|
41
|
+
"Unsupported platform '%s' for yamlscript." % sys.platform)
|
|
42
|
+
|
|
43
|
+
# We currently bind to an exact version of libys.
|
|
44
|
+
# eg 'libys.so.0.2.19'
|
|
45
|
+
libys_name = \
|
|
46
|
+
"libys.%s.%s" % (so, yamlscript_version)
|
|
47
|
+
|
|
48
|
+
# First look for the shared library bundled in platform wheels.
|
|
49
|
+
bundled_path = \
|
|
50
|
+
Path(__file__).resolve().parent / 'libys' / libys_name
|
|
51
|
+
if bundled_path.is_file():
|
|
52
|
+
return str(bundled_path)
|
|
53
|
+
|
|
54
|
+
# Then use LD_LIBRARY_PATH to find libys shared library, or default
|
|
55
|
+
# to '/usr/local/lib' (where it is installed by default):
|
|
56
|
+
ld_library_path = os.environ.get('LD_LIBRARY_PATH')
|
|
57
|
+
ld_library_paths = ld_library_path.split(':') if ld_library_path else []
|
|
58
|
+
ld_library_paths.append('/usr/local/lib')
|
|
59
|
+
ld_library_paths.append(os.environ.get('HOME') + '/.local/lib')
|
|
60
|
+
|
|
61
|
+
libys_path = None
|
|
62
|
+
for path in ld_library_paths:
|
|
63
|
+
path = path + '/' + libys_name
|
|
64
|
+
if os.path.isfile(path):
|
|
65
|
+
libys_path = path
|
|
66
|
+
break
|
|
67
|
+
|
|
68
|
+
if not libys_path:
|
|
69
|
+
raise Exception(
|
|
70
|
+
"""\
|
|
71
|
+
Shared library file '%s' not found
|
|
72
|
+
Try: curl https://yamlscript.org/install | VERSION=%s LIB=1 bash
|
|
73
|
+
See: https://github.com/yaml/yamlscript/wiki/Installing-YAMLScript
|
|
74
|
+
""" % (libys_name, yamlscript_version))
|
|
75
|
+
|
|
76
|
+
return libys_path
|
|
77
|
+
|
|
78
|
+
# Load libys shared library:
|
|
79
|
+
libys = ctypes.CDLL(find_libys_path())
|
|
80
|
+
|
|
81
|
+
# Create binding to 'load_ys_to_json' function:
|
|
82
|
+
load_ys_to_json = libys.load_ys_to_json
|
|
83
|
+
load_ys_to_json.restype = ctypes.c_char_p
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
# The YAMLScript class is the main user facing API for this module.
|
|
87
|
+
class YAMLScript():
|
|
88
|
+
"""
|
|
89
|
+
Interface with the libys shared library.
|
|
90
|
+
|
|
91
|
+
Usage:
|
|
92
|
+
import yamlscript
|
|
93
|
+
ys = yamlscript.YAMLScript()
|
|
94
|
+
data = ys.load(open('file.ys').read())
|
|
95
|
+
"""
|
|
96
|
+
|
|
97
|
+
# YAMLScript instance constructor:
|
|
98
|
+
def __init__(self, config={}):
|
|
99
|
+
# config not used yet
|
|
100
|
+
# self.config = config
|
|
101
|
+
|
|
102
|
+
# Create a new GraalVM isolatethread for life of the YAMLScript instance:
|
|
103
|
+
self.isolatethread = ctypes.c_void_p()
|
|
104
|
+
|
|
105
|
+
# Create a new GraalVM isolate:
|
|
106
|
+
rc = libys.graal_create_isolate(
|
|
107
|
+
None,
|
|
108
|
+
None,
|
|
109
|
+
ctypes.byref(self.isolatethread),
|
|
110
|
+
)
|
|
111
|
+
|
|
112
|
+
if rc != 0:
|
|
113
|
+
raise Exception("Failed to create isolate")
|
|
114
|
+
|
|
115
|
+
# Compile and eval a YAMLScript string and return the result:
|
|
116
|
+
def load(self, input):
|
|
117
|
+
# Reset any previous error:
|
|
118
|
+
self.error = None
|
|
119
|
+
|
|
120
|
+
# Call 'load_ys_to_json' function in libys shared library:
|
|
121
|
+
data_json = load_ys_to_json(
|
|
122
|
+
self.isolatethread,
|
|
123
|
+
ctypes.c_char_p(bytes(input, "utf8")),
|
|
124
|
+
).decode()
|
|
125
|
+
|
|
126
|
+
# Decode the JSON response:
|
|
127
|
+
resp = json.loads(data_json)
|
|
128
|
+
|
|
129
|
+
# Check for libys error in JSON response:
|
|
130
|
+
self.error = resp.get('error')
|
|
131
|
+
if self.error:
|
|
132
|
+
raise Exception(self.error['cause'])
|
|
133
|
+
|
|
134
|
+
# Get the response object from evaluating the YAMLScript string:
|
|
135
|
+
if not 'data' in resp:
|
|
136
|
+
raise Exception("Unexpected response from 'libys'")
|
|
137
|
+
data = resp.get('data')
|
|
138
|
+
|
|
139
|
+
# Return the response object:
|
|
140
|
+
return data
|
|
141
|
+
|
|
142
|
+
# YAMLScript instance destructor:
|
|
143
|
+
def __del__(self):
|
|
144
|
+
# Tear down the isolate thread to free resources:
|
|
145
|
+
rc = libys.graal_tear_down_isolate(self.isolatethread)
|
|
146
|
+
if rc != 0:
|
|
147
|
+
raise Exception("Failed to tear down isolate")
|
|
Binary file
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: yamlscript
|
|
3
|
+
Version: 0.2.19
|
|
4
|
+
Summary: Program in YAML — Code is Data
|
|
5
|
+
Home-page: https://github.com/ingydotnet/yamlscript
|
|
6
|
+
Author: Ingy döt Net
|
|
7
|
+
Author-email: ingy@ingy.net
|
|
8
|
+
License: MIT
|
|
9
|
+
Keywords: yaml,language
|
|
10
|
+
Classifier: Development Status :: 3 - Alpha
|
|
11
|
+
Classifier: Intended Audience :: Developers
|
|
12
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.6
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.7
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
18
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
19
|
+
Requires-Python: >=3.6, <4
|
|
20
|
+
Description-Content-Type: text/markdown
|
|
21
|
+
Requires-Dist: pyyaml
|
|
22
|
+
Dynamic: author
|
|
23
|
+
Dynamic: author-email
|
|
24
|
+
Dynamic: classifier
|
|
25
|
+
Dynamic: description-content-type
|
|
26
|
+
Dynamic: home-page
|
|
27
|
+
Dynamic: keywords
|
|
28
|
+
Dynamic: license
|
|
29
|
+
Dynamic: requires-dist
|
|
30
|
+
Dynamic: requires-python
|
|
31
|
+
Dynamic: summary
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
yamlscript-0.2.19.data/purelib/yamlscript/__init__.py,sha256=fYvhDQ__vCSYcN8ELdb30puJoem2Z74PFC-UiqHrM6c,4389
|
|
2
|
+
yamlscript-0.2.19.data/purelib/yamlscript/libys/libys.dylib.0.2.19,sha256=e6c-afdt6Qk7Dj1HSDKU-K4cxPxlEuQSV4zpncE_snA,59140360
|
|
3
|
+
yamlscript-0.2.19.dist-info/METADATA,sha256=pWM4Rdtukx2ciPN-USEcrQbuw_uvhmozz1P140NVy5M,979
|
|
4
|
+
yamlscript-0.2.19.dist-info/WHEEL,sha256=IjHG6Sw94rMrTtb4jpo2tERipQ18kULC4hOv7U1u_9I,106
|
|
5
|
+
yamlscript-0.2.19.dist-info/top_level.txt,sha256=U1bWDl8Bms9lndIZd3ITPWc-iAHZVErB56tY8C6otwg,11
|
|
6
|
+
yamlscript-0.2.19.dist-info/RECORD,,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
yamlscript
|