Skip to content

Commit

Permalink
Load and use JSON schema definition always
Browse files Browse the repository at this point in the history
The JSON schema as previously stored at the root directory of the
daliuge-translator package, making it unavailable to the package
runtime, and therefore limiting its usage to deployments where the file
would need to be manually copied to a known location.

This limitation is unnecessary if the file is stored as part of the
daliuge-translator package data. This commit implements that, moving
(and renaming) the file under dlg/dropmake/lg.graph.schema, declaring it
as part of the package data, and loading its contents unconditionally at
package import time. This means we can now run LG schema validation in
all cases, including during unit testing.

This work is part of YAN-899.

Signed-off-by: Rodrigo Tobar <rtobar@icrar.org>
  • Loading branch information
rtobar committed Jun 14, 2022
1 parent 0a38df4 commit 83dbda2
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 15 deletions.
1 change: 1 addition & 0 deletions daliuge-translator/MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ include dlg/dropmake/web/img/*
include dlg/dropmake/web/*.css
include dlg/dropmake/web/*.js
include dlg/dropmake/web/*.html
include dlg/dropmake/*.schema
include dlg/dropmake/lib/*
File renamed without changes.
25 changes: 10 additions & 15 deletions daliuge-translator/dlg/dropmake/web/lg_web.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@
bottle.BaseRequest.MEMFILE_MAX = 1024 * 512


def file_as_string(fname, enc="utf8"):
b = pkg_resources.resource_string(__name__, fname) # @UndefinedVariable
def file_as_string(fname, package=__name__, enc="utf8"):
b = pkg_resources.resource_string(package, fname) # @UndefinedVariable
return common.b2s(b, enc)


Expand All @@ -94,7 +94,8 @@ def file_as_string(fname, enc="utf8"):
("max_mem", int),
] # max_mem is only relevant for the old editor, not used in EAGLE

LG_SCHEMA_PATH = "/daliuge/dlg-lg.graph.schema"

LG_SCHEMA = json.loads(file_as_string("lg.graph.schema", package="dlg.dropmake"))


def lg_path(lg_name):
Expand Down Expand Up @@ -573,18 +574,12 @@ def gen_pgt_post():
logical_graph = json.loads(json_string)
error = None

# load LG schema
lg_schema = None
if os.path.exists(LG_SCHEMA_PATH):
with open(LG_SCHEMA_PATH, "r") as schema_file:
lg_schema = json.load(schema_file)

# validate JSON (if schema was found)
if lg_schema is not None:
try:
validate(logical_graph, lg_schema)
except ValidationError as ve:
error = "Validation Error {1}: {0}".format(str(ve), lg_name)
# validate LG against schema
try:
validate(logical_graph, LG_SCHEMA)
except ValidationError as ve:
error = "Validation Error {1}: {0}".format(str(ve), lg_name)

logical_graph = prepare_lgt(logical_graph, rmode)
# LG -> PGT
pgt = unroll_and_partition_with_params(logical_graph, reqform)
Expand Down

0 comments on commit 83dbda2

Please sign in to comment.