uns-kit 0.0.6__tar.gz → 0.0.8__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.
- {uns_kit-0.0.6 → uns_kit-0.0.8}/PKG-INFO +1 -1
- {uns_kit-0.0.6 → uns_kit-0.0.8}/pyproject.toml +1 -1
- {uns_kit-0.0.6 → uns_kit-0.0.8}/src/uns_kit/cli.py +22 -2
- {uns_kit-0.0.6 → uns_kit-0.0.8}/src/uns_kit/config.py +21 -3
- uns_kit-0.0.8/src/uns_kit/templates/default/main.py +34 -0
- uns_kit-0.0.8/src/uns_kit/templates/default/package.json +6 -0
- {uns_kit-0.0.6 → uns_kit-0.0.8}/src/uns_kit/templates/default/pyproject.toml +1 -1
- uns_kit-0.0.8/src/uns_kit/templates/default/runtime.json +4 -0
- uns_kit-0.0.8/src/uns_kit/templates/default/uns_py_app/__init__.py +1 -0
- {uns_kit-0.0.6 → uns_kit-0.0.8}/README.md +0 -0
- {uns_kit-0.0.6 → uns_kit-0.0.8}/src/uns_kit/__init__.py +0 -0
- {uns_kit-0.0.6 → uns_kit-0.0.8}/src/uns_kit/client.py +0 -0
- {uns_kit-0.0.6 → uns_kit-0.0.8}/src/uns_kit/packet.py +0 -0
- {uns_kit-0.0.6 → uns_kit-0.0.8}/src/uns_kit/proxy.py +0 -0
- {uns_kit-0.0.6 → uns_kit-0.0.8}/src/uns_kit/proxy_process.py +0 -0
- {uns_kit-0.0.6 → uns_kit-0.0.8}/src/uns_kit/status_monitor.py +0 -0
- {uns_kit-0.0.6 → uns_kit-0.0.8}/src/uns_kit/templates/default/README.md +0 -0
- {uns_kit-0.0.6 → uns_kit-0.0.8}/src/uns_kit/templates/default/src/data_example.py +0 -0
- {uns_kit-0.0.6 → uns_kit-0.0.8}/src/uns_kit/templates/default/src/load_test.py +0 -0
- {uns_kit-0.0.6 → uns_kit-0.0.8}/src/uns_kit/topic_builder.py +0 -0
- {uns_kit-0.0.6 → uns_kit-0.0.8}/src/uns_kit/uns_mqtt_proxy.py +0 -0
- {uns_kit-0.0.6 → uns_kit-0.0.8}/src/uns_kit/version.py +0 -0
|
@@ -128,9 +128,30 @@ async def _run_subscribe(
|
|
|
128
128
|
def create(dest: str):
|
|
129
129
|
template_root = importlib.resources.files("uns_kit").joinpath("templates/default")
|
|
130
130
|
dest_path = os.path.abspath(dest)
|
|
131
|
+
project_name = Path(dest_path).name
|
|
132
|
+
package_version = "0.0.0"
|
|
131
133
|
if os.path.exists(dest_path):
|
|
132
134
|
raise click.ClickException(f"Destination already exists: {dest_path}")
|
|
133
135
|
shutil.copytree(template_root, dest_path)
|
|
136
|
+
# personalize config with project name
|
|
137
|
+
config_path = Path(dest_path) / "config.json"
|
|
138
|
+
if config_path.exists():
|
|
139
|
+
try:
|
|
140
|
+
data = json.loads(config_path.read_text())
|
|
141
|
+
data.setdefault("uns", {}) # keep structure for processName, etc.
|
|
142
|
+
config_path.write_text(json.dumps(data, indent=2))
|
|
143
|
+
except Exception:
|
|
144
|
+
pass
|
|
145
|
+
# personalize package.json for PM2 metadata
|
|
146
|
+
pkg_path = Path(dest_path) / "package.json"
|
|
147
|
+
if pkg_path.exists():
|
|
148
|
+
try:
|
|
149
|
+
pkg_data = json.loads(pkg_path.read_text())
|
|
150
|
+
pkg_data["name"] = project_name
|
|
151
|
+
pkg_data["version"] = package_version
|
|
152
|
+
pkg_path.write_text(json.dumps(pkg_data, indent=2))
|
|
153
|
+
except Exception:
|
|
154
|
+
pass
|
|
134
155
|
click.echo(f"Created UNS Python app at {dest_path}")
|
|
135
156
|
click.echo("Next steps:")
|
|
136
157
|
click.echo(f" 1) cd {dest_path}")
|
|
@@ -142,6 +163,7 @@ def create(dest: str):
|
|
|
142
163
|
@cli.command("write-config", help="Write a minimal config.json scaffold.")
|
|
143
164
|
@click.option("--path", default="config.json", show_default=True)
|
|
144
165
|
def write_config(path: str):
|
|
166
|
+
project_name = Path(path).resolve().parent.name
|
|
145
167
|
data = {
|
|
146
168
|
"infra": {
|
|
147
169
|
"host": "localhost",
|
|
@@ -155,8 +177,6 @@ def write_config(path: str):
|
|
|
155
177
|
"clean": True
|
|
156
178
|
},
|
|
157
179
|
"uns": {
|
|
158
|
-
"packageName": "uns-kit",
|
|
159
|
-
"packageVersion": "0.0.1",
|
|
160
180
|
"processName": "uns-process"
|
|
161
181
|
}
|
|
162
182
|
}
|
|
@@ -3,7 +3,7 @@ from __future__ import annotations
|
|
|
3
3
|
import json
|
|
4
4
|
from dataclasses import dataclass
|
|
5
5
|
from pathlib import Path
|
|
6
|
-
from typing import List, Optional
|
|
6
|
+
from typing import List, Optional, Tuple
|
|
7
7
|
|
|
8
8
|
from .topic_builder import TopicBuilder
|
|
9
9
|
from .version import __version__
|
|
@@ -34,6 +34,7 @@ class UnsConfig:
|
|
|
34
34
|
|
|
35
35
|
infra = data.get("infra", {}) or {}
|
|
36
36
|
uns_section = data.get("uns", {}) or {}
|
|
37
|
+
pkg_name, pkg_version = _read_package_metadata(path)
|
|
37
38
|
|
|
38
39
|
proto = (infra.get("protocol") or "").lower()
|
|
39
40
|
tls = proto in ("mqtts", "ssl", "wss")
|
|
@@ -52,8 +53,8 @@ class UnsConfig:
|
|
|
52
53
|
mqtt_sub_to_topics=infra.get("mqttSubToTopics"),
|
|
53
54
|
keepalive=infra.get("keepalive", 60),
|
|
54
55
|
clean_session=infra.get("clean", True),
|
|
55
|
-
package_name=uns_section.get("packageName"
|
|
56
|
-
package_version=uns_section.get("packageVersion") or __version__,
|
|
56
|
+
package_name=uns_section.get("packageName") or pkg_name or "uns-kit",
|
|
57
|
+
package_version=uns_section.get("packageVersion") or pkg_version or __version__,
|
|
57
58
|
process_name=uns_section.get("processName", "uns-process"),
|
|
58
59
|
)
|
|
59
60
|
|
|
@@ -88,3 +89,20 @@ class UnsConfig:
|
|
|
88
89
|
|
|
89
90
|
def _none_if_empty(value: Optional[str]) -> Optional[str]:
|
|
90
91
|
return None if value == "" else value
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
def _read_package_metadata(config_path: Path) -> Tuple[Optional[str], Optional[str]]:
|
|
95
|
+
"""
|
|
96
|
+
Read name/version from the nearest package.json beside the config (if present).
|
|
97
|
+
Falls back to None when not available or invalid.
|
|
98
|
+
"""
|
|
99
|
+
pkg_path = config_path.parent / "package.json"
|
|
100
|
+
if not pkg_path.exists():
|
|
101
|
+
return None, None
|
|
102
|
+
try:
|
|
103
|
+
pkg = json.loads(pkg_path.read_text())
|
|
104
|
+
name = pkg.get("name")
|
|
105
|
+
version = pkg.get("version")
|
|
106
|
+
return (name if isinstance(name, str) else None, version if isinstance(version, str) else None)
|
|
107
|
+
except Exception:
|
|
108
|
+
return None, None
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import asyncio
|
|
2
|
+
import json
|
|
3
|
+
from pathlib import Path
|
|
4
|
+
|
|
5
|
+
from uns_kit import UnsMqttClient, UnsPacket, TopicBuilder, UnsConfig
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
async def run():
|
|
9
|
+
# Load TS-style nested config
|
|
10
|
+
cfg = UnsConfig.load(Path("config.json"))
|
|
11
|
+
tb = cfg.topic_builder()
|
|
12
|
+
|
|
13
|
+
client = UnsMqttClient(
|
|
14
|
+
cfg.host,
|
|
15
|
+
port=cfg.port,
|
|
16
|
+
username=cfg.username,
|
|
17
|
+
password=cfg.password,
|
|
18
|
+
tls=cfg.tls,
|
|
19
|
+
client_id=cfg.client_id or f"{cfg.process_name}-py",
|
|
20
|
+
topic_builder=tb,
|
|
21
|
+
reconnect_interval=1,
|
|
22
|
+
)
|
|
23
|
+
await client.connect()
|
|
24
|
+
|
|
25
|
+
# Publish a startup heartbeat to raw/data/ (can be changed)
|
|
26
|
+
await client.publish_packet("raw/data/", UnsPacket.data(value="started", uom="state"))
|
|
27
|
+
|
|
28
|
+
# Idle loop; adjust to your workload
|
|
29
|
+
while True:
|
|
30
|
+
await asyncio.sleep(5)
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
if __name__ == "__main__":
|
|
34
|
+
asyncio.run(run())
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# Placeholder package so Poetry can build a wheel.
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|