Skip to content

Commit 8e9554f

Browse files
authored
Update seqspec check so we can run it directly in python script (#58)
* update seqspec check * add spec parameter back to check function
1 parent e3a6dea commit 8e9554f

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

seqspec/seqspec_check.py

+10-10
Original file line numberDiff line numberDiff line change
@@ -33,19 +33,14 @@ def setup_check_args(parser):
3333
def validate_check_args(parser, args):
3434
spec_fn = args.yaml
3535
o = args.o
36-
schema_fn = path.join(path.dirname(__file__), "schema/seqspec.schema.json")
3736

38-
return run_check(schema_fn, spec_fn, o)
37+
return run_check(spec_fn, o)
3938

4039

41-
def run_check(schema_fn, spec_fn, o):
40+
def run_check(spec_fn, o):
4241
spec = load_spec(spec_fn)
4342

44-
with open(schema_fn, "r") as stream:
45-
schema = yaml.load(stream, Loader=yaml.Loader)
46-
v = Draft4Validator(schema)
47-
48-
errors = check(v, spec, spec_fn)
43+
errors = check(spec)
4944

5045
if errors:
5146
if o:
@@ -56,14 +51,19 @@ def run_check(schema_fn, spec_fn, o):
5651
return errors
5752

5853

59-
def check(schema: Draft4Validator, spec: Assay, spec_fn: str):
54+
def check(spec: Assay, spec_fn: str = None):
55+
schema_fn = path.join(path.dirname(__file__), "schema/seqspec.schema.json")
56+
57+
with open(schema_fn, "r") as stream:
58+
schema = yaml.load(stream, Loader=yaml.Loader)
59+
validator = Draft4Validator(schema)
6060
errors = []
6161
idx = 0
6262

6363
# with open("del.json", "w") as f:
6464
# json.dump(spec.to_dict(), f, indent=4)
6565

66-
for idx, error in enumerate(schema.iter_errors(spec.to_dict()), 1):
66+
for idx, error in enumerate(validator.iter_errors(spec.to_dict()), 1):
6767
errors.append(
6868
f"[error {idx}] {error.message} in spec[{']['.join(repr(index) for index in error.path)}]"
6969
)

0 commit comments

Comments
 (0)