From 5cd69efc4bd9cc34108114cde28951ce09f37f14 Mon Sep 17 00:00:00 2001 From: Karel Douda Date: Sat, 4 Jan 2025 13:57:02 +0100 Subject: [PATCH] Add doc rendering public action --- .github/workflows/docs.yml | 50 +++++++++++++++++++++++++ src/pyrdfrules/common/result/result.py | 14 +++---- src/pyrdfrules/common/rule/rule/body.py | 12 ++++-- src/pyrdfrules/common/rule/rule/head.py | 2 +- src/pyrdfrules/common/rule/ruleset.py | 3 +- src/pyrdfrules/common/task/task.py | 13 +++++++ src/tests/test_parsing.py | 7 +++- 7 files changed, 86 insertions(+), 15 deletions(-) create mode 100644 .github/workflows/docs.yml diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml new file mode 100644 index 0000000..5b3c65b --- /dev/null +++ b/.github/workflows/docs.yml @@ -0,0 +1,50 @@ +name: website + +# build the documentation whenever there are new commits on main +on: + push: + branches: + - main + # Alternative: only build for tags. + # tags: + # - '*' + +# security: restrict permissions for CI jobs. +permissions: + contents: read + +jobs: + # Build the documentation and upload the static HTML files as an artifact. + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 + with: + python-version: '3.13' + + # ADJUST THIS: install all dependencies (including pdoc) + - run: pip install -e . + - run: pip install pdoc + # ADJUST THIS: build your documentation into docs/. + # We use a custom build script for pdoc itself, ideally you just run `pdoc -o docs/ ...` here. + - run: pdoc pyrdfrules -o docs/ + + - uses: actions/upload-pages-artifact@v3 + with: + path: docs/ + + # Deploy the artifact to GitHub pages. + # This is a separate job so that only actions/deploy-pages has the necessary permissions. + deploy: + needs: build + runs-on: ubuntu-latest + permissions: + pages: write + id-token: write + environment: + name: github-pages + url: ${{ steps.deployment.outputs.page_url }} + steps: + - id: deployment + uses: actions/deploy-pages@v4 diff --git a/src/pyrdfrules/common/result/result.py b/src/pyrdfrules/common/result/result.py index a776c69..e4fa990 100644 --- a/src/pyrdfrules/common/result/result.py +++ b/src/pyrdfrules/common/result/result.py @@ -1,7 +1,5 @@ from pyrdfrules.common.rule.resultrule import ResultRule -from pyrdfrules.common.rule.rule.body import RuleBody -from pyrdfrules.common.rule.rule.head import RuleHead from pyrdfrules.common.rule.ruleset import Ruleset @@ -27,14 +25,14 @@ def _parse_data(self): match item: case {'body': _, 'head': __, 'measures': ___}: # Item is a rule - - rule = ResultRule.model_construct(item) - - print(rule) - + rule = ResultRule.model_validate(item) + rules.append(rule) pass case _: + print("Unknown item") pass + + self.ruleset = Ruleset(rules = rules) def get_ruleset(self) -> Ruleset: - pass \ No newline at end of file + return self.ruleset \ No newline at end of file diff --git a/src/pyrdfrules/common/rule/rule/body.py b/src/pyrdfrules/common/rule/rule/body.py index 4d28636..48b6d87 100644 --- a/src/pyrdfrules/common/rule/rule/body.py +++ b/src/pyrdfrules/common/rule/rule/body.py @@ -1,9 +1,15 @@ from typing import List from pydantic import BaseModel +from pyrdfrules.common.rule.rule.object import Object +from pyrdfrules.common.rule.rule.predicate import Predicate +from pyrdfrules.common.rule.rule.subject import Subject + class RuleBody(BaseModel): - graphs: str + graphs: List[str] + + object: Object - object: str + predicate: Predicate - items: List[dict] \ No newline at end of file + subject: Subject \ No newline at end of file diff --git a/src/pyrdfrules/common/rule/rule/head.py b/src/pyrdfrules/common/rule/rule/head.py index a596134..6e0f3f2 100644 --- a/src/pyrdfrules/common/rule/rule/head.py +++ b/src/pyrdfrules/common/rule/rule/head.py @@ -11,6 +11,6 @@ class RuleHead(BaseModel): object: Object - predicate: Predicate + predicate: str subject: Subject \ No newline at end of file diff --git a/src/pyrdfrules/common/rule/ruleset.py b/src/pyrdfrules/common/rule/ruleset.py index c11fbe3..666381d 100644 --- a/src/pyrdfrules/common/rule/ruleset.py +++ b/src/pyrdfrules/common/rule/ruleset.py @@ -34,8 +34,7 @@ class Ruleset(BaseModel): __iterator_index: int = 0 def get_rules(self) -> List[ResultRule]: - # return all rules - pass + return self.rules def as_json(self) -> str: return '' diff --git a/src/pyrdfrules/common/task/task.py b/src/pyrdfrules/common/task/task.py index 610e7cf..6a074bf 100644 --- a/src/pyrdfrules/common/task/task.py +++ b/src/pyrdfrules/common/task/task.py @@ -1,6 +1,7 @@ import datetime from pyrdfrules.common.event.event_dispatcher import EventDispatcher +from pyrdfrules.common.result.result import Result from pyrdfrules.common.task.event.task_finished_message import TaskFinishedMessage from pyrdfrules.common.task.event.task_log_message import TaskLogMessage @@ -82,6 +83,18 @@ def update_from_dict(self, data: dict) -> None: self.last_updated = datetime.datetime.now() + def get_result(self) -> Result: + """Returns formatted result of the task. + + Returns: + Result: Result of the task. + """ + + if not self.is_finished(): + raise Exception("Task is not finished yet.") + + return Result(self.result) + def _stop(self) -> None: """Stops the task. """ diff --git a/src/tests/test_parsing.py b/src/tests/test_parsing.py index 7192885..5b006b7 100644 --- a/src/tests/test_parsing.py +++ b/src/tests/test_parsing.py @@ -21,7 +21,12 @@ def test_rule_parsing(self): result = Result(rules) - print(rules) + for rule in result.get_ruleset().get_rules(): + self.assertEqual(rule.head.predicate, "") + self.assertEqual(rule.head.subject.value, "?a") + self.assertEqual(rule.head.object.value, "?b") + self.assertEqual(rule.head.graphs, [""]) + self.assertEqual(rule.body[0].subject.value, "?c") if __name__ == '__main__':