aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/conventionalrp
diff options
context:
space:
mode:
authorHsiangNianian <i@jyunko.cn>2025-03-15 16:35:39 +0800
committerHsiangNianian <i@jyunko.cn>2025-03-15 16:35:39 +0800
commit965771fb0d85ddb27dc6c5dd7df822d1fb318286 (patch)
treef33a0d36e5716da13be0e3a4134cf7359ebe5223 /src/conventionalrp
parent818d84a7bf00c07b7ab252dda5bfa70a98b8be65 (diff)
downloadconventional_role_play-965771fb0d85ddb27dc6c5dd7df822d1fb318286.tar.gz
conventional_role_play-965771fb0d85ddb27dc6c5dd7df822d1fb318286.zip
refactor: clean up code formatting and add new PluginManager class
Diffstat (limited to 'src/conventionalrp')
-rw-r--r--src/conventionalrp/__main__.py2
-rw-r--r--src/conventionalrp/_core.pyi2
-rw-r--r--src/conventionalrp/core/__init__.py2
-rw-r--r--src/conventionalrp/core/parser.py7
-rw-r--r--src/conventionalrp/core/processor.py15
-rw-r--r--src/conventionalrp/extractors/__init__.py2
-rw-r--r--src/conventionalrp/extractors/base.py2
-rw-r--r--src/conventionalrp/extractors/rule_extractor.py5
-rw-r--r--src/conventionalrp/plugins/__init__.py2
-rw-r--r--src/conventionalrp/plugins/plugin_manager.py19
-rw-r--r--src/conventionalrp/renderers/__init__.py2
-rw-r--r--src/conventionalrp/renderers/base.py2
-rw-r--r--src/conventionalrp/renderers/html_renderer.py11
-rw-r--r--src/conventionalrp/renderers/json_renderer.py4
-rw-r--r--src/conventionalrp/renderers/markdown_renderer.py9
-rw-r--r--src/conventionalrp/utils/__init__.py2
16 files changed, 60 insertions, 28 deletions
diff --git a/src/conventionalrp/__main__.py b/src/conventionalrp/__main__.py
index 01b510d..fa4f45e 100644
--- a/src/conventionalrp/__main__.py
+++ b/src/conventionalrp/__main__.py
@@ -1,7 +1,9 @@
from ._core import sum_as_string
+
def main():
print(sum_as_string(1, 2))
+
if __name__ == "__main__":
main()
diff --git a/src/conventionalrp/_core.pyi b/src/conventionalrp/_core.pyi
index 8a0cc40..0805887 100644
--- a/src/conventionalrp/_core.pyi
+++ b/src/conventionalrp/_core.pyi
@@ -1,3 +1,3 @@
def sum_as_string(a: int, b: int) -> str: ...
-class Base: ... \ No newline at end of file
+class Base: ...
diff --git a/src/conventionalrp/core/__init__.py b/src/conventionalrp/core/__init__.py
index d63b2a9..cc59ba4 100644
--- a/src/conventionalrp/core/__init__.py
+++ b/src/conventionalrp/core/__init__.py
@@ -1,4 +1,4 @@
# FILE: /trpg-log-processor/trpg-log-processor/src/conventionalrp/core/__init__.py
"""
This file initializes the core module of the conventionalrp SDK.
-""" \ No newline at end of file
+"""
diff --git a/src/conventionalrp/core/parser.py b/src/conventionalrp/core/parser.py
index 266506b..d5b91da 100644
--- a/src/conventionalrp/core/parser.py
+++ b/src/conventionalrp/core/parser.py
@@ -2,18 +2,19 @@ import json
import re
from pathlib import Path
+
class Parser:
def __init__(self):
self.rules = []
- def load_rules(self, rules_path : str):
+ def load_rules(self, rules_path: str):
"""Load parsing rules."""
if not Path(rules_path).exists():
raise FileNotFoundError(f"No such file or directory: {rules_path} ")
with open(rules_path, "r", encoding="utf-8") as f:
file_content = f.read()
-
+
rules = json.loads(file_content)
# validation rule format
@@ -53,4 +54,4 @@ class Parser:
else:
parsed_data.append({"content": line.strip(), "type": "unknown"})
- return parsed_data \ No newline at end of file
+ return parsed_data
diff --git a/src/conventionalrp/core/processor.py b/src/conventionalrp/core/processor.py
index 40033cf..4e2f573 100644
--- a/src/conventionalrp/core/processor.py
+++ b/src/conventionalrp/core/processor.py
@@ -17,23 +17,28 @@ class Processor:
def generate_output(self, processed_data, format_type):
# Implement output generation logic based on format_type
- if format_type == 'json':
+ if format_type == "json":
return self.generate_json_output(processed_data)
- elif format_type == 'html':
+ elif format_type == "html":
return self.generate_html_output(processed_data)
- elif format_type == 'markdown':
+ elif format_type == "markdown":
return self.generate_markdown_output(processed_data)
else:
raise ValueError("Unsupported format type")
def generate_json_output(self, processed_data):
import json
+
return json.dumps(processed_data)
def generate_html_output(self, processed_data):
# Implement HTML output generation
- return "<html><body>" + "".join(f"<p>{data}</p>" for data in processed_data) + "</body></html>"
+ return (
+ "<html><body>"
+ + "".join(f"<p>{data}</p>" for data in processed_data)
+ + "</body></html>"
+ )
def generate_markdown_output(self, processed_data):
# Implement Markdown output generation
- return "\n".join(f"- {data}" for data in processed_data) \ No newline at end of file
+ return "\n".join(f"- {data}" for data in processed_data)
diff --git a/src/conventionalrp/extractors/__init__.py b/src/conventionalrp/extractors/__init__.py
index c076f07..8606862 100644
--- a/src/conventionalrp/extractors/__init__.py
+++ b/src/conventionalrp/extractors/__init__.py
@@ -1,4 +1,4 @@
# FILE: /trpg-log-processor/trpg-log-processor/src/conventionalrp/extractors/__init__.py
"""
This file initializes the extractors module.
-""" \ No newline at end of file
+"""
diff --git a/src/conventionalrp/extractors/base.py b/src/conventionalrp/extractors/base.py
index fc42f29..bc3c41f 100644
--- a/src/conventionalrp/extractors/base.py
+++ b/src/conventionalrp/extractors/base.py
@@ -6,4 +6,4 @@ class BaseExtractor:
raise NotImplementedError("Subclasses should implement this method.")
def load_rules(self, rules_source):
- raise NotImplementedError("Subclasses should implement this method.") \ No newline at end of file
+ raise NotImplementedError("Subclasses should implement this method.")
diff --git a/src/conventionalrp/extractors/rule_extractor.py b/src/conventionalrp/extractors/rule_extractor.py
index 78e8505..b0d03d5 100644
--- a/src/conventionalrp/extractors/rule_extractor.py
+++ b/src/conventionalrp/extractors/rule_extractor.py
@@ -13,7 +13,8 @@ class RuleExtractor(BaseExtractor):
def load_rules_from_file(self):
import json
- with open(self.config_file, 'r') as file:
+
+ with open(self.config_file, "r") as file:
return json.load(file)
def extract(self):
@@ -21,4 +22,4 @@ class RuleExtractor(BaseExtractor):
extracted_rules = []
for rule in self.rules:
extracted_rules.append(rule) # Placeholder for actual extraction logic
- return extracted_rules \ No newline at end of file
+ return extracted_rules
diff --git a/src/conventionalrp/plugins/__init__.py b/src/conventionalrp/plugins/__init__.py
index 9f1a11b..a7e5268 100644
--- a/src/conventionalrp/plugins/__init__.py
+++ b/src/conventionalrp/plugins/__init__.py
@@ -1,4 +1,4 @@
# FILE: /trpg-log-processor/trpg-log-processor/src/conventionalrp/plugins/__init__.py
"""
This file initializes the plugins module.
-""" \ No newline at end of file
+"""
diff --git a/src/conventionalrp/plugins/plugin_manager.py b/src/conventionalrp/plugins/plugin_manager.py
index e69de29..0d49a9c 100644
--- a/src/conventionalrp/plugins/plugin_manager.py
+++ b/src/conventionalrp/plugins/plugin_manager.py
@@ -0,0 +1,19 @@
+import os
+import importlib
+
+
+class PluginManager:
+ def __init__(self, plugin_dir: str):
+ self.plugin_dir = plugin_dir
+ self.plugins = []
+
+ def load_plugins(self):
+ for plugin in os.listdir(self.plugin_dir):
+ if plugin.endswith(".py"):
+ plugin_name = plugin.split(".")[0]
+ module = importlib.import_module(f"{self.plugin_dir}.{plugin_name}")
+ self.plugins.append(module)
+
+ def run_plugins(self):
+ for plugin in self.plugins:
+ plugin.run()
diff --git a/src/conventionalrp/renderers/__init__.py b/src/conventionalrp/renderers/__init__.py
index 7838674..06f0f73 100644
--- a/src/conventionalrp/renderers/__init__.py
+++ b/src/conventionalrp/renderers/__init__.py
@@ -1,4 +1,4 @@
# FILE: /trpg-log-processor/trpg-log-processor/src/conventionalrp/renderers/__init__.py
"""
This file initializes the renderers module.
-""" \ No newline at end of file
+"""
diff --git a/src/conventionalrp/renderers/base.py b/src/conventionalrp/renderers/base.py
index 498adec..595f9bf 100644
--- a/src/conventionalrp/renderers/base.py
+++ b/src/conventionalrp/renderers/base.py
@@ -3,4 +3,4 @@ class BaseRenderer:
raise NotImplementedError("Render method must be implemented by subclasses.")
def set_style(self, style):
- self.style = style \ No newline at end of file
+ self.style = style
diff --git a/src/conventionalrp/renderers/html_renderer.py b/src/conventionalrp/renderers/html_renderer.py
index 3c30549..75efcd3 100644
--- a/src/conventionalrp/renderers/html_renderer.py
+++ b/src/conventionalrp/renderers/html_renderer.py
@@ -1,21 +1,22 @@
from .base import BaseRenderer
+
class HTMLRenderer(BaseRenderer):
def __init__(self):
super().__init__()
self.title = "TRPG Log Output"
-
+
def render(self, data):
html_content = f"<html><head><title>{self.title}</title></head><body>"
html_content += "<h1>TRPG Log Output</h1>"
html_content += "<ul>"
-
+
for entry in data:
html_content += f"<li>{entry}</li>"
-
+
html_content += "</ul></body></html>"
return html_content
-
+
def set_style(self, style):
# Implement style setting if needed
- pass \ No newline at end of file
+ pass
diff --git a/src/conventionalrp/renderers/json_renderer.py b/src/conventionalrp/renderers/json_renderer.py
index 4313001..8dcdd6d 100644
--- a/src/conventionalrp/renderers/json_renderer.py
+++ b/src/conventionalrp/renderers/json_renderer.py
@@ -1,9 +1,11 @@
from .base import BaseRenderer
+
class JSONRenderer(BaseRenderer):
def render(self, data):
import json
+
return json.dumps(data, ensure_ascii=False, indent=4)
def set_style(self, style):
- self.style = style # Placeholder for potential styling options in the future \ No newline at end of file
+ self.style = style # Placeholder for potential styling options in the future
diff --git a/src/conventionalrp/renderers/markdown_renderer.py b/src/conventionalrp/renderers/markdown_renderer.py
index 396d6a4..fab429f 100644
--- a/src/conventionalrp/renderers/markdown_renderer.py
+++ b/src/conventionalrp/renderers/markdown_renderer.py
@@ -1,13 +1,14 @@
from .base import BaseRenderer
+
class MarkdownRenderer(BaseRenderer):
def render(self, data):
"""
Renders the given data in Markdown format.
-
+
Args:
data (dict): The data to render.
-
+
Returns:
str: The rendered Markdown string.
"""
@@ -19,8 +20,8 @@ class MarkdownRenderer(BaseRenderer):
def set_style(self, style):
"""
Sets the style for the Markdown renderer.
-
+
Args:
style (dict): A dictionary of style options.
"""
- self.style = style # Currently, Markdown does not support styling, but this can be extended. \ No newline at end of file
+ self.style = style # Currently, Markdown does not support styling, but this can be extended.
diff --git a/src/conventionalrp/utils/__init__.py b/src/conventionalrp/utils/__init__.py
index 44b1840..33b66e4 100644
--- a/src/conventionalrp/utils/__init__.py
+++ b/src/conventionalrp/utils/__init__.py
@@ -1,2 +1,2 @@
# FILE: /trpg-log-processor/trpg-log-processor/src/conventionalrp/utils/__init__.py
-"""This file initializes the utils module.""" \ No newline at end of file
+"""This file initializes the utils module."""