Skip to content

Commit

Permalink
Merge pull request #10 from logilab/package-fix
Browse files Browse the repository at this point in the history
pkg: update manifest.in for file import in package
  • Loading branch information
wiresio authored Jun 30, 2024
2 parents d595418 + 55ef536 commit e81300d
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 23 deletions.
10 changes: 5 additions & 5 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
include ./tdd/*.py
include ./tdd/data/*.ttl
include ./tdd/data/*.json
include ./tdd/lib/*.js
include ./js-src/*.js
include tdd/*.py
include tdd/data/*.ttl
include tdd/data/*.json
include tdd/lib/*.js
include js-src/*.js

include app.py
include *.md
Expand Down
6 changes: 3 additions & 3 deletions tdd/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* SPDX-License-Identifier: EPL-2.0 OR W3C-20150513
********************************************************************************"""

from importlib import resources
from importlib.resources import files
import sys
import time
from threading import Thread
Expand Down Expand Up @@ -165,8 +165,8 @@ def add_cors_headers(response):

@app.route("/", methods=["GET"])
def directory_description():
with resources.open_text("tdd.data", "tdd-description.json") as f:
tdd_description = json.loads(f.read())
with files(__package__).joinpath("data/tdd-description.json").open() as strm:
tdd_description = json.load(strm)
tdd_description["base"] = CONFIG["TD_REPO_URL"]
return Response(
json.dumps(tdd_description), content_type="application/td+json"
Expand Down
16 changes: 6 additions & 10 deletions tdd/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

import base64
import json

from importlib.resources import files

from tdd.config import CONFIG
from tdd.utils import DEFAULT_THING_CONTEXT_URI, DEFAULT_DISCOVERY_CONTEXT_URI
Expand All @@ -25,7 +25,6 @@
GET_ALL_CONTEXTS,
query,
)
from importlib import resources


def convert_context_to_array(ld_content):
Expand All @@ -45,11 +44,11 @@ def overwrite_thing_context(ld_content):
return
if type(ld_content["@context"]) not in (tuple, list):
return
with resources.open_text("tdd.data", "fixed-ctx.json") as fp:
fixed_ctx = fp.read()

with files(__package__).joinpath("data/fixed-ctx.json").open() as strm:
try:
index_wot_ctx = ld_content["@context"].index(DEFAULT_THING_CONTEXT_URI)
ld_content["@context"][index_wot_ctx] = json.loads(fixed_ctx)
ld_content["@context"][index_wot_ctx] = json.load(strm)
except ValueError:
pass

Expand All @@ -61,15 +60,12 @@ def overwrite_discovery_context(ld_content):
return
if type(ld_content["@context"]) not in (tuple, list):
return
with resources.open_text("tdd.data", "fixed-discovery-ctx.json") as fp:
fixed_discovery_ctx = fp.read()
with files(__package__).joinpath("data/fixed-discovery-ctx.json").open() as strm:
try:
index_discovery_ctx = ld_content["@context"].index(
DEFAULT_DISCOVERY_CONTEXT_URI
)
ld_content["@context"][index_discovery_ctx] = json.loads(
fixed_discovery_ctx
)
ld_content["@context"][index_discovery_ctx] = json.load(strm)
except ValueError:
pass

Expand Down
12 changes: 7 additions & 5 deletions tdd/td.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@
import concurrent.futures
from copy import copy
from datetime import datetime
from importlib import resources
import json
from jsonschema import Draft7Validator
import uuid
from rdflib import Graph, RDF
from rdflib.exceptions import ParserError
import pyshacl
from importlib.resources import files, path


from tdd.context import (
Expand Down Expand Up @@ -72,11 +72,12 @@
)


with resources.open_text("tdd.data", "td-json-schema-validation.json") as fp:
schema = json.load(fp)
with files(__package__).joinpath("data/td-json-schema-validation.json").open() as strm:
schema = json.load(strm)

validator = Draft7Validator(schema=schema)


TYPE = "https://www.w3.org/2019/wot/td#Thing"
ONTOLOGY = {"prefix": "td", "base": "https://www.w3.org/2019/wot/td"}

Expand Down Expand Up @@ -137,6 +138,7 @@ def validate_td(td, id=None, check_schema=CONFIG["CHECK_SCHEMA"]):


def validate_td_json_schema(td):

errors = list(validator.iter_errors(td))
if errors:
return False, errors
Expand Down Expand Up @@ -184,9 +186,9 @@ def put_td_rdf_in_sparql(

if check_schema:
ontology_graph = create_binded_graph()
with resources.path("tdd.data", "td.ttl") as onto_path:
with path("tdd.data", "td.ttl") as onto_path:
ontology_graph.parse(location=onto_path, format="turtle")
with resources.path("tdd.data", "td-validation.ttl") as shacl_path:
with path("tdd.data", "td-validation.ttl") as shacl_path:
shacl_shapes_graph = create_binded_graph()
shacl_shapes_graph.parse(location=shacl_path, format="turtle")

Expand Down

0 comments on commit e81300d

Please sign in to comment.