Skip to content

Commit

Permalink
Merge pull request #108 from Peefy/feat-more-python-examples-and-docs
Browse files Browse the repository at this point in the history
feat: add more python examples and pyi files
  • Loading branch information
Peefy authored Jul 14, 2024
2 parents 5852fe6 + 8c60c86 commit bb601a3
Show file tree
Hide file tree
Showing 29 changed files with 1,671 additions and 69 deletions.
2 changes: 1 addition & 1 deletion python/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ fmt:
cargo fmt

test:
export PYTHONPATH=${PWD} && python3 -m pip install pytest && python3 -m pytest
export PYTHONPATH=${PWD} && python3 -m pip install pytest && python3 -m pytest -vv

deps:
python3 -m venv venv
Expand Down
137 changes: 135 additions & 2 deletions python/kcl_lib/api/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,137 @@
from .spec_pb2 import *
"""KCL Python API"""

from .spec_pb2 import (
ExternalPkg,
Argument,
Error,
Message,
Ping_Args,
Ping_Result,
GetVersion_Args,
GetVersion_Result,
ListMethod_Args,
ListMethod_Result,
ParseFile_Args,
ParseFile_Result,
ParseProgram_Args,
ParseProgram_Result,
LoadPackage_Args,
LoadPackage_Result,
ListOptions_Result,
OptionHelp,
Symbol,
Scope,
SymbolIndex,
ScopeIndex,
ExecProgram_Args,
ExecProgram_Result,
BuildProgram_Args,
BuildProgram_Result,
ExecArtifact_Args,
FormatCode_Args,
FormatCode_Result,
FormatPath_Args,
FormatPath_Result,
LintPath_Args,
LintPath_Result,
OverrideFile_Args,
OverrideFile_Result,
ListVariables_Options,
VariableList,
ListVariables_Args,
ListVariables_Result,
Variable,
MapEntry,
GetSchemaTypeMapping_Args,
GetSchemaTypeMapping_Result,
ValidateCode_Args,
ValidateCode_Result,
Position,
ListDepFiles_Args,
ListDepFiles_Result,
LoadSettingsFiles_Args,
LoadSettingsFiles_Result,
CliConfig,
KeyValuePair,
Rename_Args,
Rename_Result,
RenameCode_Args,
RenameCode_Result,
Test_Args,
Test_Result,
TestCaseInfo,
UpdateDependencies_Args,
UpdateDependencies_Result,
KclType,
Decorator,
Example,
)
from .service import API

__all__ = ["API"]
__all__ = [
"API",
"ExternalPkg",
"Argument",
"Error",
"Message",
"Ping_Args",
"Ping_Result",
"GetVersion_Args",
"GetVersion_Result",
"ListMethod_Args",
"ListMethod_Result",
"ParseFile_Args",
"ParseFile_Result",
"ParseProgram_Args",
"ParseProgram_Result",
"LoadPackage_Args",
"LoadPackage_Result",
"ListOptions_Result",
"OptionHelp",
"Symbol",
"Scope",
"SymbolIndex",
"ScopeIndex",
"ExecProgram_Args",
"ExecProgram_Result",
"BuildProgram_Args",
"BuildProgram_Result",
"ExecArtifact_Args",
"FormatCode_Args",
"FormatCode_Result",
"FormatPath_Args",
"FormatPath_Result",
"LintPath_Args",
"LintPath_Result",
"OverrideFile_Args",
"OverrideFile_Result",
"ListVariables_Options",
"VariableList",
"ListVariables_Args",
"ListVariables_Result",
"Variable",
"MapEntry",
"GetSchemaTypeMapping_Args",
"GetSchemaTypeMapping_Result",
"ValidateCode_Args",
"ValidateCode_Result",
"Position",
"ListDepFiles_Args",
"ListDepFiles_Result",
"LoadSettingsFiles_Args",
"LoadSettingsFiles_Result",
"CliConfig",
"KeyValuePair",
"Rename_Args",
"Rename_Result",
"RenameCode_Args",
"RenameCode_Result",
"Test_Args",
"Test_Result",
"TestCaseInfo",
"UpdateDependencies_Args",
"UpdateDependencies_Result",
"KclType",
"Decorator",
"Example",
]
51 changes: 49 additions & 2 deletions python/kcl_lib/api/service.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,49 @@
import kcl_lib
import kcl_lib.plugin as plugin
from .spec_pb2 import *
from .spec_pb2 import (
Ping_Args,
Ping_Result,
GetVersion_Args,
GetVersion_Result,
ParseFile_Args,
ParseFile_Result,
ParseProgram_Args,
ParseProgram_Result,
LoadPackage_Args,
LoadPackage_Result,
ListOptions_Result,
ExecProgram_Args,
ExecProgram_Result,
BuildProgram_Args,
BuildProgram_Result,
ExecArtifact_Args,
FormatCode_Args,
FormatCode_Result,
FormatPath_Args,
FormatPath_Result,
LintPath_Args,
LintPath_Result,
OverrideFile_Args,
OverrideFile_Result,
ListVariables_Args,
ListVariables_Result,
GetSchemaTypeMapping_Args,
GetSchemaTypeMapping_Result,
ValidateCode_Args,
ValidateCode_Result,
ListDepFiles_Args,
ListDepFiles_Result,
LoadSettingsFiles_Args,
LoadSettingsFiles_Result,
Rename_Args,
Rename_Result,
RenameCode_Args,
RenameCode_Result,
Test_Args,
Test_Result,
UpdateDependencies_Args,
UpdateDependencies_Result,
)
from google.protobuf import message as _message


Expand Down Expand Up @@ -89,7 +132,9 @@ def rename_code(self, args: RenameCode_Args) -> RenameCode_Result:
def test(self, args: Test_Args) -> Test_Result:
return self.call("KclvmService.Test", args)

def test(self, args: UpdateDependencies_Args) -> UpdateDependencies_Result:
def update_dependencies(
self, args: UpdateDependencies_Args
) -> UpdateDependencies_Result:
return self.call("KclvmService.UpdateDependencies", args)

# Helper method to perform the call
Expand Down Expand Up @@ -199,4 +244,6 @@ def create_method_resp_message(self, method: str) -> _message.Message:
return Test_Result()
elif method in ["UpdateDependencies", "KclvmService.UpdateDependencies"]:
return UpdateDependencies_Result()
elif method in ["GetVersion", "KclvmService.GetVersion"]:
return GetVersion_Result()
raise Exception(f"unknown method: {method}")
Loading

0 comments on commit bb601a3

Please sign in to comment.