stinger-ipc 0.0.3__tar.gz → 0.0.5__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 (66) hide show
  1. {stinger_ipc-0.0.3/stinger_ipc.egg-info → stinger_ipc-0.0.5}/PKG-INFO +2 -1
  2. {stinger_ipc-0.0.3 → stinger_ipc-0.0.5}/pyproject.toml +4 -3
  3. {stinger_ipc-0.0.3 → stinger_ipc-0.0.5/stinger_ipc.egg-info}/PKG-INFO +2 -1
  4. {stinger_ipc-0.0.3 → stinger_ipc-0.0.5}/stinger_ipc.egg-info/SOURCES.txt +1 -0
  5. stinger_ipc-0.0.5/stinger_ipc.egg-info/entry_points.txt +4 -0
  6. {stinger_ipc-0.0.3 → stinger_ipc-0.0.5}/stinger_ipc.egg-info/requires.txt +1 -0
  7. {stinger_ipc-0.0.3 → stinger_ipc-0.0.5}/stingeripc/components.py +20 -14
  8. {stinger_ipc-0.0.3 → stinger_ipc-0.0.5}/stingeripc/lang_symb.py +35 -1
  9. {stinger_ipc-0.0.3 → stinger_ipc-0.0.5}/stingeripc/templates/cpp/examples/client_main.cpp.jinja2 +2 -2
  10. {stinger_ipc-0.0.3 → stinger_ipc-0.0.5}/stingeripc/templates/cpp/examples/server_main.cpp.jinja2 +5 -5
  11. {stinger_ipc-0.0.3 → stinger_ipc-0.0.5}/stingeripc/templates/cpp/include/broker.hpp.jinja2 +7 -0
  12. {stinger_ipc-0.0.3 → stinger_ipc-0.0.5}/stingeripc/templates/cpp/include/client.hpp.jinja2 +12 -4
  13. {stinger_ipc-0.0.3 → stinger_ipc-0.0.5}/stingeripc/templates/cpp/include/ibrokerconnection.hpp.jinja2 +7 -0
  14. stinger_ipc-0.0.5/stingeripc/templates/cpp/include/property_structs.hpp.jinja2 +10 -0
  15. {stinger_ipc-0.0.3 → stinger_ipc-0.0.5}/stingeripc/templates/cpp/include/return_types.hpp.jinja2 +8 -1
  16. {stinger_ipc-0.0.3 → stinger_ipc-0.0.5}/stingeripc/templates/cpp/include/server.hpp.jinja2 +11 -4
  17. {stinger_ipc-0.0.3 → stinger_ipc-0.0.5}/stingeripc/templates/cpp/include/structs.hpp.jinja2 +7 -1
  18. {stinger_ipc-0.0.3 → stinger_ipc-0.0.5}/stingeripc/templates/cpp/src/client.cpp.jinja2 +15 -10
  19. {stinger_ipc-0.0.3 → stinger_ipc-0.0.5}/stingeripc/templates/cpp/src/server.cpp.jinja2 +12 -12
  20. {stinger_ipc-0.0.3 → stinger_ipc-0.0.5}/stingeripc/templates/markdown/index.md.jinja2 +74 -1
  21. {stinger_ipc-0.0.3 → stinger_ipc-0.0.5}/stingeripc/tools/markdown_generator.py +13 -6
  22. stinger_ipc-0.0.5/stingeripc/tools/python_generator.py +49 -0
  23. stinger_ipc-0.0.3/stinger_ipc.egg-info/entry_points.txt +0 -4
  24. stinger_ipc-0.0.3/stingeripc/tools/python_generator.py +0 -41
  25. {stinger_ipc-0.0.3 → stinger_ipc-0.0.5}/LICENSE +0 -0
  26. {stinger_ipc-0.0.3 → stinger_ipc-0.0.5}/README.md +0 -0
  27. {stinger_ipc-0.0.3 → stinger_ipc-0.0.5}/setup.cfg +0 -0
  28. {stinger_ipc-0.0.3 → stinger_ipc-0.0.5}/stinger_ipc.egg-info/dependency_links.txt +0 -0
  29. {stinger_ipc-0.0.3 → stinger_ipc-0.0.5}/stinger_ipc.egg-info/top_level.txt +0 -0
  30. {stinger_ipc-0.0.3 → stinger_ipc-0.0.5}/stingeripc/__init__.py +0 -0
  31. {stinger_ipc-0.0.3 → stinger_ipc-0.0.5}/stingeripc/args.py +0 -0
  32. {stinger_ipc-0.0.3 → stinger_ipc-0.0.5}/stingeripc/asyncapi.py +0 -0
  33. {stinger_ipc-0.0.3 → stinger_ipc-0.0.5}/stingeripc/connection.py +0 -0
  34. {stinger_ipc-0.0.3 → stinger_ipc-0.0.5}/stingeripc/exceptions.py +0 -0
  35. {stinger_ipc-0.0.3 → stinger_ipc-0.0.5}/stingeripc/interface.py +0 -0
  36. {stinger_ipc-0.0.3 → stinger_ipc-0.0.5}/stingeripc/templates/cpp/CMakeLists.txt.jinja2 +0 -0
  37. {stinger_ipc-0.0.3 → stinger_ipc-0.0.5}/stingeripc/templates/cpp/include/enums.hpp.jinja2 +0 -0
  38. {stinger_ipc-0.0.3 → stinger_ipc-0.0.5}/stingeripc/templates/cpp/src/broker.cpp.jinja2 +0 -0
  39. {stinger_ipc-0.0.3 → stinger_ipc-0.0.5}/stingeripc/templates/python/__init__.py.jinja2 +0 -0
  40. {stinger_ipc-0.0.3 → stinger_ipc-0.0.5}/stingeripc/templates/python/client.py.jinja2 +0 -0
  41. {stinger_ipc-0.0.3 → stinger_ipc-0.0.5}/stingeripc/templates/python/connection.py.jinja2 +0 -0
  42. {stinger_ipc-0.0.3 → stinger_ipc-0.0.5}/stingeripc/templates/python/interface_types.py.jinja2 +0 -0
  43. {stinger_ipc-0.0.3 → stinger_ipc-0.0.5}/stingeripc/templates/python/method_codes.py.jinja2 +0 -0
  44. {stinger_ipc-0.0.3 → stinger_ipc-0.0.5}/stingeripc/templates/python/pyproject.toml.jinja2 +0 -0
  45. {stinger_ipc-0.0.3 → stinger_ipc-0.0.5}/stingeripc/templates/python/server.py.jinja2 +0 -0
  46. {stinger_ipc-0.0.3 → stinger_ipc-0.0.5}/stingeripc/templates/rust/Cargo.toml.jinja2 +0 -0
  47. {stinger_ipc-0.0.3 → stinger_ipc-0.0.5}/stingeripc/templates/rust/client/Cargo.toml.jinja2 +0 -0
  48. {stinger_ipc-0.0.3 → stinger_ipc-0.0.5}/stingeripc/templates/rust/client/examples/client.rs.jinja2 +0 -0
  49. {stinger_ipc-0.0.3 → stinger_ipc-0.0.5}/stingeripc/templates/rust/client/src/lib.rs.jinja2 +0 -0
  50. {stinger_ipc-0.0.3 → stinger_ipc-0.0.5}/stingeripc/templates/rust/connection/Cargo.toml.jinja2 +0 -0
  51. {stinger_ipc-0.0.3 → stinger_ipc-0.0.5}/stingeripc/templates/rust/connection/examples/pub_and_recv.rs.jinja2 +0 -0
  52. {stinger_ipc-0.0.3 → stinger_ipc-0.0.5}/stingeripc/templates/rust/connection/src/handler.rs.jinja2 +0 -0
  53. {stinger_ipc-0.0.3 → stinger_ipc-0.0.5}/stingeripc/templates/rust/connection/src/lib.rs.jinja2 +0 -0
  54. {stinger_ipc-0.0.3 → stinger_ipc-0.0.5}/stingeripc/templates/rust/connection/src/payloads.rs.jinja2 +0 -0
  55. {stinger_ipc-0.0.3 → stinger_ipc-0.0.5}/stingeripc/templates/rust/server/Cargo.toml.jinja2 +0 -0
  56. {stinger_ipc-0.0.3 → stinger_ipc-0.0.5}/stingeripc/templates/rust/server/examples/server.rs.jinja2 +0 -0
  57. {stinger_ipc-0.0.3 → stinger_ipc-0.0.5}/stingeripc/templates/rust/server/src/lib.rs.jinja2 +0 -0
  58. {stinger_ipc-0.0.3 → stinger_ipc-0.0.5}/stingeripc/tools/__init__.py +0 -0
  59. {stinger_ipc-0.0.3 → stinger_ipc-0.0.5}/stingeripc/tools/rust_generator.py +0 -0
  60. {stinger_ipc-0.0.3 → stinger_ipc-0.0.5}/stingeripc/topic.py +0 -0
  61. {stinger_ipc-0.0.3 → stinger_ipc-0.0.5}/tests/test_args.py +0 -0
  62. {stinger_ipc-0.0.3 → stinger_ipc-0.0.5}/tests/test_enum.py +0 -0
  63. {stinger_ipc-0.0.3 → stinger_ipc-0.0.5}/tests/test_examples.py +0 -0
  64. {stinger_ipc-0.0.3 → stinger_ipc-0.0.5}/tests/test_interface.py +0 -0
  65. {stinger_ipc-0.0.3 → stinger_ipc-0.0.5}/tests/test_signal.py +0 -0
  66. {stinger_ipc-0.0.3 → stinger_ipc-0.0.5}/tests/test_topics.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: stinger-ipc
3
- Version: 0.0.3
3
+ Version: 0.0.5
4
4
  Summary: Tools to create code to do IPC over MQTT
5
5
  Requires-Python: >=3.12
6
6
  Description-Content-Type: text/markdown
@@ -11,6 +11,7 @@ Requires-Dist: pydantic>=2.11.7
11
11
  Requires-Dist: pyyaml>=6.0.2
12
12
  Requires-Dist: ruamel-yaml>=0.18.14
13
13
  Requires-Dist: stringcase>=1.2.0
14
+ Requires-Dist: typer>=0.16.1
14
15
  Requires-Dist: yamlloader>=1.5.1
15
16
  Dynamic: license-file
16
17
 
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "stinger-ipc"
3
- version = "0.0.3"
3
+ version = "0.0.5"
4
4
  description = "Tools to create code to do IPC over MQTT"
5
5
  readme = "README.md"
6
6
  requires-python = ">=3.12"
@@ -11,6 +11,7 @@ dependencies = [
11
11
  "pyyaml>=6.0.2",
12
12
  "ruamel-yaml>=0.18.14",
13
13
  "stringcase>=1.2.0",
14
+ "typer>=0.16.1",
14
15
  "yamlloader>=1.5.1",
15
16
  ]
16
17
 
@@ -41,6 +42,6 @@ stingeripc = [
41
42
  ]
42
43
 
43
44
  [project.scripts]
44
- pythongen = "stingeripc.tools.python_generator:main"
45
+ pythongen = "stingeripc.tools.python_generator:run"
45
46
  rustgen = "stingeripc.tools.rust_generator:main"
46
- markdowngen = "stingeripc.tools.markdown_generator:main"
47
+ markdowngen = "stingeripc.tools.markdown_generator:run"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: stinger-ipc
3
- Version: 0.0.3
3
+ Version: 0.0.5
4
4
  Summary: Tools to create code to do IPC over MQTT
5
5
  Requires-Python: >=3.12
6
6
  Description-Content-Type: text/markdown
@@ -11,6 +11,7 @@ Requires-Dist: pydantic>=2.11.7
11
11
  Requires-Dist: pyyaml>=6.0.2
12
12
  Requires-Dist: ruamel-yaml>=0.18.14
13
13
  Requires-Dist: stringcase>=1.2.0
14
+ Requires-Dist: typer>=0.16.1
14
15
  Requires-Dist: yamlloader>=1.5.1
15
16
  Dynamic: license-file
16
17
 
@@ -23,6 +23,7 @@ stingeripc/templates/cpp/include/broker.hpp.jinja2
23
23
  stingeripc/templates/cpp/include/client.hpp.jinja2
24
24
  stingeripc/templates/cpp/include/enums.hpp.jinja2
25
25
  stingeripc/templates/cpp/include/ibrokerconnection.hpp.jinja2
26
+ stingeripc/templates/cpp/include/property_structs.hpp.jinja2
26
27
  stingeripc/templates/cpp/include/return_types.hpp.jinja2
27
28
  stingeripc/templates/cpp/include/server.hpp.jinja2
28
29
  stingeripc/templates/cpp/include/structs.hpp.jinja2
@@ -0,0 +1,4 @@
1
+ [console_scripts]
2
+ markdowngen = stingeripc.tools.markdown_generator:run
3
+ pythongen = stingeripc.tools.python_generator:run
4
+ rustgen = stingeripc.tools.rust_generator:main
@@ -4,4 +4,5 @@ pydantic>=2.11.7
4
4
  pyyaml>=6.0.2
5
5
  ruamel-yaml>=0.18.14
6
6
  stringcase>=1.2.0
7
+ typer>=0.16.1
7
8
  yamlloader>=1.5.1
@@ -3,7 +3,7 @@ from enum import Enum
3
3
  import random
4
4
  import stringcase
5
5
  from abc import abstractmethod
6
- from typing import Dict, List, Optional, Any, Union
6
+ from typing import Any
7
7
  from .topic import (
8
8
  SignalTopicCreator,
9
9
  InterfaceTopicCreator,
@@ -387,7 +387,7 @@ class Signal(InterfaceComponent):
387
387
  def __init__(self, topic_creator: SignalTopicCreator, name: str):
388
388
  super().__init__(name)
389
389
  self._topic_creator = topic_creator
390
- self._arg_list = [] # type: List[Arg]
390
+ self._arg_list: list[Arg] = []
391
391
 
392
392
  def add_arg(self, arg: Arg) -> Signal:
393
393
  if arg.name in [a.name for a in self._arg_list]:
@@ -408,7 +408,7 @@ class Signal(InterfaceComponent):
408
408
  cls,
409
409
  topic_creator: SignalTopicCreator,
410
410
  name: str,
411
- signal_spec: Dict[str, str],
411
+ signal_spec: dict[str, str],
412
412
  stinger_spec: StingerSpec | None = None,
413
413
  ) -> "Signal":
414
414
  """Alternative constructor from a Stinger signal structure."""
@@ -437,7 +437,7 @@ class Method(InterfaceComponent):
437
437
  super().__init__(name)
438
438
  self._python = PythonMethodSymbols(self)
439
439
  self._topic_creator = topic_creator
440
- self._arg_list = [] # type: List[Arg]
440
+ self._arg_list: list[Arg] = []
441
441
  self._return_value: Arg | list[Arg] | None = None
442
442
 
443
443
  @property
@@ -482,7 +482,7 @@ class Method(InterfaceComponent):
482
482
  @property
483
483
  def return_value_cpp_class(self) -> str:
484
484
  if self._return_value is None:
485
- return "null"
485
+ return "void"
486
486
  elif isinstance(self._return_value, Arg):
487
487
  return self._return_value.cpp_type
488
488
  elif isinstance(self._return_value, list):
@@ -572,7 +572,7 @@ class Method(InterfaceComponent):
572
572
  cls,
573
573
  topic_creator: MethodTopicCreator,
574
574
  name: str,
575
- method_spec: Dict[str, str],
575
+ method_spec: dict[str, str],
576
576
  stinger_spec: StingerSpec | None = None,
577
577
  ) -> "Method":
578
578
  """Alternative constructor from a Stinger method structure."""
@@ -614,7 +614,7 @@ class Property(InterfaceComponent):
614
614
  def __init__(self, topic_creator: PropertyTopicCreator, name: str):
615
615
  super().__init__(name)
616
616
  self._topic_creator = topic_creator
617
- self._arg_list = [] # type: List[Arg]
617
+ self._arg_list: list[Arg] = []
618
618
  self._read_only = False
619
619
 
620
620
  def add_arg(self, arg: Arg) -> Property:
@@ -829,7 +829,7 @@ class InterfaceStruct:
829
829
  def new_struct_from_stinger(
830
830
  cls,
831
831
  name,
832
- spec: Dict[str, str | List[Dict[str, str]]],
832
+ spec: dict[str, str | list[dict[str, str]]],
833
833
  stinger_spec: StingerSpec,
834
834
  ) -> InterfaceStruct:
835
835
  istruct = cls(name)
@@ -884,7 +884,7 @@ class Broker:
884
884
  self._port = port
885
885
 
886
886
  @classmethod
887
- def new_broker_from_stinger(cls, name: str, spec: Dict[str, Any]) -> Broker:
887
+ def new_broker_from_stinger(cls, name: str, spec: dict[str, Any]) -> Broker:
888
888
  new_broker = cls(name=name)
889
889
  if "host" in spec:
890
890
  new_broker.hostname = spec["host"]
@@ -897,13 +897,14 @@ class Broker:
897
897
 
898
898
 
899
899
  class StingerSpec:
900
- def __init__(self, topic_creator: InterfaceTopicCreator, interface):
900
+ def __init__(self, topic_creator: InterfaceTopicCreator, interface: dict[str, Any]):
901
901
  self._topic_creator = topic_creator
902
902
  try:
903
903
  self._name: str = interface["name"]
904
904
  self._version: str = interface["version"]
905
905
  self._python = PythonInterfaceSymbols(self)
906
906
  self._rust = RustInterfaceSymbols(self)
907
+ self._cpp = CppInterfaceSymbols(self)
907
908
  except KeyError as e:
908
909
  raise InvalidStingerStructure(
909
910
  f"Missing interface property in {interface}: {e}"
@@ -913,8 +914,9 @@ class StingerSpec:
913
914
  f"Interface didn't appear to have a correct type"
914
915
  )
915
916
 
916
- self._summary = interface["summary"] if "summary" in interface else None
917
- self._title = interface["title"] if "title" in interface else None
917
+ self._summary = interface.get("summary")
918
+ self._title = interface.get("title")
919
+ self._documentation = interface.get("documentation")
918
920
 
919
921
  self.signals: dict[str, Signal] = {}
920
922
  self.properties: dict[str, Property] = {}
@@ -951,7 +953,7 @@ class StingerSpec:
951
953
  self._brokers[broker.name] = broker
952
954
 
953
955
  @property
954
- def brokers(self) -> Dict[str, Broker]:
956
+ def brokers(self) -> dict[str, Broker]:
955
957
  if len(self._brokers) == 0:
956
958
  default_broker = Broker()
957
959
  return {default_broker.name: default_broker}
@@ -1007,6 +1009,10 @@ class StingerSpec:
1007
1009
  def rust(self) -> RustInterfaceSymbols:
1008
1010
  return self._rust
1009
1011
 
1012
+ @property
1013
+ def cpp(self) -> CppInterfaceSymbols:
1014
+ return self._cpp
1015
+
1010
1016
  @staticmethod
1011
1017
  def get_enum_module_name() -> str:
1012
1018
  return InterfaceEnum.get_module_name()
@@ -1017,7 +1023,7 @@ class StingerSpec:
1017
1023
 
1018
1024
  @classmethod
1019
1025
  def new_spec_from_stinger(
1020
- cls, topic_creator, stinger: Dict[str, Any]
1026
+ cls, topic_creator, stinger: dict[str, Any]
1021
1027
  ) -> StingerSpec:
1022
1028
  if "stingeripc" not in stinger:
1023
1029
  raise InvalidStingerStructure("Missing 'stingeripc' format version")
@@ -5,6 +5,10 @@ class PythonSymbols:
5
5
  def __init__(self):
6
6
  ...
7
7
 
8
+ @property
9
+ def package_name(self):
10
+ return f"{stringmanip.lower_camel_case(self._iface.name).lower()}ipc"
11
+
8
12
  @property
9
13
  def type_definition_module(self) -> str:
10
14
  return "stinger_types"
@@ -51,7 +55,11 @@ class PythonMethodSymbols(PythonSymbols):
51
55
  def return_value_class(self):
52
56
  return f"{self.type_definition_module}.{self.return_value_local_class}"
53
57
 
54
- class RustInterfaceSymbols(PythonSymbols):
58
+ class RustSymbols:
59
+ def __init__(self):
60
+ pass
61
+
62
+ class RustInterfaceSymbols(RustSymbols):
55
63
 
56
64
  def __init__(self, interface):
57
65
  super().__init__()
@@ -66,3 +74,29 @@ class RustInterfaceSymbols(PythonSymbols):
66
74
  def server_struct_name(self) -> str:
67
75
  """ Name of the struct for the interface server."""
68
76
  return f"{stringmanip.upper_camel_case(self._iface.name)}Server"
77
+
78
+ class CppSymbols:
79
+ def __init__(self):
80
+ pass
81
+
82
+ class CppInterfaceSymbols(CppSymbols):
83
+
84
+ def __init__(self, interface):
85
+ super().__init__()
86
+ self._iface = interface
87
+
88
+ @property
89
+ def client_class_name(self) -> str:
90
+ return f"{stringmanip.upper_camel_case(self._iface.name)}Client"
91
+
92
+ @property
93
+ def server_class_name(self) -> str:
94
+ return f"{stringmanip.upper_camel_case(self._iface.name)}Server"
95
+
96
+ @property
97
+ def enum_header_file(self) -> str:
98
+ return "enums.hpp"
99
+
100
+ @property
101
+ def property_struct_header_file(self) -> str:
102
+ return "property_structs.hpp"
@@ -7,8 +7,8 @@
7
7
  int main(int argc, char** argv) {
8
8
 
9
9
  {%set broker = stinger.get_example_broker()%}
10
- auto conn = std::make_shared<{{broker.class_name}}>({%if broker.hostname is none%}"localhost", 1883, {%endif%}"{{stinger.name | UpperCamelCase}}Client-demo");
11
- {{stinger.name | UpperCamelCase}}Client client(conn);
10
+ auto conn = std::make_shared<{{broker.class_name}}>({%if broker.hostname is none%}"localhost", 1883, {%endif%}"{{stinger.cpp.client_class_name}}-demo");
11
+ {{stinger.cpp.client_class_name}} client(conn);
12
12
 
13
13
  {%-for sig_name, sig in stinger.signals.items() %}
14
14
  client.register{{sig_name | UpperCamelCase}}Callback([]({%for arg in sig.arg_list%}{{arg.cpp_type}} {{arg.name}}{%if not loop.last%}, {%endif%}{%endfor%}) {
@@ -3,13 +3,13 @@
3
3
 
4
4
  #include "broker.hpp"
5
5
  #include "server.hpp"
6
- #include "enums.hpp"
6
+ #include "{{stinger.cpp.enum_header_file}}"
7
7
 
8
8
  int main(int argc, char** argv) {
9
9
 
10
10
  {%set broker = stinger.get_example_broker()%}
11
- auto conn = std::make_shared<{{broker.class_name}}>({%if broker.hostname is none%}"localhost", 1883, {%endif%}"{{stinger.name | UpperCamelCase}}Serve-demo");
12
- {{stinger.name | UpperCamelCase}}Server server(conn);
11
+ auto conn = std::make_shared<{{broker.class_name}}>({%if broker.hostname is none%}"localhost", 1883, {%endif%}"{{stinger.name | UpperCamelCase}}");
12
+ {{stinger.cpp.server_class_name}} server(conn);
13
13
 
14
14
  {%-for sig_name, sig in stinger.signals.items() %}
15
15
  auto {{sig_name}}Future = server.emit{{sig_name | UpperCamelCase}}Signal({%for arg in sig.arg_list%}{{arg.get_random_example_value(lang="c++")}}{%if not loop.last%}, {%endif%}{%endfor%});
@@ -22,9 +22,9 @@ int main(int argc, char** argv) {
22
22
  server.register{{method_name | UpperCamelCase}}Handler([]({%for arg in method.arg_list%}{{arg.cpp_type}} unused{{loop.index}}{%if not loop.last%}, {%endif%}{%endfor%}) -> {{method.return_value_cpp_class}}
23
23
  {
24
24
  std::cout << "Received call for {{method_name}}\n";
25
- {%if method.return_value_type == 'struct'%}
25
+ {%-if method.return_value_type == 'struct'%}
26
26
  return {{method.return_value_name | UpperCamelCase}}{ {{method.get_return_value_random_example_value('c++')}} };
27
- {%else%}
27
+ {%-elif method.return_value_type is not false %}
28
28
  return {{method.get_return_value_random_example_value('c++')}};
29
29
  {%-endif%}
30
30
  });
@@ -1,3 +1,10 @@
1
+ /*
2
+ DO NOT MODIFY THIS FILE. It is automatically generated and changes will be over-written
3
+ on the next generation.
4
+
5
+ It contains enumerations used by the {{stinger.name}} interface.
6
+ */
7
+
1
8
 
2
9
  #pragma once
3
10
 
@@ -1,3 +1,10 @@
1
+ /*
2
+ DO NOT MODIFY THIS FILE. It is automatically generated and changes will be over-written
3
+ on the next generation.
4
+
5
+ It contains enumerations used by the {{stinger.name}} interface.
6
+ */
7
+
1
8
 
2
9
  #pragma once
3
10
 
@@ -11,10 +18,11 @@
11
18
  #include <boost/uuid/uuid.hpp>
12
19
 
13
20
  #include "ibrokerconnection.hpp"
14
- #include "enums.hpp"
21
+ #include "{{stinger.cpp.enum_header_file}}"
15
22
  #include "return_types.hpp"
23
+ {%if stinger.properties | length > 0 %}#include "{{stinger.cpp.property_struct_header_file}}"{%endif%}
16
24
 
17
- class {{stinger.name | UpperCamelCase}}Client {
25
+ class {{stinger.cpp.client_class_name}} {
18
26
 
19
27
  public:
20
28
  // This is the name of the API.
@@ -23,9 +31,9 @@ public:
23
31
  static constexpr const char INTERFACE_VERSION[] = "{{stinger.version}}";
24
32
 
25
33
  // Constructor taking a connection object.
26
- {{stinger.name | UpperCamelCase}}Client(std::shared_ptr<IBrokerConnection> broker);
34
+ {{stinger.cpp.client_class_name}}(std::shared_ptr<IBrokerConnection> broker);
27
35
 
28
- virtual ~{{stinger.name | UpperCamelCase}}Client() = default;
36
+ virtual ~{{stinger.cpp.client_class_name}}() = default;
29
37
 
30
38
  {%for sig_name, sig in stinger.signals.items()%}
31
39
  // Register a callback for the `{{sig_name}}` signal.
@@ -1,3 +1,10 @@
1
+ /*
2
+ DO NOT MODIFY THIS FILE. It is automatically generated and changes will be over-written
3
+ on the next generation.
4
+
5
+ It contains enumerations used by the {{stinger.name}} interface.
6
+ */
7
+
1
8
 
2
9
  #pragma once
3
10
 
@@ -0,0 +1,10 @@
1
+ /*
2
+ DO NOT MODIFY THIS FILE. It is automatically generated and changes will be over-written
3
+ on the next generation.
4
+
5
+ It contains enumerations used by the {{stinger.name}} interface.
6
+ */
7
+
8
+ {%for prop_name, prop in stinger.properties.items() %}
9
+ // {{prop}}
10
+ {%endfor%}
@@ -1,7 +1,14 @@
1
+ /*
2
+ DO NOT MODIFY THIS FILE. It is automatically generated and changes will be over-written
3
+ on the next generation.
4
+
5
+ It contains enumerations used by the {{stinger.name}} interface.
6
+ */
7
+
1
8
 
2
9
  #pragma once
3
10
  #include <string>
4
- #include "enums.hpp"
11
+ #include "{{stinger.cpp.enum_header_file}}"
5
12
 
6
13
  {%for method_name, method in stinger.methods.items()%}
7
14
  {%-if method.return_value_type == 'struct'%}
@@ -1,3 +1,10 @@
1
+ /*
2
+ DO NOT MODIFY THIS FILE. It is automatically generated and changes will be over-written
3
+ on the next generation.
4
+
5
+ It contains enumerations used by the {{stinger.name}} interface.
6
+ */
7
+
1
8
 
2
9
  #pragma once
3
10
 
@@ -12,18 +19,18 @@
12
19
  #include <rapidjson/document.h>
13
20
 
14
21
  #include "ibrokerconnection.hpp"
15
- #include "enums.hpp"
22
+ #include "{{stinger.cpp.enum_header_file}}"
16
23
  #include "return_types.hpp"
17
24
 
18
- class {{stinger.name | UpperCamelCase}}Server {
25
+ class {{stinger.cpp.server_class_name}} {
19
26
 
20
27
  public:
21
28
  static constexpr const char NAME[] = "{{stinger.name}}";
22
29
  static constexpr const char INTERFACE_VERSION[] = "{{stinger.version}}";
23
30
 
24
- {{stinger.name | UpperCamelCase}}Server(std::shared_ptr<IBrokerConnection> broker);
31
+ {{stinger.cpp.server_class_name}}(std::shared_ptr<IBrokerConnection> broker);
25
32
 
26
- virtual ~{{stinger.name | UpperCamelCase}}Server() = default;
33
+ virtual ~{{stinger.cpp.server_class_name}}() = default;
27
34
 
28
35
  {%for sig_name, sig in stinger.signals.items()%}
29
36
  boost::future<bool> emit{{sig_name | UpperCamelCase}}Signal({%for arg in sig.arg_list%}{{arg.cpp_type}}{%if not loop.last%}, {%endif%}{%endfor%});
@@ -1,8 +1,14 @@
1
+ /*
2
+ DO NOT MODIFY THIS FILE. It is automatically generated and changes will be over-written
3
+ on the next generation.
4
+
5
+ It contains enumerations used by the {{stinger.name}} interface.
6
+ */
1
7
 
2
8
  #pragma once
3
9
  #include <string>
4
10
  #include <boost/optional.hpp>
5
- #include "enums.hpp"
11
+ #include "{{stinger.cpp.enum_header_file}}"
6
12
 
7
13
  {%for istruct_name, istruct in stinger.structs.items() %}
8
14
  struct {{istruct_name | UpperCamelCase }} {
@@ -13,14 +13,14 @@
13
13
  #include <rapidjson/document.h>
14
14
 
15
15
  #include "client.hpp"
16
- #include "enums.hpp"
16
+ #include "{{stinger.cpp.enum_header_file}}"
17
17
  #include "ibrokerconnection.hpp"
18
18
 
19
19
 
20
- constexpr const char {{stinger.name | UpperCamelCase}}Client::NAME[];
21
- constexpr const char {{stinger.name | UpperCamelCase}}Client::INTERFACE_VERSION[];
20
+ constexpr const char {{stinger.cpp.client_class_name}}::NAME[];
21
+ constexpr const char {{stinger.cpp.client_class_name}}::INTERFACE_VERSION[];
22
22
 
23
- {{stinger.name | UpperCamelCase}}Client::{{stinger.name | UpperCamelCase}}Client(std::shared_ptr<IBrokerConnection> broker) : _broker(broker)
23
+ {{stinger.cpp.client_class_name}}::{{stinger.cpp.client_class_name}}(std::shared_ptr<IBrokerConnection> broker) : _broker(broker)
24
24
  {
25
25
  _broker->AddMessageCallback([this](const std::string& topic, const std::string& payload, const boost::optional<std::string> optCorrelationId, const boost::optional<std::string> unusedRespTopic, const boost::optional<MethodResultCode> optResultCode)
26
26
  {
@@ -39,7 +39,7 @@ constexpr const char {{stinger.name | UpperCamelCase}}Client::INTERFACE_VERSION[
39
39
  {%-endfor%}
40
40
  }
41
41
 
42
- void {{stinger.name | UpperCamelCase}}Client::_receiveMessage(
42
+ void {{stinger.cpp.client_class_name}}::_receiveMessage(
43
43
  const std::string& topic,
44
44
  const std::string& payload,
45
45
  const boost::optional<std::string> optCorrelationId,
@@ -106,14 +106,14 @@ void {{stinger.name | UpperCamelCase}}Client::_receiveMessage(
106
106
 
107
107
 
108
108
  {%-for sig_name, sig in stinger.signals.items() %}
109
- void {{stinger.name | UpperCamelCase}}Client::register{{sig_name | UpperCamelCase}}Callback(const std::function<void({%for arg in sig.arg_list%}{{arg.cpp_type}}{%if not loop.last%}, {%endif%}{%endfor%})>& cb)
109
+ void {{stinger.cpp.client_class_name}}::register{{sig_name | UpperCamelCase}}Callback(const std::function<void({%for arg in sig.arg_list%}{{arg.cpp_type}}{%if not loop.last%}, {%endif%}{%endfor%})>& cb)
110
110
  {
111
111
  _{{sig_name | camelCase}}Callback = cb;
112
112
  }
113
113
  {%-endfor%}
114
114
 
115
115
  {%for method_name, method in stinger.methods.items()%}
116
- boost::future<{{method.return_value_cpp_class}}> {{stinger.name | UpperCamelCase}}Client::{{method_name | camelCase}}({%for arg in method.arg_list%}{{arg.cpp_type}} {{arg.name}}{%if not loop.last%}, {%endif%}{%endfor%})
116
+ boost::future<{{method.return_value_cpp_class}}> {{stinger.cpp.client_class_name}}::{{method_name | camelCase}}({%for arg in method.arg_list%}{{arg.cpp_type}} {{arg.name}}{%if not loop.last%}, {%endif%}{%endfor%})
117
117
  {
118
118
  auto correlationId = boost::uuids::random_generator()();
119
119
  const std::string correlationIdStr = boost::lexical_cast<std::string>(correlationId);
@@ -122,7 +122,7 @@ boost::future<{{method.return_value_cpp_class}}> {{stinger.name | UpperCamelCase
122
122
  rapidjson::Document doc;
123
123
  doc.SetObject();
124
124
 
125
- {%macro addToDoc(arg)%}
125
+ {%-macro addToDoc(arg)%}
126
126
  {%-if arg.arg_type.name.lower() == 'primitive'%}
127
127
  {%-if arg.optional %}if ({{arg.name}}) {%endif-%}
128
128
  {%-if arg.type.name.lower() == 'string'%}
@@ -151,7 +151,7 @@ boost::future<{{method.return_value_cpp_class}}> {{stinger.name | UpperCamelCase
151
151
  return _pending{{method_name|UpperCamelCase}}MethodCalls[correlationId].get_future();
152
152
  }
153
153
 
154
- void {{stinger.name | UpperCamelCase}}Client::_handle{{method_name|UpperCamelCase}}Response(
154
+ void {{stinger.cpp.client_class_name}}::_handle{{method_name|UpperCamelCase}}Response(
155
155
  const std::string& topic,
156
156
  const std::string& payload,
157
157
  const std::string &correlationId)
@@ -182,6 +182,7 @@ void {{stinger.name | UpperCamelCase}}Client::_handle{{method_name|UpperCamelCas
182
182
  {%endif-%}
183
183
  {%endmacro-%}
184
184
  {%if method.return_value_type == 'struct'-%}
185
+ // Response has multiple values.
185
186
  {%for item in method.return_value%}
186
187
  {{unpack_rv(item)}}
187
188
  {%-endfor%}
@@ -191,8 +192,12 @@ void {{stinger.name | UpperCamelCase}}Client::_handle{{method_name|UpperCamelCas
191
192
  {%-endfor%}
192
193
  };
193
194
  promiseItr->second.set_value(returnValue);
195
+ {%-elif method.return_value_type is false %}
196
+ // There are no values in the response.
197
+ promiseItr->second.set_value();
194
198
  {%-else%}
195
- {{-unpack_rv(method.return_value)}}
199
+ // Response has a single value.
200
+ {{unpack_rv(method.return_value)}}
196
201
  promiseItr->second.set_value({{method.return_value_property_name}});
197
202
  {%-endif%}
198
203
  }
@@ -11,14 +11,14 @@
11
11
  #include <rapidjson/document.h>
12
12
 
13
13
  #include "server.hpp"
14
- #include "enums.hpp"
14
+ #include "{{stinger.cpp.enum_header_file}}"
15
15
  #include "ibrokerconnection.hpp"
16
16
 
17
17
 
18
- constexpr const char {{stinger.name | UpperCamelCase}}Server::NAME[];
19
- constexpr const char {{stinger.name | UpperCamelCase}}Server::INTERFACE_VERSION[];
18
+ constexpr const char {{stinger.cpp.server_class_name}}::NAME[];
19
+ constexpr const char {{stinger.cpp.server_class_name}}::INTERFACE_VERSION[];
20
20
 
21
- {{stinger.name | UpperCamelCase}}Server::{{stinger.name | UpperCamelCase}}Server(std::shared_ptr<IBrokerConnection> broker) : _broker(broker) {
21
+ {{stinger.cpp.server_class_name}}::{{stinger.cpp.server_class_name}}(std::shared_ptr<IBrokerConnection> broker) : _broker(broker) {
22
22
  _broker->AddMessageCallback([this](const std::string& topic, const std::string& payload, const boost::optional<std::string> optCorrelationId, const boost::optional<std::string> optResponseTopic, const boost::optional<MethodResultCode> unusedRc)
23
23
  {
24
24
  _receiveMessage(topic, payload, optCorrelationId, optResponseTopic);
@@ -28,7 +28,7 @@ constexpr const char {{stinger.name | UpperCamelCase}}Server::INTERFACE_VERSION[
28
28
  {%endfor%}
29
29
  }
30
30
 
31
- void {{stinger.name | UpperCamelCase}}Server::_receiveMessage(
31
+ void {{stinger.cpp.server_class_name}}::_receiveMessage(
32
32
  const std::string& topic,
33
33
  const std::string& payload,
34
34
  const boost::optional<std::string> optCorrelationId,
@@ -67,7 +67,7 @@ void {{stinger.name | UpperCamelCase}}Server::_receiveMessage(
67
67
  }
68
68
 
69
69
  {%for sig_name, sig in stinger.signals.items()%}
70
- boost::future<bool> {{stinger.name | UpperCamelCase}}Server::emit{{sig_name | UpperCamelCase}}Signal({%for arg in sig.arg_list%}{{arg.cpp_type}} {{arg.name}}{%if not loop.last%}, {%endif%}{%endfor%})
70
+ boost::future<bool> {{stinger.cpp.server_class_name}}::emit{{sig_name | UpperCamelCase}}Signal({%for arg in sig.arg_list%}{{arg.cpp_type}} {{arg.name}}{%if not loop.last%}, {%endif%}{%endfor%})
71
71
  {
72
72
  rapidjson::Document doc;
73
73
  doc.SetObject();
@@ -98,7 +98,7 @@ boost::future<bool> {{stinger.name | UpperCamelCase}}Server::emit{{sig_name | Up
98
98
  {%endfor%}
99
99
 
100
100
  {%for method_name, method in stinger.methods.items()%}
101
- void {{stinger.name | UpperCamelCase}}Server::register{{method_name | UpperCamelCase}}Handler(std::function<{{method.return_value_cpp_class}}({%for arg in method.arg_list%}{{arg.cpp_type}}{%if not loop.last%}, {%endif%}{%endfor%})> func)
101
+ void {{stinger.cpp.server_class_name}}::register{{method_name | UpperCamelCase}}Handler(std::function<{{method.return_value_cpp_class}}({%for arg in method.arg_list%}{{arg.cpp_type}}{%if not loop.last%}, {%endif%}{%endfor%})> func)
102
102
  {
103
103
  std::cout << "Registered method to handle {{method.topic}}\n";
104
104
  _{{method_name | camelCase}}Handler = func;
@@ -106,7 +106,7 @@ void {{stinger.name | UpperCamelCase}}Server::register{{method_name | UpperCamel
106
106
  {%endfor%}
107
107
 
108
108
  {%for method_name, method in stinger.methods.items()%}
109
- void {{stinger.name | UpperCamelCase}}Server::_call{{method_name | UpperCamelCase}}Handler(
109
+ void {{stinger.cpp.server_class_name}}::_call{{method_name | UpperCamelCase}}Handler(
110
110
  const std::string& topic,
111
111
  const rapidjson::Document& doc,
112
112
  const boost::optional<std::string> optCorrelationId,
@@ -130,12 +130,13 @@ void {{stinger.name | UpperCamelCase}}Server::_call{{method_name | UpperCamelCas
130
130
  }
131
131
  {%endfor%}
132
132
 
133
- {{method.return_value_cpp_class}} ret = _{{method_name | camelCase}}Handler({%for arg in method.arg_list%}temp{{arg.name|UpperCamelCase}}{%if not loop.last%}, {%endif%}{%endfor%});
133
+ {%if method.return_value_type is not false%}{{method.return_value_cpp_class}} ret = {%endif%}_{{method_name | camelCase}}Handler({%for arg in method.arg_list%}temp{{arg.name|UpperCamelCase}}{%if not loop.last%}, {%endif%}{%endfor%});
134
134
 
135
135
  if (optResponseTopic)
136
136
  {
137
137
  rapidjson::Document responseJson;
138
138
  responseJson.SetObject();
139
+
139
140
  {%macro add_arg_to_json(arg, value) %}
140
141
  // add the {{arg.name}} (a/n {{arg.arg_type.name}}) to the json
141
142
  rapidjson::Value returnValue{{arg.name|UpperCamelCase}};
@@ -150,16 +151,15 @@ void {{stinger.name | UpperCamelCase}}Server::_call{{method_name | UpperCamelCas
150
151
  {%-endif%} {# value or enum#}
151
152
  responseJson.AddMember("{{arg.name}}", returnValue{{arg.name|UpperCamelCase}}, responseJson.GetAllocator());
152
153
  {%endmacro%}
153
-
154
154
  {%-if method.return_value_type == 'struct'%}
155
155
  // Return type is a struct of values that need added to json
156
156
  {%for member in method.return_value-%}
157
157
  {{add_arg_to_json(member, "ret."+member.name)}}
158
158
  {%endfor%}
159
- {%-else%}
159
+ {%-elif method.return_value_type is not false%}
160
+ // Return type is a single value
160
161
  {{add_arg_to_json(method.return_value, "ret")}}
161
162
  {%-endif%}
162
-
163
163
  rapidjson::StringBuffer buf;
164
164
  rapidjson::Writer<rapidjson::StringBuffer> writer(buf);
165
165
  responseJson.Accept(writer);
@@ -1,6 +1,79 @@
1
1
  # _{{stinger.name}}_ API Overview
2
+ {%-if stinger.summary %}
3
+ _{{stinger.summary}}_
4
+ {%endif-%}
5
+ {%if stinger.documentation%}
6
+ {{stinger.documentation}}
7
+
8
+ ## Connections
9
+
10
+ A connection object is a wrapper around an MQTT client and provides specific functionality to support both clients and servers.
11
+ Generally, you only need one connection object per daemon/program, as it can support multiple clients and servers.
12
+
13
+ ### Connection code Examples
14
+
15
+ <details>
16
+ <summary>Python</summary>
17
+
18
+ ```python{%set broker = stinger.get_example_broker()%}
19
+ from connection import {{broker.class_name}}
20
+
21
+ connection_object = {{broker.class_name}}({%if broker.hostname is none%}'localhost', 1883{%endif%})
22
+ ```
23
+
24
+ The `connection_object` will be passed to client and server constructors.
25
+
26
+ </details>
27
+
28
+ <details>
29
+ <summary>C++</summary>
30
+
31
+ ```c++{%set broker = stinger.get_example_broker()%}
32
+ #include "broker.hpp"
33
+
34
+ auto connection_object = std::make_shared<{{broker.class_name}}>({%if broker.hostname is none%}"localhost", 1883, {%endif%}"{{stinger.name | UpperCamelCase}}");
35
+ ```
36
+
37
+ The `connection_object` will be passed to client and server constructors.
38
+
39
+ </details>
40
+
41
+ ## Server
2
42
 
3
- {{stinger.description}}
43
+ A server is a _provider_ of functionality. It sends signals, handles method calls, and owns property values.
44
+
45
+ ### Server Code Examples
46
+
47
+ <details>
48
+ <summary>Python Server</summary>
49
+
50
+ ```python{%set broker = stinger.get_example_broker()%}
51
+ from {{stinger.python.package_name}}.client import {{stinger.cpp.server_class_name}}
52
+
53
+ server = {{stinger.python.server_class_name}}(connection_object)
54
+ ```
55
+
56
+ The `server` object provides methods for emitting signals and updating properties. It also allows for decorators to indicate method call handlers.
57
+
58
+ </details>
59
+
60
+ <details>
61
+ <summary>C++ Server</summary>
62
+
63
+ ```python{%set broker = stinger.get_example_broker()%}
64
+ from connection import {{broker.class_name}}
65
+
66
+ conn = {{broker.class_name}}({%if broker.hostname is none%}'localhost', 1883{%endif%})
67
+ server = {{stinger.python.server_class_name}}(conn)
68
+ ```
69
+
70
+ The `server` object provides methods for emitting signals and updating properties. It also allows for decorators to indicate method call handlers.
71
+
72
+ </details>
73
+
74
+ ## Client
75
+
76
+ {%endif-%}
4
77
  {%macro argrow(arg) -%}
5
78
  |{{arg.name|center(15)}}|
6
79
  {%-if arg.arg_type.name.lower() == "enum" or arg.arg_type.name.lower() == "struct"%}{{arg.markdown_type|center(10)}}
@@ -1,12 +1,15 @@
1
1
  import os
2
2
  import sys
3
3
  from jacobsjinjatoo import templator as jj2
4
-
4
+ import os.path
5
+ import typer
6
+ from typing_extensions import Annotated
5
7
  from stingeripc import StingerInterface
8
+ from rich import print
9
+ from pathlib import Path
6
10
 
7
- def main():
8
- inname = sys.argv[1]
9
- outdir = sys.argv[2]
11
+ def main(inname: Annotated[Path, typer.Argument(exists=True, file_okay=True, dir_okay=False, readable=True)], outdir: Annotated[Path, typer.Argument(file_okay=False, dir_okay=True, writable=True, readable=True)]):
12
+ print(f"[bold green]Reading:[/bold green] {inname}")
10
13
  with open(inname, "r") as f:
11
14
  stinger = StingerInterface.from_yaml(f)
12
15
  params = {
@@ -19,7 +22,11 @@ def main():
19
22
  for output_file in [
20
23
  "index.md",
21
24
  ]:
25
+ print(f"[bold red]GENERATING:[/bold red] {output_file}")
22
26
  t.render_template(f"{output_file}.jinja2", output_file, **params)
23
27
 
24
- if __name__ == '__main__':
25
- main()
28
+ def run():
29
+ typer.run(main)
30
+
31
+ if __name__ == "__main__":
32
+ run()
@@ -0,0 +1,49 @@
1
+ from jacobsjinjatoo import templator as jj2
2
+ from jacobsjinjatoo import stringmanip
3
+ import sys
4
+ import os.path
5
+ import typer
6
+ from typing_extensions import Annotated
7
+ from stingeripc import StingerInterface
8
+ from rich import print
9
+ from pathlib import Path
10
+
11
+ def main(inname: Annotated[Path, typer.Argument(exists=True, file_okay=True, dir_okay=False, readable=True)], outdir: Annotated[Path, typer.Argument(file_okay=False, dir_okay=True, writable=True, readable=True)]):
12
+
13
+ print(f"[bold green]Reading:[/bold green] {inname}")
14
+ with open(inname, "r") as f:
15
+ stinger = StingerInterface.from_yaml(f)
16
+ params = {
17
+ "stinger": stinger,
18
+ }
19
+ t = jj2.CodeTemplator(output_dir=os.path.dirname(outdir))
20
+ t.add_template_dir(
21
+ os.path.join(os.path.dirname(__file__), "../templates", "python")
22
+ )
23
+ for output_file in [
24
+ "pyproject.toml",
25
+ ]:
26
+ print(f"[bold red]Generating:[/bold red] {output_file}")
27
+ t.render_template(f"{output_file}.jinja2", os.path.join(outdir, output_file), **params)
28
+
29
+ package_name = f"{stringmanip.lower_camel_case(stinger.name).lower()}ipc"
30
+ generated_pkg_dir = os.path.join(outdir, package_name)
31
+ print(f"[bold red]Making Directory:[/bold red] {generated_pkg_dir}")
32
+ os.makedirs(generated_pkg_dir, exist_ok=True)
33
+ for output_file in [
34
+ "server.py",
35
+ "client.py",
36
+ "connection.py",
37
+ "__init__.py",
38
+ "method_codes.py",
39
+ ]:
40
+ print(f"[bold red]Generating:[/bold red] {output_file}")
41
+ t.render_template(f"{output_file}.jinja2", os.path.join(generated_pkg_dir, output_file), **params)
42
+
43
+ t.render_template("interface_types.py.jinja2", os.path.join(generated_pkg_dir, f"{stinger.get_enum_module_name()}.py"), **params)
44
+
45
+ def run():
46
+ typer.run(main)
47
+
48
+ if __name__ == "__main__":
49
+ run()
@@ -1,4 +0,0 @@
1
- [console_scripts]
2
- markdowngen = stingeripc.tools.markdown_generator:main
3
- pythongen = stingeripc.tools.python_generator:main
4
- rustgen = stingeripc.tools.rust_generator:main
@@ -1,41 +0,0 @@
1
- from jacobsjinjatoo import templator as jj2
2
- import sys
3
- import yaml
4
- import os.path
5
-
6
-
7
-
8
- from stingeripc import StingerInterface
9
-
10
- def main():
11
- inname = sys.argv[1]
12
- outdir = sys.argv[2]
13
- with open(inname, "r") as f:
14
- stinger = StingerInterface.from_yaml(f)
15
- params = {
16
- "stinger": stinger,
17
- }
18
- t = jj2.CodeTemplator(output_dir=os.path.dirname(outdir))
19
- t.add_template_dir(
20
- os.path.join(os.path.dirname(__file__), "../templates", "python")
21
- )
22
- for output_file in [
23
- "pyproject.toml",
24
- ]:
25
- t.render_template(f"{output_file}.jinja2", output_file, **params)
26
-
27
- generated_src_dir = os.path.join(outdir, stinger.name.lower())
28
- os.makedirs(generated_src_dir, exist_ok=True)
29
- for output_file in [
30
- "server.py",
31
- "client.py",
32
- "connection.py",
33
- "__init__.py",
34
- "method_codes.py",
35
- ]:
36
- t.render_template(f"{output_file}.jinja2", os.path.join(stinger.name.lower(), output_file), **params)
37
-
38
- t.render_template("interface_types.py.jinja2", os.path.join(stinger.name.lower(), f"{stinger.get_enum_module_name()}.py"), **params)
39
-
40
- if __name__ == "__main__":
41
- main()
File without changes
File without changes
File without changes