yamlscript 0.2.22__py3-none-win_amd64.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,153 @@
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.22'
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
+ # Confirm platform and determine file extension:
34
+ if sys.platform == 'linux':
35
+ libys_name = \
36
+ "libys.so.%s" % yamlscript_version
37
+ elif sys.platform == 'darwin':
38
+ libys_name = \
39
+ "libys.dylib.%s" % yamlscript_version
40
+ elif sys.platform == 'win32':
41
+ libys_name = 'libys.dll'
42
+ else:
43
+ raise Exception(
44
+ "Unsupported platform '%s' for yamlscript." % sys.platform)
45
+
46
+ # We currently bind to an exact version of libys.
47
+ # eg 'libys.so.0.2.22'
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 the platform library path plus common install locations.
55
+ if sys.platform == 'win32':
56
+ library_path = os.environ.get('PATH')
57
+ library_paths = library_path.split(os.pathsep) if library_path else []
58
+ else:
59
+ library_path = os.environ.get('LD_LIBRARY_PATH')
60
+ library_paths = library_path.split(os.pathsep) if library_path else []
61
+ library_paths.append('/usr/local/lib')
62
+
63
+ home = os.environ.get('HOME') or os.path.expanduser('~')
64
+ if home:
65
+ library_paths.append(os.path.join(home, '.local', 'lib'))
66
+
67
+ libys_path = None
68
+ for path in library_paths:
69
+ full_path = os.path.join(path, libys_name)
70
+ if os.path.isfile(full_path):
71
+ libys_path = full_path
72
+ break
73
+
74
+ if not libys_path:
75
+ raise Exception(
76
+ """\
77
+ Shared library file '%s' not found
78
+ Try: curl https://yamlscript.org/install | VERSION=%s LIB=1 bash
79
+ See: https://github.com/yaml/yamlscript/wiki/Installing-YAMLScript
80
+ """ % (libys_name, yamlscript_version))
81
+
82
+ return libys_path
83
+
84
+ # Load libys shared library:
85
+ libys = ctypes.CDLL(find_libys_path())
86
+
87
+ # Create binding to 'load_ys_to_json' function:
88
+ load_ys_to_json = libys.load_ys_to_json
89
+ load_ys_to_json.restype = ctypes.c_char_p
90
+
91
+
92
+ # The YAMLScript class is the main user facing API for this module.
93
+ class YAMLScript():
94
+ """
95
+ Interface with the libys shared library.
96
+
97
+ Usage:
98
+ import yamlscript
99
+ ys = yamlscript.YAMLScript()
100
+ data = ys.load(open('file.ys').read())
101
+ """
102
+
103
+ # YAMLScript instance constructor:
104
+ def __init__(self, config={}):
105
+ # config not used yet
106
+ # self.config = config
107
+
108
+ # Create a new GraalVM isolatethread for life of the YAMLScript instance:
109
+ self.isolatethread = ctypes.c_void_p()
110
+
111
+ # Create a new GraalVM isolate:
112
+ rc = libys.graal_create_isolate(
113
+ None,
114
+ None,
115
+ ctypes.byref(self.isolatethread),
116
+ )
117
+
118
+ if rc != 0:
119
+ raise Exception("Failed to create isolate")
120
+
121
+ # Compile and eval a YAMLScript string and return the result:
122
+ def load(self, input):
123
+ # Reset any previous error:
124
+ self.error = None
125
+
126
+ # Call 'load_ys_to_json' function in libys shared library:
127
+ data_json = load_ys_to_json(
128
+ self.isolatethread,
129
+ ctypes.c_char_p(bytes(input, "utf8")),
130
+ ).decode()
131
+
132
+ # Decode the JSON response:
133
+ resp = json.loads(data_json)
134
+
135
+ # Check for libys error in JSON response:
136
+ self.error = resp.get('error')
137
+ if self.error:
138
+ raise Exception(self.error['cause'])
139
+
140
+ # Get the response object from evaluating the YAMLScript string:
141
+ if not 'data' in resp:
142
+ raise Exception("Unexpected response from 'libys'")
143
+ data = resp.get('data')
144
+
145
+ # Return the response object:
146
+ return data
147
+
148
+ # YAMLScript instance destructor:
149
+ def __del__(self):
150
+ # Tear down the isolate thread to free resources:
151
+ rc = libys.graal_tear_down_isolate(self.isolatethread)
152
+ if rc != 0:
153
+ raise Exception("Failed to tear down isolate")
@@ -0,0 +1,33 @@
1
+ Metadata-Version: 2.4
2
+ Name: yamlscript
3
+ Version: 0.2.22
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
+ License-File: License
22
+ Requires-Dist: pyyaml
23
+ Dynamic: author
24
+ Dynamic: author-email
25
+ Dynamic: classifier
26
+ Dynamic: description-content-type
27
+ Dynamic: home-page
28
+ Dynamic: keywords
29
+ Dynamic: license
30
+ Dynamic: license-file
31
+ Dynamic: requires-dist
32
+ Dynamic: requires-python
33
+ Dynamic: summary
@@ -0,0 +1,7 @@
1
+ yamlscript-0.2.22.data/purelib/yamlscript/__init__.py,sha256=_MI5fKKzBzQEOeW2c3noIYjOtwx1tAGlMLKOelDP3v8,4769
2
+ yamlscript-0.2.22.data/purelib/yamlscript/libys/libys.dll,sha256=MvEpY_8C9VBZuhles6PRiFy5ODUhaNRJwHqq7MQCw-c,60092416
3
+ yamlscript-0.2.22.dist-info/licenses/License,sha256=p8zkBa2O7oxOXPqo0vhuPEheBvp60GSYQvK9TwCf65w,1072
4
+ yamlscript-0.2.22.dist-info/METADATA,sha256=OCoFKYWupEqaiAfeYNU3cemsAGtpj13h15LKUw6PHDc,1056
5
+ yamlscript-0.2.22.dist-info/WHEEL,sha256=GjDPPQwEcripVP6P2r3RxLa-h5Lb9ifGB7FYYtbLDT0,98
6
+ yamlscript-0.2.22.dist-info/top_level.txt,sha256=U1bWDl8Bms9lndIZd3ITPWc-iAHZVErB56tY8C6otwg,11
7
+ yamlscript-0.2.22.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (82.0.1)
3
+ Root-Is-Purelib: false
4
+ Tag: py3-none-win_amd64
5
+
@@ -0,0 +1,19 @@
1
+ Copyright 2021 Ingy döt Net
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
4
+ this software and associated documentation files (the "Software"), to deal in
5
+ the Software without restriction, including without limitation the rights to
6
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
7
+ of the Software, and to permit persons to whom the Software is furnished to do
8
+ so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in all
11
+ copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
+ SOFTWARE.
@@ -0,0 +1 @@
1
+ yamlscript