kcl-lib 0.11.0__cp313-cp313t-manylinux_2_17_aarch64.manylinux2014_aarch64.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.

Potentially problematic release.


This version of kcl-lib might be problematic. Click here for more details.

@@ -0,0 +1,720 @@
1
+ Metadata-Version: 2.4
2
+ Name: kcl_lib
3
+ Version: 0.11.0
4
+ Classifier: Programming Language :: Rust
5
+ Classifier: Programming Language :: Python :: Implementation :: CPython
6
+ Classifier: Programming Language :: Python :: Implementation :: PyPy
7
+ Requires-Dist: protobuf >=4.25.3
8
+ Requires-Dist: pdoc ; extra == 'docs'
9
+ Requires-Dist: ruff ; extra == 'lint'
10
+ Requires-Dist: pytest ; extra == 'test'
11
+ Provides-Extra: docs
12
+ Provides-Extra: lint
13
+ Provides-Extra: test
14
+ Summary: KCL Programming Language Python Lib
15
+ License: Apache-2.0
16
+ Requires-Python: >=3.7
17
+ Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
18
+ Project-URL: Documentation, https://kcl-lang.io
19
+ Project-URL: Homepage, https://kcl-lang.io
20
+ Project-URL: Repository, https://github.com/kcl-lang/kcl
21
+
22
+ # KCL Artifact Library for Python
23
+
24
+ ## Installation
25
+
26
+ ```shell
27
+ python3 -m pip install kcl-lib
28
+ ```
29
+
30
+ ## Quick Start
31
+
32
+ ```python
33
+ import kcl_lib.api as api
34
+
35
+ args = api.ExecProgram_Args(k_filename_list=["/path/to/kcl_file.k"])
36
+ api = api.API()
37
+ result = api.exec_program(args)
38
+ print(result.yaml_result)
39
+ ```
40
+
41
+ ## Developing
42
+
43
+ Setup virtualenv:
44
+
45
+ ```shell
46
+ python3 -m venv venv
47
+ ```
48
+
49
+ Activate venv:
50
+
51
+ ```shell
52
+ source venv/bin/activate
53
+ ```
54
+
55
+ Install maturin:
56
+
57
+ ```shell
58
+ cargo install maturin
59
+ ```
60
+
61
+ Build bindings:
62
+
63
+ ```shell
64
+ maturin develop
65
+ ```
66
+
67
+ Test
68
+
69
+ ```shell
70
+ python3 -m pytest
71
+ ```
72
+
73
+ ## API Reference
74
+
75
+ ### exec_program
76
+
77
+ Execute KCL file with arguments and return the JSON/YAML result.
78
+
79
+ <details><summary>Example</summary>
80
+ <p>
81
+
82
+ The content of `schema.k` is
83
+
84
+ ```python
85
+ schema AppConfig:
86
+ replicas: int
87
+
88
+ app: AppConfig {
89
+ replicas: 2
90
+ }
91
+ ```
92
+
93
+ Python Code
94
+
95
+ ```python
96
+ import kcl_lib.api as api
97
+
98
+ args = api.ExecProgram_Args(k_filename_list=["schema.k"])
99
+ api = api.API()
100
+ result = api.exec_program(args)
101
+ assert result.yaml_result == "app:\n replicas: 2"
102
+ ```
103
+
104
+ </p>
105
+ </details>
106
+
107
+ A case with the file not found error
108
+
109
+ <details><summary>Example</summary>
110
+ <p>
111
+
112
+ ```python
113
+ import kcl_lib.api as api
114
+
115
+ try:
116
+ args = api.ExecProgram_Args(k_filename_list=["file_not_found"])
117
+ api = api.API()
118
+ result = api.exec_program(args)
119
+ assert False
120
+ except Exception as err:
121
+ assert "Cannot find the kcl file" in str(err)
122
+ ```
123
+
124
+ </p>
125
+ </details>
126
+
127
+ ### parse_file
128
+
129
+ Parse KCL single file to Module AST JSON string with import dependencies and parse errors.
130
+
131
+ <details><summary>Example</summary>
132
+ <p>
133
+
134
+ The content of `schema.k` is
135
+
136
+ ```python
137
+ schema AppConfig:
138
+ replicas: int
139
+
140
+ app: AppConfig {
141
+ replicas: 2
142
+ }
143
+ ```
144
+
145
+ Python Code
146
+
147
+ ```python
148
+ import kcl_lib.api as api
149
+
150
+ args = api.ParseParseFile_Args(path=TEST_FILE)
151
+ api = api.API()
152
+ result = api.parse_file(args)
153
+ ```
154
+
155
+ </p>
156
+ </details>
157
+
158
+ ### parse_program
159
+
160
+ Parse KCL program with entry files and return the AST JSON string.
161
+
162
+ <details><summary>Example</summary>
163
+ <p>
164
+
165
+ The content of `schema.k` is
166
+
167
+ ```python
168
+ schema AppConfig:
169
+ replicas: int
170
+
171
+ app: AppConfig {
172
+ replicas: 2
173
+ }
174
+ ```
175
+
176
+ Python Code
177
+
178
+ ```python
179
+ import kcl_lib.api as api
180
+
181
+ args = api.ParseProgram_Args(paths=["schema.k"])
182
+ api = api.API()
183
+ result = api.parse_program(args)
184
+ assert len(result.paths) == 1
185
+ assert len(result.errors) == 0
186
+ ```
187
+
188
+ </p>
189
+ </details>
190
+
191
+ ### load_package
192
+
193
+ load_package provides users with the ability to parse KCL program and semantic model information including symbols, types, definitions, etc.
194
+
195
+ <details><summary>Example</summary>
196
+ <p>
197
+
198
+ The content of `schema.k` is
199
+
200
+ ```python
201
+ schema AppConfig:
202
+ replicas: int
203
+
204
+ app: AppConfig {
205
+ replicas: 2
206
+ }
207
+ ```
208
+
209
+ Python Code
210
+
211
+ ```python
212
+ import kcl_lib.api as api
213
+
214
+ args = api.LoadPackage_Args(
215
+ parse_args=api.ParseProgram_Args(paths=["schema.k"]), resolve_ast=True
216
+ )
217
+ api = api.API()
218
+ result = api.load_package(args)
219
+ assert list(result.symbols.values())[0].ty.schema_name == "AppConfig"
220
+ ```
221
+
222
+ </p>
223
+ </details>
224
+
225
+ ### list_variables
226
+
227
+ list_variables provides users with the ability to parse KCL program and get all variables by specs.
228
+
229
+ <details><summary>Example</summary>
230
+ <p>
231
+
232
+ The content of `schema.k` is
233
+
234
+ ```python
235
+ schema AppConfig:
236
+ replicas: int
237
+
238
+ app: AppConfig {
239
+ replicas: 2
240
+ }
241
+ ```
242
+
243
+ Python Code
244
+
245
+ ```python
246
+ import kcl_lib.api as api
247
+
248
+ args = api.ListVariables_Args(files=[TEST_FILE])
249
+ api = api.API()
250
+ result = api.list_variables(args)
251
+ ```
252
+
253
+ </p>
254
+ </details>
255
+
256
+ ### list_options
257
+
258
+ list_options provides users with the ability to parse KCL program and get all option information.
259
+
260
+ <details><summary>Example</summary>
261
+ <p>
262
+
263
+ The content of `options.k` is
264
+
265
+ ```python
266
+ a = option("key1")
267
+ b = option("key2", required=True)
268
+ c = {
269
+ metadata.key = option("metadata-key")
270
+ }
271
+ ```
272
+
273
+ Python Code
274
+
275
+ ```python
276
+ import kcl_lib.api as api
277
+
278
+ args = api.ParseProgram_Args(paths=["options.k"])
279
+ api = api.API()
280
+ result = api.list_options(args)
281
+ assert len(result.options) == 3
282
+ assert result.options[0].name == "key1"
283
+ assert result.options[1].name == "key2"
284
+ assert result.options[2].name == "metadata-key"
285
+ ```
286
+
287
+ </p>
288
+ </details>
289
+
290
+ ### get_schema_type_mapping
291
+
292
+ Get schema type mapping defined in the program.
293
+
294
+ <details><summary>Example</summary>
295
+ <p>
296
+
297
+ The content of `schema.k` is
298
+
299
+ ```python
300
+ schema AppConfig:
301
+ replicas: int
302
+
303
+ app: AppConfig {
304
+ replicas: 2
305
+ }
306
+ ```
307
+
308
+ Python Code
309
+
310
+ ```python
311
+ import kcl_lib.api as api
312
+
313
+ exec_args = api.ExecProgram_Args(k_filename_list=["schema.k"])
314
+ args = api.GetSchemaTypeMapping_Args(exec_args=exec_args)
315
+ api = api.API()
316
+ result = api.get_schema_type_mapping(args)
317
+ assert result.schema_type_mapping["app"].properties["replicas"].type == "int"
318
+ ```
319
+
320
+ </p>
321
+ </details>
322
+
323
+ ### override_file
324
+
325
+ Override KCL file with arguments. See [https://www.kcl-lang.io/docs/user_docs/guides/automation](https://www.kcl-lang.io/docs/user_docs/guides/automation) for more override spec guide.
326
+
327
+ <details><summary>Example</summary>
328
+ <p>
329
+
330
+ The content of `main.k` is
331
+
332
+ ```python
333
+ a = 1
334
+ b = {
335
+ "a": 1
336
+ "b": 2
337
+ }
338
+ ```
339
+
340
+ Python Code
341
+
342
+ ```python
343
+ import kcl_lib.api as api
344
+ import pathlib
345
+
346
+ test_file = "main.k"
347
+ args = api.OverrideFile_Args(
348
+ file=test_file,
349
+ specs=["b.a=2"],
350
+ )
351
+ api = api.API()
352
+ result = api.override_file(args)
353
+ assert len(result.parse_errors) == 0
354
+ assert result.result == True
355
+ assert pathlib.Path(test_file).read_text() == """\
356
+ a = 1
357
+ b = {
358
+ "a": 2
359
+ "b": 2
360
+ }
361
+ """
362
+ ```
363
+
364
+ </p>
365
+ </details>
366
+
367
+ ### format_code
368
+
369
+ Format the code source.
370
+
371
+ <details><summary>Example</summary>
372
+ <p>
373
+
374
+ Python Code
375
+
376
+ ```python
377
+ import kcl_lib.api as api
378
+
379
+ source_code = """\
380
+ schema Person:
381
+ name: str
382
+ age: int
383
+
384
+ check:
385
+ 0 < age < 120
386
+ """
387
+ args = api.FormatCode_Args(source=source_code)
388
+ api_instance = api.API()
389
+ result = api_instance.format_code(args)
390
+ assert (
391
+ result.formatted.decode()
392
+ == """\
393
+ schema Person:
394
+ name: str
395
+ age: int
396
+
397
+ check:
398
+ 0 < age < 120
399
+
400
+ """
401
+ )
402
+ ```
403
+
404
+ </p>
405
+ </details>
406
+
407
+ ### format_path
408
+
409
+ Format KCL file or directory path contains KCL files and returns the changed file paths.
410
+
411
+ <details><summary>Example</summary>
412
+ <p>
413
+
414
+ The content of `format_path.k` is
415
+
416
+ ```python
417
+ schema Person:
418
+ name: str
419
+ age: int
420
+
421
+ check:
422
+ 0 < age < 120
423
+ ```
424
+
425
+ Python Code
426
+
427
+ ```python
428
+ import kcl_lib.api as api
429
+
430
+ args = api.FormatPath_Args(path="format_path.k")
431
+ api_instance = api.API()
432
+ result = api_instance.format_path(args)
433
+ print(result)
434
+ ```
435
+
436
+ </p>
437
+ </details>
438
+
439
+ ### lint_path
440
+
441
+ Lint files and return error messages including errors and warnings.
442
+
443
+ <details><summary>Example</summary>
444
+ <p>
445
+
446
+ The content of `lint_path.k` is
447
+
448
+ ```python
449
+ import math
450
+
451
+ a = 1
452
+ ```
453
+
454
+ Python Code
455
+
456
+ ```python
457
+ import kcl_lib.api as api
458
+
459
+ args = api.LintPath_Args(paths=["lint_path.k"])
460
+ api_instance = api.API()
461
+ result = api_instance.lint_path(args)
462
+ ```
463
+
464
+ </p>
465
+ </details>
466
+
467
+ ### validate_code
468
+
469
+ Validate code using schema and JSON/YAML data strings.
470
+
471
+ <details><summary>Example</summary>
472
+ <p>
473
+
474
+ Python Code
475
+
476
+ ```python
477
+ import kcl_lib.api as api
478
+
479
+ code = """\
480
+ schema Person:
481
+ name: str
482
+ age: int
483
+
484
+ check:
485
+ 0 < age < 120
486
+ """
487
+ data = '{"name": "Alice", "age": 10}'
488
+ args = api.ValidateCode_Args(code=code, data=data, format="json")
489
+ api_instance = api.API()
490
+ result = api_instance.validate_code(args)
491
+ assert result.success == True
492
+ assert result.err_message == ""
493
+ ```
494
+
495
+ </p>
496
+ </details>
497
+
498
+ ### rename
499
+
500
+ Rename all the occurrences of the target symbol in the files. This API will rewrite files if they contain symbols to be renamed. Return the file paths that got changed.
501
+
502
+ <details><summary>Example</summary>
503
+ <p>
504
+
505
+ The content of `main.k` is
506
+
507
+ ```python
508
+ a = 1
509
+ b = a
510
+ ```
511
+
512
+ Python Code
513
+
514
+ ```python
515
+ import kcl_lib.api as api
516
+
517
+ args = api.Rename_Args(
518
+ package_root=".",
519
+ symbol_path="a",
520
+ file_paths=["main.k"],
521
+ new_name="a2",
522
+ )
523
+ api_instance = api.API()
524
+ result = api_instance.rename(args)
525
+ ```
526
+
527
+ </p>
528
+ </details>
529
+
530
+ ### rename_code
531
+
532
+ Rename all the occurrences of the target symbol and return the modified code if any code has been changed. This API won't rewrite files but return the changed code.
533
+
534
+ <details><summary>Example</summary>
535
+ <p>
536
+
537
+ Python Code
538
+
539
+ ```python
540
+ import kcl_lib.api as api
541
+
542
+ args = api.RenameCode_Args(
543
+ package_root="/mock/path",
544
+ symbol_path="a",
545
+ source_codes={"/mock/path/main.k": "a = 1\nb = a"},
546
+ new_name="a2",
547
+ )
548
+ api_instance = api.API()
549
+ result = api_instance.rename_code(args)
550
+ assert result.changed_codes["/mock/path/main.k"] == "a2 = 1\nb = a2"
551
+ ```
552
+
553
+ </p>
554
+ </details>
555
+
556
+ ### test
557
+
558
+ Test KCL packages with test arguments.
559
+
560
+ <details><summary>Example</summary>
561
+ <p>
562
+
563
+ Python Code
564
+
565
+ ```python
566
+ import kcl_lib.api as api
567
+ args = api.Test_Args(
568
+ pkg_list=["path/to/testing/pkg/..."],
569
+ )
570
+ api_instance = api.API()
571
+ result = api_instance.test(args)
572
+ ```
573
+
574
+ </p>
575
+ </details>
576
+
577
+ ### load_settings_files
578
+
579
+ Load the setting file config defined in `kcl.yaml`
580
+
581
+ <details><summary>Example</summary>
582
+ <p>
583
+
584
+ The content of `kcl.yaml` is
585
+
586
+ ```yaml
587
+ kcl_cli_configs:
588
+ strict_range_check: true
589
+ kcl_options:
590
+ - key: key
591
+ value: value
592
+ ```
593
+
594
+ Python Code
595
+
596
+ ```python
597
+ import kcl_lib.api as api
598
+
599
+ args = api.LoadSettingsFiles_Args(
600
+ work_dir=".", files=["kcl.yaml"]
601
+ )
602
+ api_instance = api.API()
603
+ result = api_instance.load_settings_files(args)
604
+ assert result.kcl_cli_configs.files == []
605
+ assert result.kcl_cli_configs.strict_range_check == True
606
+ assert (
607
+ result.kcl_options[0].key == "key" and result.kcl_options[0].value == '"value"'
608
+ )
609
+ ```
610
+
611
+ </p>
612
+ </details>
613
+
614
+ ### update_dependencies
615
+
616
+ Download and update dependencies defined in the `kcl.mod` file and return the external package name and location list.
617
+
618
+ <details><summary>Example</summary>
619
+ <p>
620
+
621
+ The content of `module/kcl.mod` is
622
+
623
+ ```yaml
624
+ [package]
625
+ name = "mod_update"
626
+ edition = "0.0.1"
627
+ version = "0.0.1"
628
+
629
+ [dependencies]
630
+ helloworld = { oci = "oci://ghcr.io/kcl-lang/helloworld", tag = "0.1.0" }
631
+ flask = { git = "https://github.com/kcl-lang/flask-demo-kcl-manifests", commit = "ade147b" }
632
+ ```
633
+
634
+ Python Code
635
+
636
+ ```python
637
+ import kcl_lib.api as api
638
+
639
+ args = api.UpdateDependencies_Args(
640
+ manifest_path="module"
641
+ )
642
+ api_instance = api.API()
643
+ result = api_instance.update_dependencies(args)
644
+ pkg_names = [pkg.pkg_name for pkg in result.external_pkgs]
645
+ assert len(pkg_names) == 2
646
+ assert "helloworld" in pkg_names
647
+ assert "flask" in pkg_names
648
+ ```
649
+
650
+ </p>
651
+ </details>
652
+
653
+ Call `exec_program` with external dependencies
654
+
655
+ <details><summary>Example</summary>
656
+ <p>
657
+
658
+ The content of `module/kcl.mod` is
659
+
660
+ ```yaml
661
+ [package]
662
+ name = "mod_update"
663
+ edition = "0.0.1"
664
+ version = "0.0.1"
665
+
666
+ [dependencies]
667
+ helloworld = { oci = "oci://ghcr.io/kcl-lang/helloworld", tag = "0.1.0" }
668
+ flask = { git = "https://github.com/kcl-lang/flask-demo-kcl-manifests", commit = "ade147b" }
669
+ ```
670
+
671
+ The content of `module/main.k` is
672
+
673
+ ```python
674
+ import helloworld
675
+ import flask
676
+
677
+ a = helloworld.The_first_kcl_program
678
+ ```
679
+
680
+ Python Code
681
+
682
+ ```python
683
+ import kcl_lib.api as api
684
+
685
+ args = api.UpdateDependencies_Args(
686
+ manifest_path="module"
687
+ )
688
+ api_instance = api.API()
689
+ result = api_instance.update_dependencies(args)
690
+ exec_args = api.ExecProgram_Args(
691
+ k_filename_list=["module/main.k"],
692
+ external_pkgs=result.external_pkgs,
693
+ )
694
+ result = api_instance.exec_program(exec_args)
695
+ assert result.yaml_result == "a: Hello World!"
696
+ ```
697
+
698
+ </p>
699
+ </details>
700
+
701
+ ### get_version
702
+
703
+ Return the KCL service version information.
704
+
705
+ <details><summary>Example</summary>
706
+ <p>
707
+
708
+ Python Code
709
+
710
+ ```python
711
+ import kcl_lib.api as api
712
+
713
+ api_instance = api.API()
714
+ result = api_instance.get_version()
715
+ print(result.version_info)
716
+ ```
717
+
718
+ </p>
719
+ </details>
720
+
@@ -0,0 +1,11 @@
1
+ kcl_lib-0.11.0.dist-info/METADATA,sha256=PWyXsZNBzD2l-go1GZfGADx0TO_rAGjVsv_9G5hf2qs,12017
2
+ kcl_lib-0.11.0.dist-info/WHEEL,sha256=C6OBKVmKfuwsbiDjU1tnXQsZq9Z63wB0inxxegrU7Ao,132
3
+ kcl_lib/api/spec_pb2.pyi,sha256=SICDHsPDw7ygxFvBFUE9wU7BNUHUTkAskHUgMunO7hE,39503
4
+ kcl_lib/api/service.py,sha256=Phgae8NUgsCsnHU9TMpDdOWcL3I-KETJqN53tXFxr-A,22878
5
+ kcl_lib/api/__init__.py,sha256=xDhj649QOL-WIXjGyGACSBrUZCZwf51gjUlnsJQNNyI,2865
6
+ kcl_lib/api/spec_pb2.py,sha256=eh4xUcPaNrqB2vZhpC12-F7O0TjJ_gEmpIMDZbPNlYo,27825
7
+ kcl_lib/plugin/__init__.py,sha256=8n67HzfKI8I2E-OWZmE68ZRh88Jzq-Pc61qAmCdMUj8,125
8
+ kcl_lib/plugin/plugin.py,sha256=shHQS4atDxfctMOinoSUOO6Z568P9xB7BoT_aNn-xOw,2505
9
+ kcl_lib/__init__.py,sha256=3EKn2Bb6NvoajnhLym-yQiobUBgdnj46bhe5u_GYo5A,24
10
+ kcl_lib/_kcl_lib.cpython-313t-aarch64-linux-gnu.so,sha256=PCzXGU3atblHoM-YUIPwM2O2tV969rm3tXmKLnR1KNg,23337152
11
+ kcl_lib-0.11.0.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: maturin (1.7.8)
3
+ Root-Is-Purelib: false
4
+ Tag: cp313-cp313t-manylinux_2_17_aarch64.manylinux2014_aarch64