Forráskód Böngészése

Replace query mechanism

Arkadiusz Ryś 2 éve
szülő
commit
a846e4ef23
4 módosított fájl, 56 hozzáadás és 31 törlés
  1. 2 1
      data/configuration.toml
  2. 5 13
      graph_exploring_tool/query.py
  3. 12 12
      requirements.txt
  4. 37 5
      tasks.py

+ 2 - 1
data/configuration.toml

@@ -1,4 +1,5 @@
-endpoint_sparql = "http://127.0.0.1:3030/SystemDesignOntology2Layers/sparql" # Fuseki SPARQL endpoint for the drivetrain
+#endpoint_sparql = "http://127.0.0.1:3030/SystemDesignOntology2Layers/sparql" # Fuseki SPARQL endpoint for the drivetrain
+endpoint_sparql = "https://fuseki.rys.app/SystemDesignOntology2Layers/" # Fuseki SPARQL endpoint for the drivetrain
 #endpoint_sparql = "http://127.0.0.1:3030/Drivetrain/sparql" # Fuseki SPARQL endpoint for the drivetrain
 #endpoint_sparql = "http://127.0.0.1:8000/" # Fuseki SPARQL endpoint (default spendpoint dev uri)
 #endpoint_sparql = "https://fuseki.rys.app/example/" # Deployement endpoint

+ 5 - 13
graph_exploring_tool/query.py

@@ -2,10 +2,8 @@ import json.decoder
 from dataclasses import dataclass, field
 from typing import List
 from urllib.error import URLError
-
+import owly
 import arklog
-from SPARQLWrapper import SPARQLWrapper, JSON, POSTDIRECTLY
-from SPARQLWrapper.SPARQLExceptions import QueryBadFormed
 
 arklog.set_config_logging()
 
@@ -77,19 +75,13 @@ reverse_prefix = {
 }
 
 
-def perform_query(endpoint: str, query_text: str, post: bool = False) -> dict:
+def perform_query(endpoint_uri: str, query_text: str, post: bool = False) -> dict:
     """"""
-    sparql = SPARQLWrapper(endpoint)
-    sparql.setReturnFormat(JSON)
-    if post:
-        sparql.setRequestMethod(POSTDIRECTLY)
-    sparql.setQuery(query_text)
+    endpoint = owly.Endpoint(endpoint_uri)
     try:
-        ret = sparql.query().convert()
-    except QueryBadFormed:
-        raise
+        result = endpoint.perform_query(query_text)
     except URLError:
         raise
     except json.decoder.JSONDecodeError:
         raise
-    return ret
+    return result.as_json()

+ 12 - 12
requirements.txt

@@ -1,24 +1,24 @@
 # Graph Exploring Tool
-toml          ~= 0.10.2
-arklog        ~= 0.5.1
-dacite        ~= 1.8.1
-rdflib        ~= 6.3.2
-sparqlwrapper ~= 2.0.0
+owly   ~= 0.0.2
+toml   ~= 0.10.2
+arklog ~= 0.5.1
+dacite ~= 1.8.1
+rdflib ~= 6.3.2
 # Test
-pytest ~= 7.3.1
+pytest ~= 7.4.0
 # Doc
 sphinx ~= 7.0.1
 # Dev
-tox         ~= 4.5.1
-pip         ~= 23.1.2
+tox         ~= 4.6.4
+pip         ~= 23.2
 flit        ~= 3.9.0
 twine       ~= 4.0.2
-invoke      ~= 2.1.2
+invoke      ~= 2.2.0
 jinja2      ~= 3.1.2
 flake8      ~= 6.0.0
-coverage    ~= 7.2.5
-pyinstaller ~= 5.11.0
-pyinstaller-hooks-contrib ~= 2023.3
+coverage    ~= 7.2.7
+pyinstaller ~= 5.13.0
+pyinstaller-hooks-contrib ~= 2023.5
 # pylode        ~= 3.0.4
 # owlready2     ~= 0.40
 # graphviz      ~= 0.20.1

+ 37 - 5
tasks.py

@@ -3,11 +3,11 @@ from pathlib import Path
 from invoke import task
 from jinja2 import Template
 
+system = "graph_exploring_tool"  # Directory name of the project
 
 @task
 def lint(c):
     """"""
-    system = "graph_exploring_tool"
     c.run(f"python3 -m black {system}")
     c.run(f"python3 -m pylint {system}")
 
@@ -18,21 +18,50 @@ def documentation(c):
     c.run("python3 -m sphinx docs docs/build/html")
 
 
+@task(name="preview", aliases=("rst",))
+def preview(c):
+    """Show a preview of the README file."""
+    rst_view = c.run(f"restview --listen=8888 --browser --pypi-strict README.rst", asynchronous=True, out_stream=sys.stdout)
+    print("Listening on http://localhost:8888/")
+    rst_view.join()
+
+
+@task
+def clean(c):
+    """Remove all artefacts."""
+    patterns = ["build", "docs/build"]
+    for pattern in patterns:
+        c.run(f"rm -rf {pattern}")
+
+
 @task
 def test(c):
     """Run all tests under the tests directory."""
     c.run("python3 -m unittest discover tests 'test_*' -v")
 
 
+@task
+def coverage(c):
+    """Run coverage from the 'tests' directory."""
+    c.run("coverage run --source . -m unittest discover tests 'test_*' -v")
+    c.run("coverage html")
+
+
+@task
+def minimum(c):
+    """Check the minimum required python version for the project."""
+    c.run("vermin --no-parse-comments .")
+
+
 @task(name="migrate")
 def migrate_requirements(c):
     """Copy requirements from the requirements.txt file to pyproject.toml."""
     lines = Path("requirements.txt").read_text().split("\n")
-    current = "graph_exploring_tool"
+    current = system.lower().replace("-", "_")
     requirements = {current: [], "test": [], "doc": [], "graphical": [], "dev": []}
     for line in lines:
         if line.startswith("#"):
-            candidate = line[1:].lower().strip().replace(" ", "_")
+            candidate = line[1:].lower().strip().replace(" ", "_").replace("-", "_")
             if candidate in requirements.keys():
                 current = candidate
                 continue
@@ -50,7 +79,10 @@ def release(c, version):
         print("Version can be either major, minor or patch.")
         return
 
-    from graph_exploring_tool import __version_info__, __version__
+    import importlib
+    current_module = importlib.import_module(system)
+    __version_info__ = current_module.__version_info__
+    __version__ = current_module.__version__
     _major, _minor, _patch = __version_info__
 
     if version == "patch":
@@ -64,7 +96,7 @@ def release(c, version):
         _patch = 0
 
     c.run(f"git checkout -b release-{_major}.{_minor}.{_patch} dev")
-    c.run(f"sed -i 's/{__version__}/{_major}.{_minor}.{_patch}/g' graph_exploring_tool/__init__.py")
+    c.run(f"sed -i 's/{__version__}/{_major}.{_minor}.{_patch}/g' {system}/__init__.py")
     print(f"Update the readme for version {_major}.{_minor}.{_patch}.")
     input("Press enter when ready.")
     c.run(f"git add -u")