mustrd 0.2.0__py3-none-any.whl → 0.2.0a1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
mustrd/run.py CHANGED
@@ -1,106 +1,95 @@
1
- """
2
- MIT License
3
-
4
- Copyright (c) 2023 Semantic Partners Ltd
5
-
6
- Permission is hereby granted, free of charge, to any person obtaining a copy
7
- of this software and associated documentation files (the "Software"), to deal
8
- in the Software without restriction, including without limitation the rights
9
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
- copies of the Software, and to permit persons to whom the Software is
11
- furnished to do so, subject to the following conditions:
12
-
13
- The above copyright notice and this permission notice shall be included in all
14
- copies or substantial portions of the Software.
15
-
16
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
- SOFTWARE.
23
- """
24
-
25
- import argparse
26
- import logger_setup
27
- import sys
28
- import os
29
- from rdflib import Graph
30
- from .mustrd import get_triple_store_graph, run_specs, get_triple_stores, review_results, validate_specs, get_specs
31
- from pathlib import Path
32
- from .namespace import TRIPLESTORE
33
- from .utils import get_project_root
34
- import logging
35
- log = logger_setup.setup_logger(__name__)
36
-
37
-
38
- def parse_args() -> argparse.Namespace:
39
- parser = argparse.ArgumentParser()
40
- parser.add_argument("-p", "--put", help="Path under test - required", required=True)
41
- parser.add_argument("-v", "--verbose", help="verbose logging", action='store_true')
42
- parser.add_argument("-c", "--config", help="Path to triple store configuration", default=None)
43
- parser.add_argument("-d", "--data", help="Path to test data", default=None)
44
- parser.add_argument("-g", "--given", help="Override path for given files", default=None)
45
- parser.add_argument("-w", "--when", help="Override path for when files", default=None)
46
- parser.add_argument("-t", "--then", help="Override path for then files", default=None)
47
-
48
- return parser.parse_args()
49
-
50
-
51
- # https://github.com/Semantic-partners/mustrd/issues/108
52
- def main(argv):
53
- #given_path = when_path = then_path = None
54
- project_root = get_project_root()
55
- run_config = {}
56
- args = parse_args()
57
- run_config["spec_path"] = Path(args.put)
58
- log.info(f"Path under test is { run_config['spec_path']}")
59
-
60
- verbose = args.verbose
61
- if verbose:
62
- log.info(f"Verbose set")
63
- run_config["verbose"] = True
64
-
65
- if args.config:
66
- triplestore_spec_path = Path(args.config)
67
- log.info(f"Path for triple store configuration is {triplestore_spec_path}")
68
- triple_stores = get_triple_stores(get_triple_store_graph(triplestore_spec_path))
69
- else:
70
- log.info(f"No triple store configuration added, running default configuration")
71
- triple_stores = [{'type': TRIPLESTORE.RdfLib}]
72
- log.info("Triple Stores: " + str(triple_stores))
73
- if args.data:
74
- run_config["data_path"] = Path(args.data)
75
- else:
76
- run_config["data_path"] = Path(args.put)
77
- log.info(f"Path for test data folder is {run_config['data_path']}")
78
-
79
- if args.given:
80
- run_config["given_path"] = Path(args.given)
81
- log.info(f"Path for given folder is {run_config['given_path']}")
82
-
83
- if args.when:
84
- run_config["when_path"] = Path(args.when)
85
- log.info(f"Path for when folder is {run_config['when_path']}")
86
-
87
- if args.then:
88
- run_config["then_path"] = Path(args.then)
89
- log.info(f"Path for then folder is {run_config['then_path']}")
90
-
91
- shacl_graph = Graph().parse(Path(os.path.join(project_root, "model/mustrdShapes.ttl")))
92
- ont_graph = Graph().parse(Path(os.path.join(project_root, "model/ontology.ttl")))
93
-
94
- valid_spec_uris, spec_graph, invalid_spec_results = \
95
- validate_specs(run_config, triple_stores, shacl_graph, ont_graph)
96
-
97
- specs, skipped_spec_results = \
98
- get_specs(valid_spec_uris, spec_graph, triple_stores, run_config)
99
-
100
- results = invalid_spec_results + skipped_spec_results + run_specs(specs)
101
-
102
- review_results(results, verbose)
103
-
104
-
105
- if __name__ == "__main__":
106
- main(sys.argv[1:])
1
+ """
2
+ MIT License
3
+
4
+ Copyright (c) 2023 Semantic Partners Ltd
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to deal
8
+ in the Software without restriction, including without limitation the rights
9
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in all
14
+ copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ SOFTWARE.
23
+ """
24
+
25
+ import argparse
26
+ import logger_setup
27
+ import sys
28
+ import os
29
+ from rdflib import Graph
30
+ from mustrd import run_specs, get_triple_stores, review_results, validate_specs
31
+ from pathlib import Path
32
+ from namespace import MUST
33
+ from utils import get_project_root
34
+
35
+ log = logger_setup.setup_logger(__name__)
36
+
37
+
38
+ def parse_args() -> argparse.Namespace:
39
+ parser = argparse.ArgumentParser()
40
+ parser.add_argument("-p", "--put", help="Path under test - required", required=True)
41
+ parser.add_argument("-v", "--verbose", help="verbose logging", action='store_true')
42
+ parser.add_argument("-c", "--config", help="Path to triple store configuration", default=None)
43
+ parser.add_argument("-g", "--given", help="Folder for given files", default=None)
44
+ parser.add_argument("-w", "--when", help="Folder for when files", default=None)
45
+ parser.add_argument("-t", "--then", help="Folder for then files", default=None)
46
+
47
+ return parser.parse_args()
48
+
49
+
50
+ # https://github.com/Semantic-partners/mustrd/issues/108
51
+ def main(argv):
52
+ given_path = when_path = then_path = None
53
+ project_root = get_project_root()
54
+ args = parse_args()
55
+ path_under_test = Path(args.put)
56
+ log.info(f"Path under test is {path_under_test}")
57
+
58
+ verbose = args.verbose
59
+ if verbose:
60
+ log.info(f"Verbose set")
61
+
62
+ if args.config:
63
+ triplestore_spec_path = Path(args.config)
64
+ log.info(f"Path for triple store configuration is {triplestore_spec_path}")
65
+ triple_stores = get_triple_stores(Graph().parse(triplestore_spec_path))
66
+ else:
67
+ log.info(f"No triple store configuration added, running default configuration")
68
+ triple_stores = [{'type': MUST.RdfLib}]
69
+
70
+ if args.given:
71
+ given_path = Path(args.given)
72
+ log.info(f"Path for given folder is {given_path}")
73
+
74
+ if args.when:
75
+ when_path = Path(args.when)
76
+ log.info(f"Path for when folder is {when_path}")
77
+
78
+ if args.then:
79
+ then_path = Path(args.then)
80
+ log.info(f"Path for then folder is {then_path}")
81
+
82
+ shacl_graph = Graph().parse(Path(os.path.join(project_root, "model/mustrdShapes.ttl")))
83
+ ont_graph = Graph().parse(Path(os.path.join(project_root, "model/ontology.ttl")))
84
+
85
+ valid_spec_uris, spec_graph, invalid_spec_results = \
86
+ validate_specs(path_under_test, triple_stores, shacl_graph, ont_graph)
87
+
88
+ results = \
89
+ run_specs(valid_spec_uris, spec_graph, invalid_spec_results, triple_stores, given_path, when_path, then_path)
90
+
91
+ review_results(results, verbose)
92
+
93
+
94
+ if __name__ == "__main__":
95
+ main(sys.argv[1:])