kcl-lib 0.9.1__cp39-none-win_amd64.whl → 0.9.3__cp39-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.

Potentially problematic release.


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

@@ -0,0 +1,722 @@
1
+ Metadata-Version: 2.3
2
+ Name: kcl_lib
3
+ Version: 0.9.3
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
+ assert result.variables["app"].variables[0].value == "AppConfig {replicas: 2}"
252
+ ```
253
+
254
+ </p>
255
+ </details>
256
+
257
+ ### list_options
258
+
259
+ list_options provides users with the ability to parse KCL program and get all option information.
260
+
261
+ <details><summary>Example</summary>
262
+ <p>
263
+
264
+ The content of `options.k` is
265
+
266
+ ```python
267
+ a = option("key1")
268
+ b = option("key2", required=True)
269
+ c = {
270
+ metadata.key = option("metadata-key")
271
+ }
272
+ ```
273
+
274
+ Python Code
275
+
276
+ ```python
277
+ import kcl_lib.api as api
278
+
279
+ args = api.ParseProgram_Args(paths=["options.k"])
280
+ api = api.API()
281
+ result = api.list_options(args)
282
+ assert len(result.options) == 3
283
+ assert result.options[0].name == "key1"
284
+ assert result.options[1].name == "key2"
285
+ assert result.options[2].name == "metadata-key"
286
+ ```
287
+
288
+ </p>
289
+ </details>
290
+
291
+ ### get_schema_type_mapping
292
+
293
+ Get schema type mapping defined in the program.
294
+
295
+ <details><summary>Example</summary>
296
+ <p>
297
+
298
+ The content of `schema.k` is
299
+
300
+ ```python
301
+ schema AppConfig:
302
+ replicas: int
303
+
304
+ app: AppConfig {
305
+ replicas: 2
306
+ }
307
+ ```
308
+
309
+ Python Code
310
+
311
+ ```python
312
+ import kcl_lib.api as api
313
+
314
+ exec_args = api.ExecProgram_Args(k_filename_list=["schema.k"])
315
+ args = api.GetSchemaTypeMapping_Args(exec_args=exec_args)
316
+ api = api.API()
317
+ result = api.get_schema_type_mapping(args)
318
+ assert result.schema_type_mapping["app"].properties["replicas"].type == "int"
319
+ ```
320
+
321
+ </p>
322
+ </details>
323
+
324
+ ### override_file
325
+
326
+ 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.
327
+
328
+ <details><summary>Example</summary>
329
+ <p>
330
+
331
+ The content of `main.k` is
332
+
333
+ ```python
334
+ a = 1
335
+
336
+ b = {
337
+ "a": 1
338
+ "b": 2
339
+ }
340
+ ```
341
+
342
+ Python Code
343
+
344
+ ```python
345
+ import kcl_lib.api as api
346
+ import pathlib
347
+
348
+ test_file = "main.k"
349
+ args = api.OverrideFile_Args(
350
+ file=test_file,
351
+ specs=["b.a=2"],
352
+ )
353
+ api = api.API()
354
+ result = api.override_file(args)
355
+ assert len(result.parse_errors) == 0
356
+ assert result.result == True
357
+ assert pathlib.Path(test_file).read_text() == """\
358
+ a = 1
359
+ b = {
360
+ "a": 2
361
+ "b": 2
362
+ }
363
+ """
364
+ ```
365
+
366
+ </p>
367
+ </details>
368
+
369
+ ### format_code
370
+
371
+ Format the code source.
372
+
373
+ <details><summary>Example</summary>
374
+ <p>
375
+
376
+ Python Code
377
+
378
+ ```python
379
+ import kcl_lib.api as api
380
+
381
+ source_code = """\
382
+ schema Person:
383
+ name: str
384
+ age: int
385
+
386
+ check:
387
+ 0 < age < 120
388
+ """
389
+ args = api.FormatCode_Args(source=source_code)
390
+ api_instance = api.API()
391
+ result = api_instance.format_code(args)
392
+ assert (
393
+ result.formatted.decode()
394
+ == """\
395
+ schema Person:
396
+ name: str
397
+ age: int
398
+
399
+ check:
400
+ 0 < age < 120
401
+
402
+ """
403
+ )
404
+ ```
405
+
406
+ </p>
407
+ </details>
408
+
409
+ ### format_path
410
+
411
+ Format KCL file or directory path contains KCL files and returns the changed file paths.
412
+
413
+ <details><summary>Example</summary>
414
+ <p>
415
+
416
+ The content of `format_path.k` is
417
+
418
+ ```python
419
+ schema Person:
420
+ name: str
421
+ age: int
422
+
423
+ check:
424
+ 0 < age < 120
425
+ ```
426
+
427
+ Python Code
428
+
429
+ ```python
430
+ import kcl_lib.api as api
431
+
432
+ args = api.FormatPath_Args(path="format_path.k")
433
+ api_instance = api.API()
434
+ result = api_instance.format_path(args)
435
+ print(result)
436
+ ```
437
+
438
+ </p>
439
+ </details>
440
+
441
+ ### lint_path
442
+
443
+ Lint files and return error messages including errors and warnings.
444
+
445
+ <details><summary>Example</summary>
446
+ <p>
447
+
448
+ The content of `lint_path.k` is
449
+
450
+ ```python
451
+ import math
452
+
453
+ a = 1
454
+ ```
455
+
456
+ Python Code
457
+
458
+ ```python
459
+ import kcl_lib.api as api
460
+
461
+ args = api.LintPath_Args(paths=["lint_path.k"])
462
+ api_instance = api.API()
463
+ result = api_instance.lint_path(args)
464
+ ```
465
+
466
+ </p>
467
+ </details>
468
+
469
+ ### validate_code
470
+
471
+ Validate code using schema and JSON/YAML data strings.
472
+
473
+ <details><summary>Example</summary>
474
+ <p>
475
+
476
+ Python Code
477
+
478
+ ```python
479
+ import kcl_lib.api as api
480
+
481
+ code = """\
482
+ schema Person:
483
+ name: str
484
+ age: int
485
+
486
+ check:
487
+ 0 < age < 120
488
+ """
489
+ data = '{"name": "Alice", "age": 10}'
490
+ args = api.ValidateCode_Args(code=code, data=data, format="json")
491
+ api_instance = api.API()
492
+ result = api_instance.validate_code(args)
493
+ assert result.success == True
494
+ assert result.err_message == ""
495
+ ```
496
+
497
+ </p>
498
+ </details>
499
+
500
+ ### rename
501
+
502
+ 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.
503
+
504
+ <details><summary>Example</summary>
505
+ <p>
506
+
507
+ The content of `main.k` is
508
+
509
+ ```python
510
+ a = 1
511
+ b = a
512
+ ```
513
+
514
+ Python Code
515
+
516
+ ```python
517
+ import kcl_lib.api as api
518
+
519
+ args = api.Rename_Args(
520
+ package_root=".",
521
+ symbol_path="a",
522
+ file_paths=["main.k"],
523
+ new_name="a2",
524
+ )
525
+ api_instance = api.API()
526
+ result = api_instance.rename(args)
527
+ ```
528
+
529
+ </p>
530
+ </details>
531
+
532
+ ### rename_code
533
+
534
+ 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.
535
+
536
+ <details><summary>Example</summary>
537
+ <p>
538
+
539
+ Python Code
540
+
541
+ ```python
542
+ import kcl_lib.api as api
543
+
544
+ args = api.RenameCode_Args(
545
+ package_root="/mock/path",
546
+ symbol_path="a",
547
+ source_codes={"/mock/path/main.k": "a = 1\nb = a"},
548
+ new_name="a2",
549
+ )
550
+ api_instance = api.API()
551
+ result = api_instance.rename_code(args)
552
+ assert result.changed_codes["/mock/path/main.k"] == "a2 = 1\nb = a2"
553
+ ```
554
+
555
+ </p>
556
+ </details>
557
+
558
+ ### test
559
+
560
+ Test KCL packages with test arguments.
561
+
562
+ <details><summary>Example</summary>
563
+ <p>
564
+
565
+ Python Code
566
+
567
+ ```python
568
+ import kcl_lib.api as api
569
+ args = api.Test_Args(
570
+ pkg_list=["path/to/testing/pkg/..."],
571
+ )
572
+ api_instance = api.API()
573
+ result = api_instance.test(args)
574
+ ```
575
+
576
+ </p>
577
+ </details>
578
+
579
+ ### load_settings_files
580
+
581
+ Load the setting file config defined in `kcl.yaml`
582
+
583
+ <details><summary>Example</summary>
584
+ <p>
585
+
586
+ The content of `kcl.yaml` is
587
+
588
+ ```yaml
589
+ kcl_cli_configs:
590
+ strict_range_check: true
591
+ kcl_options:
592
+ - key: key
593
+ value: value
594
+ ```
595
+
596
+ Python Code
597
+
598
+ ```python
599
+ import kcl_lib.api as api
600
+
601
+ args = api.LoadSettingsFiles_Args(
602
+ work_dir=".", files=["kcl.yaml"]
603
+ )
604
+ api_instance = api.API()
605
+ result = api_instance.load_settings_files(args)
606
+ assert result.kcl_cli_configs.files == []
607
+ assert result.kcl_cli_configs.strict_range_check == True
608
+ assert (
609
+ result.kcl_options[0].key == "key" and result.kcl_options[0].value == '"value"'
610
+ )
611
+ ```
612
+
613
+ </p>
614
+ </details>
615
+
616
+ ### update_dependencies
617
+
618
+ Download and update dependencies defined in the `kcl.mod` file and return the external package name and location list.
619
+
620
+ <details><summary>Example</summary>
621
+ <p>
622
+
623
+ The content of `module/kcl.mod` is
624
+
625
+ ```yaml
626
+ [package]
627
+ name = "mod_update"
628
+ edition = "0.0.1"
629
+ version = "0.0.1"
630
+
631
+ [dependencies]
632
+ helloworld = { oci = "oci://ghcr.io/kcl-lang/helloworld", tag = "0.1.0" }
633
+ flask = { git = "https://github.com/kcl-lang/flask-demo-kcl-manifests", commit = "ade147b" }
634
+ ```
635
+
636
+ Python Code
637
+
638
+ ```python
639
+ import kcl_lib.api as api
640
+
641
+ args = api.UpdateDependencies_Args(
642
+ manifest_path="module"
643
+ )
644
+ api_instance = api.API()
645
+ result = api_instance.update_dependencies(args)
646
+ pkg_names = [pkg.pkg_name for pkg in result.external_pkgs]
647
+ assert len(pkg_names) == 2
648
+ assert "helloworld" in pkg_names
649
+ assert "flask" in pkg_names
650
+ ```
651
+
652
+ </p>
653
+ </details>
654
+
655
+ Call `exec_program` with external dependencies
656
+
657
+ <details><summary>Example</summary>
658
+ <p>
659
+
660
+ The content of `module/kcl.mod` is
661
+
662
+ ```yaml
663
+ [package]
664
+ name = "mod_update"
665
+ edition = "0.0.1"
666
+ version = "0.0.1"
667
+
668
+ [dependencies]
669
+ helloworld = { oci = "oci://ghcr.io/kcl-lang/helloworld", tag = "0.1.0" }
670
+ flask = { git = "https://github.com/kcl-lang/flask-demo-kcl-manifests", commit = "ade147b" }
671
+ ```
672
+
673
+ The content of `module/main.k` is
674
+
675
+ ```python
676
+ import helloworld
677
+ import flask
678
+
679
+ a = helloworld.The_first_kcl_program
680
+ ```
681
+
682
+ Python Code
683
+
684
+ ```python
685
+ import kcl_lib.api as api
686
+
687
+ args = api.UpdateDependencies_Args(
688
+ manifest_path="module"
689
+ )
690
+ api_instance = api.API()
691
+ result = api_instance.update_dependencies(args)
692
+ exec_args = api.ExecProgram_Args(
693
+ k_filename_list=["module/main.k"],
694
+ external_pkgs=result.external_pkgs,
695
+ )
696
+ result = api_instance.exec_program(exec_args)
697
+ assert result.yaml_result == "a: Hello World!"
698
+ ```
699
+
700
+ </p>
701
+ </details>
702
+
703
+ ### get_version
704
+
705
+ Return the KCL service version information.
706
+
707
+ <details><summary>Example</summary>
708
+ <p>
709
+
710
+ Python Code
711
+
712
+ ```python
713
+ import kcl_lib.api as api
714
+
715
+ api_instance = api.API()
716
+ result = api_instance.get_version()
717
+ print(result.version_info)
718
+ ```
719
+
720
+ </p>
721
+ </details>
722
+
@@ -0,0 +1,11 @@
1
+ kcl_lib-0.9.3.dist-info/METADATA,sha256=kMdLV4jYMKFmtmaWhWnJGMduFtBr2pNX31mO8FehQ7Q,12796
2
+ kcl_lib-0.9.3.dist-info/WHEEL,sha256=iLyJQhiiBYwo5FdZQS-97uaKimQdR9d5M5S1bVJlIxM,94
3
+ kcl_lib/api/service.py,sha256=cCqho-0jEuU4q7VKAmusUf-E_Egk_brZWNq0D1IHxZA,24472
4
+ kcl_lib/api/spec_pb2.py,sha256=Q-p6KrdDXkslZkpLEgRnhbd0D85Lycds9d2umc8zqPs,28370
5
+ kcl_lib/api/spec_pb2.pyi,sha256=N_FjBZVpe_uaQX5U09l-i8i1EYyn0u8Irvqf9oyevYM,40667
6
+ kcl_lib/api/__init__.py,sha256=NKelBIJzxUdJdSeSSNYS9ydpd4vf8k7Yf1mLqeoQecg,3002
7
+ kcl_lib/plugin/plugin.py,sha256=myBXT9NXmYp5lXHADUW96nmG3THSSQlpgWMOOxVjl3c,2587
8
+ kcl_lib/plugin/__init__.py,sha256=oWZbsj-_zmxLIcWpTWgGitEFCtiZphZUs2A3cazs720,128
9
+ kcl_lib/__init__.py,sha256=l3Vex1HIfcckzc9d23poK8cntz2zAnchQM4l6qbXluM,25
10
+ kcl_lib/_kcl_lib.cp39-win_amd64.pyd,sha256=e7m2V5nx1458x1XoQNkG5td3A0py4D5j0CcwBNS8mCQ,18817536
11
+ kcl_lib-0.9.3.dist-info/RECORD,,