update stereotype

This commit is contained in:
2025-10-21 20:09:51 +08:00
parent faaa8bb357
commit 6d0ac475ba
5 changed files with 47 additions and 51 deletions

View File

@@ -40,43 +40,41 @@ def component(component_type, component_name, comment=None):
return cls
return decorator
runner_classes = {}
runner_comments = {}
def runner(runner_name, comment=None):
def decorator(cls):
if not hasattr(cls, 'run') or not callable(getattr(cls, 'run')):
Log.error(f"runner <{cls.__name__}> must implement a 'run' method", True)
cls = ensure_component_subclass(cls, "RUNNER", runner_name)
runner_classes[runner_name] = cls
runner_comments[runner_name] = comment
if "runner" not in all_component_classes:
register_component_type("runner")
all_component_classes["runner"][runner_name] = cls
all_component_comments["runner"][runner_name] = comment
return cls
return decorator
factory_classes = {}
factory_comments = {}
def factory(factory_name, comment=None):
def decorator(cls):
if not hasattr(cls, 'create') or not callable(getattr(cls, 'create')):
Log.error(f"factory <{cls.__name__}> must implement a 'create' method", True)
cls = ensure_component_subclass(cls, "FACTORY", factory_name)
factory_classes[factory_name] = cls
factory_comments[factory_name] = comment
if "factory" not in all_component_classes:
register_component_type("factory")
all_component_classes["factory"][factory_name] = cls
all_component_comments["factory"][factory_name] = comment
return cls
return decorator
client_classes = {}
client_comments = {}
def client(client_name, comment=None):
def decorator(cls):
cls = ensure_component_subclass(cls, "CLIENT", client_name)
client_classes[client_name] = cls
client_comments[client_name] = comment
if "client" not in all_component_classes:
register_component_type("client")
all_component_classes["client"][client_name] = cls
all_component_comments["client"][client_name] = comment
return cls
return decorator
server_classes = {}
server_comments = {}
def server(server_name, comment=None):
def decorator(cls):
cls = ensure_component_subclass(cls, "SERVER", server_name)
@@ -84,18 +82,15 @@ def server(server_name, comment=None):
Log.error(f"server <{cls.__name__}> must implement 'host' and 'port' attributes", True)
if not hasattr(cls, 'serve') or not callable(getattr(cls, 'serve')):
Log.error(f"server <{cls.__name__}> must implement a 'serve' method", True)
server_classes[server_name] = cls
server_comments[server_name] = comment
if "server" not in all_component_classes:
register_component_type("server")
all_component_classes["server"][server_name] = cls
all_component_comments["server"][server_name] = comment
return cls
return decorator
# --- Utils --- #
register_component_type("RUNNER")
register_component_type("FACTORY")
register_component_type("CLIENT")
register_component_type("SERVER")
def get_all_component_classes():
return all_component_classes

View File

@@ -1,10 +1,9 @@
Metadata-Version: 1.0
Metadata-Version: 2.4
Name: pyboot
Version: 0.2
Summary: UNKNOWN
Home-page: UNKNOWN
Author: UNKNOWN
Author-email: UNKNOWN
License: UNKNOWN
Description: UNKNOWN
Platform: UNKNOWN
Requires-Dist: pyyaml
Requires-Dist: psutil
Requires-Dist: GPUtil
Requires-Dist: flask
Requires-Dist: flask_cors
Dynamic: requires-dist

View File

@@ -1,5 +1,13 @@
.gitignore
README.md
setup.py
__pycache__/setup.cpython-39.pyc
pyapp.egg-info/PKG-INFO
pyapp.egg-info/SOURCES.txt
pyapp.egg-info/dependency_links.txt
pyapp.egg-info/entry_points.txt
pyapp.egg-info/requires.txt
pyapp.egg-info/top_level.txt
pyboot/__init__.py
pyboot/application.py
pyboot/boot.py

View File

@@ -1,4 +1,3 @@
[console_scripts]
pb = pyboot.boot:main
pyboot = pyboot.boot:main

View File

@@ -40,43 +40,41 @@ def component(component_type, component_name, comment=None):
return cls
return decorator
runner_classes = {}
runner_comments = {}
def runner(runner_name, comment=None):
def decorator(cls):
if not hasattr(cls, 'run') or not callable(getattr(cls, 'run')):
Log.error(f"runner <{cls.__name__}> must implement a 'run' method", True)
cls = ensure_component_subclass(cls, "RUNNER", runner_name)
runner_classes[runner_name] = cls
runner_comments[runner_name] = comment
if "runner" not in all_component_classes:
register_component_type("runner")
all_component_classes["runner"][runner_name] = cls
all_component_comments["runner"][runner_name] = comment
return cls
return decorator
factory_classes = {}
factory_comments = {}
def factory(factory_name, comment=None):
def decorator(cls):
if not hasattr(cls, 'create') or not callable(getattr(cls, 'create')):
Log.error(f"factory <{cls.__name__}> must implement a 'create' method", True)
cls = ensure_component_subclass(cls, "FACTORY", factory_name)
factory_classes[factory_name] = cls
factory_comments[factory_name] = comment
if "factory" not in all_component_classes:
register_component_type("factory")
all_component_classes["factory"][factory_name] = cls
all_component_comments["factory"][factory_name] = comment
return cls
return decorator
client_classes = {}
client_comments = {}
def client(client_name, comment=None):
def decorator(cls):
cls = ensure_component_subclass(cls, "CLIENT", client_name)
client_classes[client_name] = cls
client_comments[client_name] = comment
if "client" not in all_component_classes:
register_component_type("client")
all_component_classes["client"][client_name] = cls
all_component_comments["client"][client_name] = comment
return cls
return decorator
server_classes = {}
server_comments = {}
def server(server_name, comment=None):
def decorator(cls):
cls = ensure_component_subclass(cls, "SERVER", server_name)
@@ -84,18 +82,15 @@ def server(server_name, comment=None):
Log.error(f"server <{cls.__name__}> must implement 'host' and 'port' attributes", True)
if not hasattr(cls, 'serve') or not callable(getattr(cls, 'serve')):
Log.error(f"server <{cls.__name__}> must implement a 'serve' method", True)
server_classes[server_name] = cls
server_comments[server_name] = comment
if "server" not in all_component_classes:
register_component_type("server")
all_component_classes["server"][server_name] = cls
all_component_comments["server"][server_name] = comment
return cls
return decorator
# --- Utils --- #
register_component_type("RUNNER")
register_component_type("FACTORY")
register_component_type("CLIENT")
register_component_type("SERVER")
def get_all_component_classes():
return all_component_classes