Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Python Tests

on:
push:
branches: ["**"]
pull_request:

jobs:
test:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.11'

- name: Install Poetry
run: |
curl -sSL https://install.python-poetry.org | python3 -
echo "$HOME/.local/bin" >> $GITHUB_PATH

- name: Install dependencies
run: |
poetry install

- name: Run tests
run: |
poetry run make run-test
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,4 @@ dmypy.json

# Pyre type checker
.pyre/
.report
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,14 @@ ruff:
ruff check --fix
ruff format

run-test:
pytest

help:
@echo "Available commands:"
@echo " install - Install dependencies and set up pre-commit hooks"
@echo " ruff - Format code and fix linting issues using ruff"
@echo " run-test - Run tests"
@echo " demo - Run /examples/demo.py file"
@echo " async-demo - Run /examples/async_demo.py file"
@echo " paranet-demo - Run /examples/paranets_demo.py file"
@echo " paranet-demo - Run /examples/paranets_demo.py file"
22 changes: 8 additions & 14 deletions dkg/utils/knowledge_collection_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from dkg.types import JSONLD, NQuads
from pyld import jsonld
from dkg.constants import DEFAULT_RDF_FORMAT, DEFAULT_CANON_ALGORITHM, ESCAPE_MAP
from rdflib import Graph, BNode, URIRef, Literal as RDFLiteral
from rdflib import Graph, BNode, URIRef, Dataset
from rdflib.exceptions import ParserError as RDFParserError
from uuid import uuid4
from web3 import Web3
Expand Down Expand Up @@ -182,16 +182,13 @@ def replace_blank_node(term):
def group_nquads_by_subject(nquads_list: list[str], sort: bool = False):
grouped = {}

# Process each quad in original order
for nquad in nquads_list:
if not nquad.strip(): # Skip empty lines
continue
all_nquads = "\n".join(nquad for nquad in nquads_list if nquad.strip())

# Parse single quad
g = Graph()
g.parse(data=nquad, format="nquads")
quad = next(iter(g))
subject, predicate, obj = quad
d = Dataset()
d.parse(data=all_nquads, format="nquads")

for quad in d:
subject, predicate, obj, graph = quad

# Get subject key
subject_key = (
Expand All @@ -204,11 +201,8 @@ def group_nquads_by_subject(nquads_list: list[str], sort: bool = False):
if subject_key not in grouped:
grouped[subject_key] = []

# Format object
object_value = f'"{obj}"' if isinstance(obj, RDFLiteral) else f"<{obj}>"

# Add quad to group
quad_string = f"{subject_key} <{predicate}> {object_value} ."
quad_string = f"{subject.n3()} {predicate.n3()} {obj.n3()} ."
grouped[subject_key].append(quad_string)

# Return grouped quads (sorted if requested)
Expand Down
3,431 changes: 2,050 additions & 1,381 deletions poetry.lock

Large diffs are not rendered by default.

21 changes: 20 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
[tool.poetry]
name = "dkg"
version = "8.0.13"
version = "8.0.14"
description = "Python library for interacting with the OriginTrail Decentralized Knowledge Graph"
authors = ["Uladzislau Hubar <[email protected]>, Zvonimir Sculac <[email protected]>"]
license = "Apache-2.0"
readme = "README.md"


[tool.poetry.dependencies]
python = "^3.10"
pyyaml = "^6.0.2"
Expand All @@ -23,10 +24,28 @@ python-dotenv = "^1.0.1"
[tool.poetry.group.dev.dependencies]
ruff = "^0.8.4"
pre-commit = "^4.0.1"
pytest = "^8.0"
pytest-cov = "^4.0"


[tools.setuptools]
packages = ["dkg"]


[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"


[tool.pytest.ini_options]
minversion = "8.0"
addopts = "-ra"
testpaths = [
"test"
]


python_files = [
"test_*.py",
"*_test.py"
]
File renamed without changes.
Loading