xcl-lang 0.5.3__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.
Files changed (72) hide show
  1. xcl_lang-0.5.3/.gitignore +12 -0
  2. xcl_lang-0.5.3/LICENSE +202 -0
  3. xcl_lang-0.5.3/Makefile +54 -0
  4. xcl_lang-0.5.3/PARITY.md +76 -0
  5. xcl_lang-0.5.3/PKG-INFO +313 -0
  6. xcl_lang-0.5.3/README.md +282 -0
  7. xcl_lang-0.5.3/hatch_build.py +34 -0
  8. xcl_lang-0.5.3/pyproject.toml +74 -0
  9. xcl_lang-0.5.3/tests/conftest.py +45 -0
  10. xcl_lang-0.5.3/tests/engines.py +56 -0
  11. xcl_lang-0.5.3/tests/fake_engine.py +151 -0
  12. xcl_lang-0.5.3/tests/fakes.py +52 -0
  13. xcl_lang-0.5.3/tests/integration/configs/docker/main.xcl +15 -0
  14. xcl_lang-0.5.3/tests/integration/conftest.py +58 -0
  15. xcl_lang-0.5.3/tests/integration/docker_helpers.py +230 -0
  16. xcl_lang-0.5.3/tests/integration/sync_entities.py +122 -0
  17. xcl_lang-0.5.3/tests/integration/test_aio.py +573 -0
  18. xcl_lang-0.5.3/tests/integration/test_docker_plugin.py +154 -0
  19. xcl_lang-0.5.3/tests/integration/test_engine_process.py +753 -0
  20. xcl_lang-0.5.3/tests/integration/test_functions.py +338 -0
  21. xcl_lang-0.5.3/tests/integration/test_github_tamper.py +271 -0
  22. xcl_lang-0.5.3/tests/integration/test_load.py +79 -0
  23. xcl_lang-0.5.3/tests/integration/test_sync.py +755 -0
  24. xcl_lang-0.5.3/tests/keys/jumppad-labs.asc +20 -0
  25. xcl_lang-0.5.3/tests/parity/__init__.py +1 -0
  26. xcl_lang-0.5.3/tests/parity/conftest.py +99 -0
  27. xcl_lang-0.5.3/tests/parity/run_python.py +396 -0
  28. xcl_lang-0.5.3/tests/parity/test_parity.py +95 -0
  29. xcl_lang-0.5.3/tests/parity/test_types.py +50 -0
  30. xcl_lang-0.5.3/tests/parity/types.py +125 -0
  31. xcl_lang-0.5.3/tests/plugins.toml +7 -0
  32. xcl_lang-0.5.3/tests/unit/test_client.py +113 -0
  33. xcl_lang-0.5.3/tests/unit/test_config.py +42 -0
  34. xcl_lang-0.5.3/tests/unit/test_docstrings.py +63 -0
  35. xcl_lang-0.5.3/tests/unit/test_engine_errors.py +60 -0
  36. xcl_lang-0.5.3/tests/unit/test_engines_helper.py +48 -0
  37. xcl_lang-0.5.3/tests/unit/test_entity.py +127 -0
  38. xcl_lang-0.5.3/tests/unit/test_errors.py +182 -0
  39. xcl_lang-0.5.3/tests/unit/test_fork.py +66 -0
  40. xcl_lang-0.5.3/tests/unit/test_hydrate.py +207 -0
  41. xcl_lang-0.5.3/tests/unit/test_import.py +33 -0
  42. xcl_lang-0.5.3/tests/unit/test_schema.py +331 -0
  43. xcl_lang-0.5.3/tests/unit/test_signature.py +83 -0
  44. xcl_lang-0.5.3/tests/unit/test_subprocess_transport.py +444 -0
  45. xcl_lang-0.5.3/tests/unit/test_transport.py +99 -0
  46. xcl_lang-0.5.3/tests/unit/test_transport_selection.py +122 -0
  47. xcl_lang-0.5.3/tests/unit/test_types.py +78 -0
  48. xcl_lang-0.5.3/xcl/__init__.py +122 -0
  49. xcl_lang-0.5.3/xcl/_client.py +114 -0
  50. xcl_lang-0.5.3/xcl/_core/__init__.py +7 -0
  51. xcl_lang-0.5.3/xcl/_core/core_pb2.py +125 -0
  52. xcl_lang-0.5.3/xcl/_core/core_pb2.pyi +375 -0
  53. xcl_lang-0.5.3/xcl/_core/transport_pb2.py +39 -0
  54. xcl_lang-0.5.3/xcl/_core/transport_pb2.pyi +27 -0
  55. xcl_lang-0.5.3/xcl/_entity.py +181 -0
  56. xcl_lang-0.5.3/xcl/_errors.py +440 -0
  57. xcl_lang-0.5.3/xcl/_functions.py +41 -0
  58. xcl_lang-0.5.3/xcl/_poll.py +210 -0
  59. xcl_lang-0.5.3/xcl/_schema.py +506 -0
  60. xcl_lang-0.5.3/xcl/_transport/__init__.py +33 -0
  61. xcl_lang-0.5.3/xcl/_transport/inprocess.py +263 -0
  62. xcl_lang-0.5.3/xcl/_transport/select.py +68 -0
  63. xcl_lang-0.5.3/xcl/_transport/subprocess.py +534 -0
  64. xcl_lang-0.5.3/xcl/_types.py +135 -0
  65. xcl_lang-0.5.3/xcl/_version.py +8 -0
  66. xcl_lang-0.5.3/xcl/aio.py +312 -0
  67. xcl_lang-0.5.3/xcl/config.py +235 -0
  68. xcl_lang-0.5.3/xcl/diff.py +122 -0
  69. xcl_lang-0.5.3/xcl/events.py +77 -0
  70. xcl_lang-0.5.3/xcl/mask.py +60 -0
  71. xcl_lang-0.5.3/xcl/registry.py +152 -0
  72. xcl_lang-0.5.3/xcl-ref.txt +1 -0
@@ -0,0 +1,12 @@
1
+ # virtual environments and build output are never committed
2
+ .venv/
3
+ build/
4
+ dist/
5
+ *.egg-info/
6
+ __pycache__/
7
+ .pytest_cache/
8
+
9
+ # the engine built for the local platform by make engine and make libxcl,
10
+ # and release archives downloaded for wheels
11
+ xcl/_bin/
12
+ xcl/_lib/
xcl_lang-0.5.3/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
@@ -0,0 +1,54 @@
1
+ # Development targets. The package is built against a local checkout of xcl,
2
+ # XCL_SRC, from which the CoreService messages are generated and the engine
3
+ # program is built into xcl/_bin. A release uses the signed engine archives
4
+ # from the xcl release instead, see .github/workflows/release.yml.
5
+ XCL_SRC ?= ../xcl
6
+ PYTHON ?= python3
7
+
8
+ # VERSION is the package version, from xcl/_version.py; a development
9
+ # engine is stamped with it so the package's version check passes
10
+ VERSION := $(shell $(PYTHON) -c "import re; print(re.search(r'__version__\s*=\s*\"([^\"]+)\"', open('xcl/_version.py').read()).group(1))")
11
+
12
+ # protos generates the CoreService message classes and the frame messages of
13
+ # the engine program's transport from the xcl checkout's proto/ into
14
+ # xcl/_core. protoc writes them under xcl/core/v1, following the proto
15
+ # package, which would shadow this package's own name, so the files are
16
+ # moved; they import nothing but the protobuf runtime
17
+ protos:
18
+ rm -rf build/protos && mkdir -p build/protos xcl/_core
19
+ protoc -I "$(XCL_SRC)/proto" --python_out=build/protos --pyi_out=build/protos "$(XCL_SRC)/proto/xcl/core/v1/core.proto" "$(XCL_SRC)/proto/xcl/core/v1/transport.proto"
20
+ cp build/protos/xcl/core/v1/core_pb2.py build/protos/xcl/core/v1/core_pb2.pyi build/protos/xcl/core/v1/transport_pb2.py build/protos/xcl/core/v1/transport_pb2.pyi xcl/_core/
21
+ rm -rf build/protos
22
+
23
+ # engine builds the engine program, xcl-core, from the xcl checkout into
24
+ # xcl/_bin for the local platform, stamped with this package's version. It
25
+ # needs Go and no C compiler; it is the engine the package runs by default
26
+ EXE := $(shell $(PYTHON) -c "import sys; print('.exe' if sys.platform == 'win32' else '')")
27
+ engine:
28
+ mkdir -p xcl/_bin
29
+ $(MAKE) -C "$(XCL_SRC)" xcl-core XCL_CORE_VERSION=v$(VERSION) XCL_CORE_OUT="$(CURDIR)/xcl/_bin/xcl-core$(EXE)"
30
+
31
+ # libxcl builds the engine as a shared library from the xcl checkout into
32
+ # xcl/_lib for the local platform, stamped with this package's version. It
33
+ # needs Go and a C compiler, and XCL_TRANSPORT=inprocess selects it
34
+ LIBXCL_EXT := $(shell $(PYTHON) -c "import sys; print('dll' if sys.platform == 'win32' else 'dylib' if sys.platform == 'darwin' else 'so')")
35
+ libxcl:
36
+ mkdir -p xcl/_lib
37
+ $(MAKE) -C "$(XCL_SRC)" libxcl LIBXCL_VERSION=v$(VERSION) LIBXCL_OUT="$(CURDIR)/xcl/_lib/libxcl.$(LIBXCL_EXT)"
38
+
39
+ # plugins builds the fixture plugins the integration tests use into
40
+ # build/plugins
41
+ plugins:
42
+ mkdir -p build/plugins
43
+ cd "$(XCL_SRC)/bindings/libxcl" && go build -o "$(CURDIR)/build/plugins/xcl-plugin-slow" ./testdata/plugins/slow && go build -o "$(CURDIR)/build/plugins/xcl-plugin-recording" ./testdata/plugins/recording && go build -o "$(CURDIR)/build/plugins/parity" ./cmd/parity
44
+
45
+ # test runs the unit tests, which need no engine, and the integration tests,
46
+ # which need make engine (or make libxcl with XCL_TRANSPORT=inprocess) and
47
+ # make plugins to have run
48
+ test:
49
+ $(PYTHON) -m pytest
50
+
51
+ test-unit:
52
+ $(PYTHON) -m pytest tests/unit
53
+
54
+ .PHONY: protos engine libxcl plugins test test-unit
@@ -0,0 +1,76 @@
1
+ # Parity with the Go API
2
+
3
+ Every operation and lookup of the Go API has an equivalent in the synchronous
4
+ API, `xcl.Config`, and the asyncio API, `xcl.aio.Config`. This list is
5
+ checked against the Go API of the xcl release the package bundles at each
6
+ release; the `tests/parity` suite checks that the two give the same results
7
+ on a shared set of fixtures.
8
+
9
+ ## Operations
10
+
11
+ | Go (`*xcl.Config`) | `xcl.Config` | `xcl.aio.Config` |
12
+ |---|---|---|
13
+ | `Validate(paths...)` / `ValidateContext(ctx, paths...)` | `validate(*paths)` | `await validate(*paths)` |
14
+ | `Apply(paths...)` / `ApplyContext(ctx, paths...)` | `apply(*paths)` | `await apply(*paths)` |
15
+ | `Diff(paths, options...)` / `DiffContext(ctx, paths, options...)` | `diff(*paths, reveal_sensitive=False)` | `await diff(*paths, reveal_sensitive=False)` |
16
+ | `Destroy()` / `DestroyContext(ctx)` | `destroy()` | `await destroy()` |
17
+ | `Load()` / `LoadContext(ctx)` | `load()` | `await load()` |
18
+
19
+ The context forms are how the asyncio API cancels: cancelling the task that
20
+ awaits an operation cancels the engine's context. The synchronous API
21
+ cancels on `KeyboardInterrupt`.
22
+
23
+ ## Lookups
24
+
25
+ | Go | `xcl.Config` | `xcl.aio.Config` |
26
+ |---|---|---|
27
+ | `Entities()` | `entities()` | `await entities()` |
28
+ | `EntityCount()` | `entity_count()` | `await entity_count()` |
29
+ | `FindResource(address)` / `Find[T](c, address)` | `find(cls, address)` | `await find(cls, address)` |
30
+ | `FindByType[T](c, path...)` / `FindEntitiesByType(path...)` | `find_by_type(cls, *path)` | `await find_by_type(cls, *path)` |
31
+ | `FindOne[T](c, path...)` / `FindOneEntity(path...)` | `find_one(cls, *path)` | `await find_one(cls, *path)` |
32
+ | `All[T](c)` | `all(cls)` | `await all(cls)` |
33
+ | `Outputs()` | `outputs()` | `await outputs()` |
34
+ | `EncodeSavedEntity(data, options...)` | `encode_saved_entity(data, highlight=False)` | `await encode_saved_entity(data, highlight=False)` |
35
+
36
+ Passing `None` as the class returns the registered class for the entity's
37
+ type, or `xcl.Entity` for a type no class was registered for, which is how a
38
+ Go plugin's entities are read.
39
+
40
+ ## Configuration options
41
+
42
+ | Go (`xcl.NewConfig` option) | `xcl.Config(...)` and `xcl.aio.Config(...)` |
43
+ |---|---|
44
+ | `WithRegistry(r)` | `registries=[...]` (`xcl.LocalRegistry`, `xcl.GitHubRegistry`) |
45
+ | `WithStatePath(dir)` | `state_path=dir` |
46
+ | `WithStateStore(store)` | `state_store=obj` |
47
+ | `WithStateMask(m)` | `state_mask=xcl.mask.aes256gcm(key)` |
48
+ | `WithVariables(vars)` | `variables={...}` |
49
+ | `WithEventHandler(h)` | `on_event=callable` |
50
+ | `WithEventData(level)` | `event_data="none" \| "raw" \| "processed"` |
51
+ | `WithEventBufferSize(n)` | `event_buffer_size=n` |
52
+ | `WithEventMask(m)` | `event_mask=xcl.mask.hmac_sha256(key)` |
53
+ | `WithNoEventMask()` | `no_event_mask=True` |
54
+
55
+ ## Registries
56
+
57
+ | Go | Python |
58
+ |---|---|
59
+ | `registry.NewLocal(registry.PluginPattern(p))` | `xcl.LocalRegistry(plugin_pattern=p)` |
60
+ | `local.RegisterType(prototype, name...)` | `local.register_type(cls)` with `@xcl.entity(type, subtype)` |
61
+ | `local.RegisterFunction(name, fn)` | `local.register_function(fn, name=None)` |
62
+ | `local.RegisterExternalPlugin(path)` | `local.register_external_plugin(path)` |
63
+ | `local.RegisterPluginDirectory(dir)` | `local.register_plugin_directory(dir)` |
64
+ | `registry.NewGitHub(options...)` | `xcl.GitHubRegistry(cache_dir=, trusted_keys=, token=, api_url=)` |
65
+ | `github.RegisterPlugin(repo, version)` | `github.register_plugin(repo, version)` |
66
+ | `github.RegisterType(prototype, name...)` | `github.register_type(cls)` |
67
+
68
+ ## Not applicable
69
+
70
+ | Go | Why there is no Python form |
71
+ |---|---|
72
+ | `Decode(entity, &target)` | A lookup already returns an instance of the registered class; there is no separate struct to fill. |
73
+ | `As[T](entity)` | A lookup takes the class to return; `find(cls, address)` is the conversion. |
74
+ | `EncodeEntity(value, options...)` | It renders a Go value; Python renders a saved record with `encode_saved_entity`. |
75
+ | `GetResources()` / `ResourceCount()` | Deprecated in Go in favour of `Entities()` / `EntityCount()`. |
76
+ | `Event.Entity()` through a Go type | `xcl.Event.entity()` hydrates the registered class or `xcl.Entity`. |
@@ -0,0 +1,313 @@
1
+ Metadata-Version: 2.5
2
+ Name: xcl-lang
3
+ Version: 0.5.3
4
+ Summary: XCL, the declarative configuration language, for Python: the xcl engine run as a bundled subprocess on every platform, imported as xcl
5
+ Project-URL: Homepage, https://xcl.dev
6
+ Project-URL: Source, https://github.com/jumppad-labs/xcl-python
7
+ Project-URL: Engine, https://github.com/jumppad-labs/xcl
8
+ Author: Jumppad Labs
9
+ License-Expression: Apache-2.0
10
+ License-File: LICENSE
11
+ Keywords: configuration,hcl,infrastructure,xcl
12
+ Classifier: Development Status :: 3 - Alpha
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: Operating System :: MacOS
15
+ Classifier: Operating System :: Microsoft :: Windows
16
+ Classifier: Operating System :: POSIX :: Linux
17
+ Classifier: Programming Language :: Python :: 3
18
+ Classifier: Programming Language :: Python :: 3 :: Only
19
+ Classifier: Programming Language :: Python :: 3.10
20
+ Classifier: Programming Language :: Python :: 3.11
21
+ Classifier: Programming Language :: Python :: 3.12
22
+ Classifier: Programming Language :: Python :: 3.13
23
+ Classifier: Topic :: Software Development :: Libraries
24
+ Requires-Python: >=3.10
25
+ Requires-Dist: protobuf>=5.26
26
+ Provides-Extra: inprocess
27
+ Requires-Dist: cffi>=1.16; extra == 'inprocess'
28
+ Provides-Extra: test
29
+ Requires-Dist: pytest>=8; extra == 'test'
30
+ Description-Content-Type: text/markdown
31
+
32
+ # xcl for Python
33
+
34
+ XCL, the declarative configuration language, for Python. The package drives
35
+ the same engine Go programs use, bundled in the wheel as a small program that
36
+ the package runs as a subprocess, the same way on every platform, Alpine
37
+ included, with the same API and the same results everywhere. A Python program
38
+ validates, diffs, applies, loads and destroys configuration exactly as a Go
39
+ program does, uses the same Go plugins, and adds its own Python functions to
40
+ configuration.
41
+
42
+ - Engine and Go library: [github.com/jumppad-labs/xcl](https://github.com/jumppad-labs/xcl)
43
+ - Language and documentation: [xcl.dev](https://xcl.dev)
44
+
45
+ ## Install
46
+
47
+ ```
48
+ pip install xcl-lang
49
+ ```
50
+
51
+ The distribution is `xcl-lang` on PyPI and is imported as `xcl`. No Go
52
+ toolchain and no C compiler are needed: each wheel bundles the engine
53
+ program, `xcl-core`, for its platform, and contains no compiled extension,
54
+ so one wheel per platform serves every CPython 3.10 and later. Wheels are
55
+ published for
56
+
57
+ - Linux x86-64 and arm64 on glibc 2.28 or later (`manylinux_2_28`);
58
+ - Linux x86-64 and arm64 on musl (`musllinux_1_2`), Alpine included;
59
+ - macOS 11 or later, x86-64 and arm64;
60
+ - Windows x86-64 and arm64.
61
+
62
+ The engine runs as a subprocess on every platform. `import xcl` starts
63
+ nothing: the engine starts the first time a configuration is used, is shared
64
+ by every configuration in the process, and stops on its own when the last
65
+ configuration is closed or the interpreter exits. It never outlives its
66
+ host, even one that is killed, and its diagnostics go to your standard
67
+ error. The package version is the xcl release it bundles, and it refuses to
68
+ run against any other engine.
69
+
70
+ ## Getting started
71
+
72
+ A Python program describes its entity types as dataclasses, registers them
73
+ and any plugins on a registry, and creates a configuration. This program
74
+ uses the Docker example plugin, published as a signed GitHub release, to
75
+ create a network and a container:
76
+
77
+ ```python
78
+ from dataclasses import dataclass
79
+
80
+ import xcl
81
+
82
+ # the jumppad-labs release key, from https://xcl.dev/keys/jumppad-labs-releases.asc
83
+ RELEASE_KEY = open("jumppad-labs-releases.asc").read()
84
+
85
+
86
+ @xcl.entity("settings")
87
+ @dataclass
88
+ class Settings(xcl.Resource):
89
+ image: str
90
+ replicas: int = 1
91
+
92
+
93
+ github = xcl.GitHubRegistry(trusted_keys=[RELEASE_KEY])
94
+ github.register_plugin("jumppad-labs/xcl-plugin-docker", "v0.2.0")
95
+
96
+ local = xcl.LocalRegistry()
97
+ local.register_type(Settings)
98
+
99
+ with xcl.Config(registries=[local, github], state_path=".xcl") as cfg:
100
+ cfg.apply("./infra")
101
+
102
+ settings = cfg.find(Settings, "settings.web")
103
+ print(settings.image, settings.replicas)
104
+
105
+ network = cfg.find(None, "docker.network.main")
106
+ print(network.address, network.subnet, network.docker_id)
107
+
108
+ cfg.destroy()
109
+ ```
110
+
111
+ with the configuration in `infra/main.xcl`:
112
+
113
+ ```hcl
114
+ settings "web" {
115
+ image = "nginx:1.27-alpine"
116
+ }
117
+
118
+ docker "network" "main" {
119
+ subnet = "10.73.0.0/24"
120
+ }
121
+
122
+ docker "container" "web" {
123
+ image = settings.web.image
124
+
125
+ network {
126
+ name = docker.network.main.meta.name
127
+ }
128
+ }
129
+ ```
130
+
131
+ `apply` runs to completion before returning; other Python threads keep
132
+ running while it works. `find` returns an instance of the registered class
133
+ for a type the program registered, and an `xcl.Entity`, a read-only mapping
134
+ with `.meta` and `.address`, for a plugin's type: `network.subnet` and
135
+ `network["subnet"]` both read an attribute.
136
+
137
+ ### Entity types
138
+
139
+ A dataclass decorated with `@xcl.entity(type)`, or `@xcl.entity(type, subtype)`
140
+ for a type written `database "postgres" "main" {}`, describes a block type
141
+ through its annotations:
142
+
143
+ ```python
144
+ @dataclass
145
+ class Volume:
146
+ source: str
147
+ name: str = xcl.field(label=True, default="") # the block's name, volume "data" {}
148
+
149
+
150
+ @dataclass
151
+ class Listener:
152
+ port: int
153
+ name: str = xcl.field(label=True, default="")
154
+
155
+
156
+ @xcl.entity("app")
157
+ @dataclass
158
+ class App(xcl.Resource):
159
+ image: str # required
160
+ replicas: int = 2 # optional, with a default
161
+ region: str | None = None # optional
162
+ password: xcl.Sensitive[str] | None = None # sensitive: masked in events and state
163
+ endpoint: xcl.Computed[str] = None # set by the provider, never in configuration
164
+ health: Health | None = None # a nested block
165
+ volume: list[Volume] = xcl.field(default_factory=list) # a list of blocks, in order
166
+ listener: dict[str, Listener] = xcl.field(default_factory=dict) # named blocks, keyed by name
167
+ ```
168
+
169
+ Configuration is checked against the class as it is against a Go type: a
170
+ missing required field, a computed field set in configuration or an unknown
171
+ attribute is reported with its file and line. A looked-up `Sensitive` value
172
+ prints as `(sensitive)` and `reveal()` returns `None`; real values never leave
173
+ the engine through a lookup.
174
+
175
+ ### Functions
176
+
177
+ A Python function registered on a local registry is callable from
178
+ configuration by name. Its annotations give its signature: `str`, `bool`,
179
+ `int` and `float` parameters and result, and lists and dicts of those.
180
+
181
+ ```python
182
+ def slugify(title: str) -> str:
183
+ return title.lower().replace(" ", "-")
184
+
185
+ local.register_function(slugify)
186
+ ```
187
+
188
+ ```hcl
189
+ app "web" {
190
+ name = slugify("My App")
191
+ }
192
+ ```
193
+
194
+ The result is filled in exactly like a built-in function's, and a result
195
+ computed from a sensitive argument is held as sensitive. A name a builtin or
196
+ another function already uses raises `xcl.FunctionNameClashError` when the
197
+ configuration is created.
198
+
199
+ ### Variables, state and events
200
+
201
+ ```python
202
+ cfg = xcl.Config(
203
+ registries=[local],
204
+ variables={"region": "us"}, # variable.region in configuration
205
+ state_path="./.xcl", # or state_store=MyStore()
206
+ state_mask=xcl.mask.aes256gcm(key), # encrypt sensitive values in state
207
+ on_event=lambda e: print(e.operation, e.phase, e.resource_id),
208
+ event_data="processed", # carry the entity on events, masked
209
+ )
210
+ ```
211
+
212
+ A custom state store is any object with `load() -> list[bytes]`,
213
+ `save(records: list[bytes])`, `exists() -> bool` and `clear()`; it receives
214
+ each entity's JSON record. The engine's events arrive at `on_event` as
215
+ `xcl.Event`, with the same data levels and masking a Go program has;
216
+ `event.entity()` hydrates the entity an event carries.
217
+
218
+ Lookups: `entities()`, `entity_count()`, `find(cls, address)`,
219
+ `find_by_type(cls, *path)`, `find_one(cls, *path)`, `all(cls)`,
220
+ `outputs()` and `encode_saved_entity(record)`. Pass `None` as the class to
221
+ get the registered class, or an `xcl.Entity` for an unregistered type.
222
+
223
+ ## Asyncio
224
+
225
+ `xcl.aio.Config` offers every operation and lookup as an awaitable that
226
+ never blocks the event loop. Registered functions, the event handler and the
227
+ state store's methods may be `async def`:
228
+
229
+ ```python
230
+ import asyncio
231
+ import xcl.aio
232
+
233
+
234
+ async def slugify(title: str) -> str:
235
+ return title.lower().replace(" ", "-")
236
+
237
+
238
+ async def main():
239
+ local = xcl.LocalRegistry()
240
+ local.register_type(App)
241
+ local.register_function(slugify)
242
+
243
+ async with xcl.aio.Config(registries=[local], state_path=".xcl", on_event=on_event) as cfg:
244
+ await cfg.apply("./infra")
245
+ web = await cfg.find(App, "app.web")
246
+ print(web.name)
247
+
248
+
249
+ async def on_event(event):
250
+ print(event.operation, event.phase, event.resource_id)
251
+
252
+
253
+ asyncio.run(main())
254
+ ```
255
+
256
+ The engine is polled from a thread, and each task it posts runs as an
257
+ asyncio task, so a web service keeps answering requests during a long
258
+ apply. Cancelling the task that awaits an operation cancels the engine's
259
+ work: no further provider call starts, the progress made is saved, and
260
+ `asyncio.CancelledError` is raised once the engine has stopped.
261
+
262
+ ## Errors
263
+
264
+ Every failure is an exception under `xcl.Error`, one class per kind of
265
+ error, carrying `message`, `details` and `causes`: `xcl.NotFoundError`,
266
+ `xcl.NotUniqueError`, `xcl.ConfigError` (whose `problems` list each problem
267
+ with its file, line and column), `xcl.PluginVerificationError`,
268
+ `xcl.FunctionNameClashError`, `xcl.CancelledError` and so on. A plugin
269
+ release whose signature does not verify against the trusted keys is refused.
270
+
271
+ Two errors concern the engine itself. `xcl.EngineNotFoundError` is raised on
272
+ first use when the installed package does not hold its engine, and names
273
+ where the engine program and the shared library were expected.
274
+ `xcl.EngineExitedError` is raised by every call waiting on the engine if it
275
+ exits unexpectedly, carrying its exit status, or the signal that ended it, in
276
+ `details` and `returncode`. Your program carries on: the next configuration
277
+ starts a new engine, and a configuration created before the exit raises
278
+ `xcl.EngineExitedError` again.
279
+
280
+ ## Forking
281
+
282
+ A forked child creates its own configuration. `import xcl` starts nothing,
283
+ so forking before using the package is unaffected, and a child forked after
284
+ the parent used it simply creates a new `xcl.Config`, which starts the
285
+ child's own engine. Using a configuration created before the fork raises
286
+ `xcl.ForkedProcessError` in the child, since its engine belongs to the
287
+ parent. With that one rule, gunicorn's `preload_app`, celery's prefork pool
288
+ and `multiprocessing` with the `fork` start method all work.
289
+
290
+ ## Development
291
+
292
+ The package is built against a checkout of xcl, `XCL_SRC` (by default
293
+ `../xcl`): `make protos` generates the message classes from its `proto/` with
294
+ protoc, `make engine` builds the engine program into `xcl/_bin` with Go and no
295
+ C compiler, `make plugins` builds the fixture plugins the integration tests
296
+ use, and `make test` runs the suite.
297
+
298
+ The engine can also be built as a shared library and loaded into the Python
299
+ process instead, which keeps the in-process route tested: `make libxcl`
300
+ builds it into `xcl/_lib` with Go and a C compiler, `pip install -e
301
+ '.[test,inprocess]'` adds cffi to load it (the standard library's ctypes is
302
+ used without it), and `XCL_TRANSPORT=inprocess` selects it. Without the
303
+ variable the engine program runs even when the library is present, and a
304
+ missing engine is reported, never replaced by the other form. With the
305
+ in-process route the forking rule is stricter, since the engine is a Go
306
+ runtime in the process: use the `spawn` start method, or create the
307
+ configuration after the fork, in gunicorn's `post_fork` hook or celery's
308
+ `worker_process_init` signal.
309
+ `PARITY.md` lists every Go operation and lookup with its Python equivalent. The distribution is published as `xcl-lang`, since the name `xcl` on PyPI belongs to another project; the import name is `xcl`.
310
+
311
+ ## Licence
312
+
313
+ Apache-2.0, as xcl.