ephaptic 0.2.2__py3-none-any.whl → 0.2.3__py3-none-any.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.
- ephaptic/cli/__main__.py +34 -8
- {ephaptic-0.2.2.dist-info → ephaptic-0.2.3.dist-info}/METADATA +2 -1
- {ephaptic-0.2.2.dist-info → ephaptic-0.2.3.dist-info}/RECORD +7 -7
- {ephaptic-0.2.2.dist-info → ephaptic-0.2.3.dist-info}/WHEEL +0 -0
- {ephaptic-0.2.2.dist-info → ephaptic-0.2.3.dist-info}/entry_points.txt +0 -0
- {ephaptic-0.2.2.dist-info → ephaptic-0.2.3.dist-info}/licenses/LICENSE +0 -0
- {ephaptic-0.2.2.dist-info → ephaptic-0.2.3.dist-info}/top_level.txt +0 -0
ephaptic/cli/__main__.py
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import sys, os, json, inspect, importlib, typing, typer
|
|
1
|
+
import sys, os, json, inspect, importlib, typing, typer, subprocess as sp
|
|
2
2
|
|
|
3
3
|
from pathlib import Path
|
|
4
4
|
from pydantic import TypeAdapter
|
|
@@ -16,8 +16,8 @@ def load_ephaptic(import_name: str) -> Ephaptic:
|
|
|
16
16
|
sys.path.insert(0, os.getcwd())
|
|
17
17
|
|
|
18
18
|
if ":" not in import_name:
|
|
19
|
-
typer.secho(f"Warning: Import name did not specify
|
|
20
|
-
import_name += ":
|
|
19
|
+
typer.secho(f"Warning: Import name did not specify client name. Defaulting to `client`.", fg=typer.colors.YELLOW)
|
|
20
|
+
import_name += ":client" # default: expect client to be named `client` inside the file
|
|
21
21
|
|
|
22
22
|
module_name, var_name = import_name.split(":", 1)
|
|
23
23
|
|
|
@@ -35,7 +35,7 @@ def load_ephaptic(import_name: str) -> Ephaptic:
|
|
|
35
35
|
raise typer.Exit(1)
|
|
36
36
|
|
|
37
37
|
if not isinstance(instance, Ephaptic):
|
|
38
|
-
typer.secho(f"Error: '{var_name}' is not an Ephaptic
|
|
38
|
+
typer.secho(f"Error: '{var_name}' is not an Ephaptic client. It is type: {type(instance)}", fg=typer.colors.RED)
|
|
39
39
|
raise typer.Exit(1)
|
|
40
40
|
|
|
41
41
|
return instance
|
|
@@ -53,12 +53,31 @@ def create_schema(adapter: TypeAdapter, definitions: dict) -> dict:
|
|
|
53
53
|
|
|
54
54
|
return schema
|
|
55
55
|
|
|
56
|
+
def run_subprocess():
|
|
57
|
+
cmd = [sys.executable]
|
|
58
|
+
cmd += [arg for arg in sys.argv if arg not in {'--watch', '-w'}]
|
|
59
|
+
sp.run(cmd)
|
|
60
|
+
|
|
56
61
|
@app.command()
|
|
57
62
|
def generate(
|
|
58
|
-
|
|
59
|
-
output: Path = typer.Option('schema.json', '--output', '-o', help="Output path for the JSON schema.")
|
|
63
|
+
client: str = typer.Argument('client:client', help="The import string for the Ephaptic client."),
|
|
64
|
+
output: Path = typer.Option('schema.json', '--output', '-o', help="Output path for the JSON schema."),
|
|
65
|
+
watch: bool = typer.Option(False, '--watch', '-w', help="Watch for changes in `.py` files and regenerate schema file automatically."),
|
|
60
66
|
):
|
|
61
|
-
|
|
67
|
+
if watch:
|
|
68
|
+
import watchfiles
|
|
69
|
+
|
|
70
|
+
cwd = os.getcwd()
|
|
71
|
+
typer.secho(f"Watching for changes ({cwd})...", fg=typer.colors.GREEN)
|
|
72
|
+
|
|
73
|
+
run_subprocess()
|
|
74
|
+
|
|
75
|
+
for changes in watchfiles.watch(cwd):
|
|
76
|
+
if any(f.endswith('.py') for _, f in changes):
|
|
77
|
+
typer.secho("Detected changes, regenerating...")
|
|
78
|
+
run_subprocess()
|
|
79
|
+
|
|
80
|
+
ephaptic = load_ephaptic(client)
|
|
62
81
|
|
|
63
82
|
typer.secho(f"Found {len(ephaptic._exposed_functions)} functions.", fg=typer.colors.GREEN)
|
|
64
83
|
|
|
@@ -97,8 +116,15 @@ def generate(
|
|
|
97
116
|
|
|
98
117
|
schema_output["methods"][name] = method_schema
|
|
99
118
|
|
|
119
|
+
new = json.dumps(schema_output, indent=2)
|
|
120
|
+
|
|
121
|
+
if output.exists():
|
|
122
|
+
old = output.read_text()
|
|
123
|
+
if old == new:
|
|
124
|
+
return
|
|
125
|
+
|
|
100
126
|
with open(output, "w") as f:
|
|
101
|
-
|
|
127
|
+
f.write(new)
|
|
102
128
|
|
|
103
129
|
typer.secho(f"Schema generated to `{output}`.", fg=typer.colors.GREEN, bold=True)
|
|
104
130
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: ephaptic
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.3
|
|
4
4
|
Summary: The Python client/server package for ephaptic.
|
|
5
5
|
Author-email: uukelele <robustrobot11@gmail.com>
|
|
6
6
|
License: MIT License
|
|
@@ -36,6 +36,7 @@ Requires-Dist: websockets>=12.0
|
|
|
36
36
|
Requires-Dist: pydantic>=2.0
|
|
37
37
|
Requires-Dist: typer[standard]>=0.20.0
|
|
38
38
|
Requires-Dist: python-dotenv
|
|
39
|
+
Requires-Dist: watchfiles
|
|
39
40
|
Provides-Extra: server
|
|
40
41
|
Requires-Dist: redis; extra == "server"
|
|
41
42
|
Dynamic: license-file
|
|
@@ -5,15 +5,15 @@ ephaptic/adapters/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU
|
|
|
5
5
|
ephaptic/adapters/fastapi_.py,sha256=yfSbJuA7Tgeh9EhZkfIve0Uj-cOZmTBljlBsCRKh2EE,1007
|
|
6
6
|
ephaptic/adapters/quart_.py,sha256=MBo9g6h_zI63mL4aGdrvV5yEXsHaOd0Iv5J8SAPHBoA,537
|
|
7
7
|
ephaptic/cli/__init__.py,sha256=p_mYumuQLr3HZa-6I4QKut6khZv3WQjEX-B-aa4cdEE,44
|
|
8
|
-
ephaptic/cli/__main__.py,sha256=
|
|
8
|
+
ephaptic/cli/__main__.py,sha256=fbfEGUnufc7vO65ZHnCV7YSshlHyif1c3kzR7vSp9GM,4218
|
|
9
9
|
ephaptic/client/__init__.py,sha256=NeaPIzTFeozP54wlDYHIg_adHP3Z3LWVujsRUlpn4_U,35
|
|
10
10
|
ephaptic/client/client.py,sha256=YYAlzA40xBvWsiDu0Gsd1EBJaqivLR-bSszepWdNODs,4181
|
|
11
11
|
ephaptic/transports/__init__.py,sha256=kSAlgvm8sV9nHHu61LTjjTpv4bweah90xvFrwQMDQtQ,169
|
|
12
12
|
ephaptic/transports/fastapi_ws.py,sha256=X0PMRcwM-KDpKA-zXShGTFhD1kHMSqrx3PBBKZtQ1W0,258
|
|
13
13
|
ephaptic/transports/websocket.py,sha256=jwgclSDSq0lQCvgwjwUXe9MzPk7NH0FdmsLhWxYBh-4,261
|
|
14
|
-
ephaptic-0.2.
|
|
15
|
-
ephaptic-0.2.
|
|
16
|
-
ephaptic-0.2.
|
|
17
|
-
ephaptic-0.2.
|
|
18
|
-
ephaptic-0.2.
|
|
19
|
-
ephaptic-0.2.
|
|
14
|
+
ephaptic-0.2.3.dist-info/licenses/LICENSE,sha256=kMpJjLKMj6zsAhf4uHApO4q0r31Ye1VyfBOl9cFW13M,1065
|
|
15
|
+
ephaptic-0.2.3.dist-info/METADATA,sha256=ZokQJXZp3r4icuY3F8IRpqALNpEZXrCOLkgv8l2lHvk,7783
|
|
16
|
+
ephaptic-0.2.3.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
17
|
+
ephaptic-0.2.3.dist-info/entry_points.txt,sha256=lis9vIDIrMVJM43r9ooFkb07KhrX4946duvYru3VfT4,46
|
|
18
|
+
ephaptic-0.2.3.dist-info/top_level.txt,sha256=nNhdhcz2o_IuwZ9I2uWQuLZrRmSW0dQVU3qwGrb35Io,9
|
|
19
|
+
ephaptic-0.2.3.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|