Skip to content

Commit

Permalink
Add doc rendering public action
Browse files Browse the repository at this point in the history
  • Loading branch information
kdouda committed Jan 4, 2025
1 parent 54f1876 commit 5cd69ef
Show file tree
Hide file tree
Showing 7 changed files with 86 additions and 15 deletions.
50 changes: 50 additions & 0 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
@@ -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
14 changes: 6 additions & 8 deletions src/pyrdfrules/common/result/result.py
Original file line number Diff line number Diff line change
@@ -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


Expand All @@ -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
return self.ruleset
12 changes: 9 additions & 3 deletions src/pyrdfrules/common/rule/rule/body.py
Original file line number Diff line number Diff line change
@@ -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]
subject: Subject
2 changes: 1 addition & 1 deletion src/pyrdfrules/common/rule/rule/head.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ class RuleHead(BaseModel):

object: Object

predicate: Predicate
predicate: str

subject: Subject
3 changes: 1 addition & 2 deletions src/pyrdfrules/common/rule/ruleset.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 ''
Expand Down
13 changes: 13 additions & 0 deletions src/pyrdfrules/common/task/task.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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.
"""
Expand Down
7 changes: 6 additions & 1 deletion src/tests/test_parsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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, "<created>")
self.assertEqual(rule.head.subject.value, "?a")
self.assertEqual(rule.head.object.value, "?b")
self.assertEqual(rule.head.graphs, ["<yago>"])
self.assertEqual(rule.body[0].subject.value, "?c")


if __name__ == '__main__':
Expand Down

0 comments on commit 5cd69ef

Please sign in to comment.