From f2df26e03088a5275e25f98fcc72aaee0d76cab5 Mon Sep 17 00:00:00 2001 From: Karel Douda Date: Wed, 11 Sep 2024 16:01:53 +0200 Subject: [PATCH] Add skeleton API classes --- requirements.txt | 25 ++++++++++++++++ src/pyrdfrules/api/__init__.py | 0 src/pyrdfrules/api/cache/__init__.py | 0 src/pyrdfrules/api/cache/cache_api.py | 26 ++++++++++++++++ src/pyrdfrules/api/http_rdfrules_api.py | 12 ++++++++ .../api/http_rdfrules_api_context.py | 11 +++++++ src/pyrdfrules/api/rdfrules_api.py | 15 ++++++++++ src/pyrdfrules/api/rdfrules_api_context.py | 5 ++++ src/pyrdfrules/api/task/__init__.py | 0 src/pyrdfrules/api/task/task_api.py | 25 ++++++++++++++++ src/pyrdfrules/api/workspace/__init__.py | 0 src/pyrdfrules/api/workspace/workspace_api.py | 30 +++++++++++++++++++ src/pyrdfrules/engine/engine.py | 23 ++++++++++++++ 13 files changed, 172 insertions(+) create mode 100644 src/pyrdfrules/api/__init__.py create mode 100644 src/pyrdfrules/api/cache/__init__.py create mode 100644 src/pyrdfrules/api/cache/cache_api.py create mode 100644 src/pyrdfrules/api/http_rdfrules_api.py create mode 100644 src/pyrdfrules/api/http_rdfrules_api_context.py create mode 100644 src/pyrdfrules/api/rdfrules_api.py create mode 100644 src/pyrdfrules/api/rdfrules_api_context.py create mode 100644 src/pyrdfrules/api/task/__init__.py create mode 100644 src/pyrdfrules/api/task/task_api.py create mode 100644 src/pyrdfrules/api/workspace/__init__.py create mode 100644 src/pyrdfrules/api/workspace/workspace_api.py diff --git a/requirements.txt b/requirements.txt index a9d04a1..ed5ac3f 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,13 +1,38 @@ annotated-types==0.6.0 +anyio==4.4.0 +argcomplete==3.5.0 +black==24.8.0 +certifi==2024.8.30 +charset-normalizer==3.3.2 +click==8.1.7 +datamodel-code-generator==0.26.0 +dnspython==2.6.1 +email_validator==2.2.0 +genson==1.3.0 +h11==0.14.0 +httpcore==1.0.5 +httpx==0.27.2 +idna==3.8 +inflect==5.6.2 install-jdk==1.1.0 +isort==5.13.2 +Jinja2==3.1.4 JPype1==1.5.0 +MarkupSafe==2.1.5 +mypy-extensions==1.0.0 numpy==2.1.1 packaging==24.0 pandas==2.2.2 +pathspec==0.12.1 +platformdirs==4.3.2 pydantic==2.6.4 pydantic_core==2.16.3 python-dateutil==2.9.0.post0 pytz==2024.1 +PyYAML==6.0.2 +requests==2.32.3 six==1.16.0 +sniffio==1.3.1 typing_extensions==4.10.0 tzdata==2024.1 +urllib3==2.2.2 diff --git a/src/pyrdfrules/api/__init__.py b/src/pyrdfrules/api/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/pyrdfrules/api/cache/__init__.py b/src/pyrdfrules/api/cache/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/pyrdfrules/api/cache/cache_api.py b/src/pyrdfrules/api/cache/cache_api.py new file mode 100644 index 0000000..199a503 --- /dev/null +++ b/src/pyrdfrules/api/cache/cache_api.py @@ -0,0 +1,26 @@ +from pyrdfrules.api.rdfrules_api_context import RDFRulesApiContext + + +class CacheApi(): + + context: RDFRulesApiContext + + def __init__(self, context: RDFRulesApiContext) -> None: + self.context = context + pass + + async def get_memory_info(): + """Gets memory info. + """ + + async def clear(): + """Clears the cache. + """ + + async def delete(key: str): + """Deletes a key from the cache. + """ + + async def alias(key: str, alias: str): + """Creates an alias for a key. + """ \ No newline at end of file diff --git a/src/pyrdfrules/api/http_rdfrules_api.py b/src/pyrdfrules/api/http_rdfrules_api.py new file mode 100644 index 0000000..7ea40ad --- /dev/null +++ b/src/pyrdfrules/api/http_rdfrules_api.py @@ -0,0 +1,12 @@ +from pyrdfrules.api.rdfrules_api import RDFRulesApi +from pyrdfrules.api.rdfrules_api_context import RDFRulesApiContext + + +class HTTPRDFRulesApi(RDFRulesApi): + + def __init__(self, context: RDFRulesApiContext) -> None: + super().__init__(context) + self.cache = None + self.workspace = None + self.task = None + pass \ No newline at end of file diff --git a/src/pyrdfrules/api/http_rdfrules_api_context.py b/src/pyrdfrules/api/http_rdfrules_api_context.py new file mode 100644 index 0000000..ea16273 --- /dev/null +++ b/src/pyrdfrules/api/http_rdfrules_api_context.py @@ -0,0 +1,11 @@ +from pydantic import BaseModel +from pydantic_core import Url + +from pyrdfrules.api.rdfrules_api_context import RDFRulesApiContext + + +class HTTPRDFRulesApiContext(RDFRulesApiContext): + + url: Url + """URL of the RDFRules API server. + """ \ No newline at end of file diff --git a/src/pyrdfrules/api/rdfrules_api.py b/src/pyrdfrules/api/rdfrules_api.py new file mode 100644 index 0000000..963e069 --- /dev/null +++ b/src/pyrdfrules/api/rdfrules_api.py @@ -0,0 +1,15 @@ +from pyrdfrules.api.cache.cache_api import CacheApi +from pyrdfrules.api.rdfrules_api_context import RDFRulesApiContext +from pyrdfrules.api.task.task_api import TaskApi +from pyrdfrules.api.workspace.workspace_api import WorkspaceApi + + +class RDFRulesApi(): + cache: CacheApi + workspace: WorkspaceApi + task: TaskApi + context: RDFRulesApiContext + + def __init__(self, context: RDFRulesApiContext) -> None: + self.context = context + pass \ No newline at end of file diff --git a/src/pyrdfrules/api/rdfrules_api_context.py b/src/pyrdfrules/api/rdfrules_api_context.py new file mode 100644 index 0000000..42d47d1 --- /dev/null +++ b/src/pyrdfrules/api/rdfrules_api_context.py @@ -0,0 +1,5 @@ +from pydantic import BaseModel + + +class RDFRulesApiContext(BaseModel): + pass \ No newline at end of file diff --git a/src/pyrdfrules/api/task/__init__.py b/src/pyrdfrules/api/task/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/pyrdfrules/api/task/task_api.py b/src/pyrdfrules/api/task/task_api.py new file mode 100644 index 0000000..0af2364 --- /dev/null +++ b/src/pyrdfrules/api/task/task_api.py @@ -0,0 +1,25 @@ +from pyrdfrules.api.rdfrules_api_context import RDFRulesApiContext + + +class TaskApi(): + + context: RDFRulesApiContext + + def __init__(self, context: RDFRulesApiContext) -> None: + self.context = context + pass + + async def create_task(self): + """Create a task. + """ + pass + + async def get_task_status(self, task_id: str): + """Get the status of a task. + """ + pass + + async def interrupt_task(self, task_id: str): + """Interrupt a task. + """ + pass \ No newline at end of file diff --git a/src/pyrdfrules/api/workspace/__init__.py b/src/pyrdfrules/api/workspace/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/pyrdfrules/api/workspace/workspace_api.py b/src/pyrdfrules/api/workspace/workspace_api.py new file mode 100644 index 0000000..2d91415 --- /dev/null +++ b/src/pyrdfrules/api/workspace/workspace_api.py @@ -0,0 +1,30 @@ +from pyrdfrules.api.rdfrules_api_context import RDFRulesApiContext + + +class WorkspaceApi(): + + context: RDFRulesApiContext + + def __init__(self, context: RDFRulesApiContext) -> None: + self.context = context + pass + + async def get_all_files(self): + """Get all files and directories recursively from the workspace directory. + """ + pass + + async def get_file(self, path: str): + """Get the file content. + """ + pass + + async def delete_file(self, path: str): + """Delete a file. + """ + pass + + async def upload_file(self, path: str, content: bytes): + """Upload a file. + """ + pass \ No newline at end of file diff --git a/src/pyrdfrules/engine/engine.py b/src/pyrdfrules/engine/engine.py index 43a528a..8cbd36f 100644 --- a/src/pyrdfrules/engine/engine.py +++ b/src/pyrdfrules/engine/engine.py @@ -1,3 +1,4 @@ +import json from typing import Awaitable from pydantic import BaseModel @@ -64,4 +65,26 @@ async def launch_pipeline(self, pipeline: Pipeline) -> Awaitable[PipelineRunResu Throws: """ + pass + + + + @ensure_started + async def run_task(self, task: str|dict) -> Awaitable[None]: + """ + Runs a task on the engine. + + Args: + task (str|dict): Task to run, either string-serialized JSON or JSON represented as a dict. + + Returns: + Awaitable[None]: Returns a non-blocking future. + """ + + # todo custom exception + if not isinstance(task, dict): + task = json.loads(task) + + + pass \ No newline at end of file