ghga-validator 1.0.0__tar.gz

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.
Files changed (34) hide show
  1. ghga_validator-1.0.0/LICENSE +202 -0
  2. ghga_validator-1.0.0/PKG-INFO +99 -0
  3. ghga_validator-1.0.0/README.md +81 -0
  4. ghga_validator-1.0.0/ghga_validator/__init__.py +23 -0
  5. ghga_validator-1.0.0/ghga_validator/__main__.py +27 -0
  6. ghga_validator-1.0.0/ghga_validator/cli.py +130 -0
  7. ghga_validator-1.0.0/ghga_validator/core/__init__.py +19 -0
  8. ghga_validator-1.0.0/ghga_validator/core/validation.py +83 -0
  9. ghga_validator-1.0.0/ghga_validator/linkml/__init__.py +15 -0
  10. ghga_validator-1.0.0/ghga_validator/linkml/object_iterator.py +289 -0
  11. ghga_validator-1.0.0/ghga_validator/plugins/__init__.py +20 -0
  12. ghga_validator-1.0.0/ghga_validator/plugins/jsonschema_validation.py +94 -0
  13. ghga_validator-1.0.0/ghga_validator/plugins/ref_validation.py +147 -0
  14. ghga_validator-1.0.0/ghga_validator/plugins/unique_identifier_validation.py +103 -0
  15. ghga_validator-1.0.0/ghga_validator/schema_utils.py +48 -0
  16. ghga_validator-1.0.0/ghga_validator/utils.py +30 -0
  17. ghga_validator-1.0.0/ghga_validator.egg-info/PKG-INFO +99 -0
  18. ghga_validator-1.0.0/ghga_validator.egg-info/SOURCES.txt +33 -0
  19. ghga_validator-1.0.0/ghga_validator.egg-info/dependency_links.txt +1 -0
  20. ghga_validator-1.0.0/ghga_validator.egg-info/entry_points.txt +2 -0
  21. ghga_validator-1.0.0/ghga_validator.egg-info/not-zip-safe +1 -0
  22. ghga_validator-1.0.0/ghga_validator.egg-info/requires.txt +6 -0
  23. ghga_validator-1.0.0/ghga_validator.egg-info/top_level.txt +2 -0
  24. ghga_validator-1.0.0/setup.cfg +42 -0
  25. ghga_validator-1.0.0/setup.py +23 -0
  26. ghga_validator-1.0.0/tests/fixtures/__init__.py +16 -0
  27. ghga_validator-1.0.0/tests/fixtures/utils.py +20 -0
  28. ghga_validator-1.0.0/tests/test_validate.py +32 -0
  29. ghga_validator-1.0.0/tests/test_validate_attribute.py +32 -0
  30. ghga_validator-1.0.0/tests/test_validate_empty.py +32 -0
  31. ghga_validator-1.0.0/tests/test_validate_empty_required.py +32 -0
  32. ghga_validator-1.0.0/tests/test_validate_json_schema.py +32 -0
  33. ghga_validator-1.0.0/tests/test_validate_ref.py +32 -0
  34. ghga_validator-1.0.0/tests/test_validate_unique_id.py +32 -0
@@ -0,0 +1,202 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2021 - 2023 Universität Tübingen, DKFZ, EMBL, and Universität zu Köln
190
+ for the German Human Genome-Phenome Archive (GHGA)
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
@@ -0,0 +1,99 @@
1
+ Metadata-Version: 2.1
2
+ Name: ghga_validator
3
+ Version: 1.0.0
4
+ Summary: GHGA Validator
5
+ Home-page: https://github.com/ghga-de/ghga-validator
6
+ Author: German Human Genome Phenome Archive (GHGA)
7
+ Author-email: contact@ghga.de
8
+ License: Apache 2.0
9
+ Classifier: Operating System :: POSIX :: Linux
10
+ Classifier: Programming Language :: Python :: 3.9
11
+ Classifier: License :: OSI Approved :: Apache Software License
12
+ Classifier: Topic :: Internet :: WWW/HTTP :: HTTP Servers
13
+ Classifier: Topic :: Scientific/Engineering :: Bio-Informatics
14
+ Requires-Python: >=3.9
15
+ Description-Content-Type: text/markdown; charset=UTF-8
16
+ Provides-Extra: all
17
+ License-File: LICENSE
18
+
19
+
20
+ [![tests](https://github.com/ghga-de/ghga-validator/actions/workflows/unit_and_int_tests.yaml/badge.svg)](https://github.com/ghga-de/ghga-validator/actions/workflows/unit_and_int_tests.yaml)
21
+ [![Coverage Status](https://coveralls.io/repos/github/ghga-de/ghga-validator/badge.svg?branch=main)](https://coveralls.io/github/ghga-de/ghga-validator?branch=main)
22
+
23
+ # Ghga Validator
24
+
25
+ GHGA Validator
26
+
27
+ ## Description
28
+
29
+ <!-- Please provide a short overview of the features of this service.-->
30
+
31
+ ghga-validator is a Python library and command line utility to validate metadata
32
+ w.r.t. its compliance to the [GHGA Metadata
33
+ Model](github.com/ghga-de/ghga-metadata-schema). It takes metadata encoded in JSON of YAML format and produces a validation report in JSON format.
34
+
35
+
36
+ ## Installation
37
+ We recommend installing the latest version of ghga-validator using pip:
38
+ ```
39
+ pip install -U ghga-validator
40
+ ```
41
+
42
+ ## Usage
43
+
44
+ ```
45
+ Usage: ghga-validator [OPTIONS]
46
+
47
+ GHGA Validator
48
+
49
+ ghga-validator is a command line utility to validate metadata w.r.t. its
50
+ compliance to the GHGA Metadata Model. It takes metadata encoded in JSON of
51
+ YAML format and produces a validation report in JSON format.
52
+
53
+ Options:
54
+ -s, --schema PATH Path to metadata schema (modelled using
55
+ LinkML) [required]
56
+ -i, --input FILE Path to submission file in JSON format to be
57
+ validated [required]
58
+ -r, --report FILE Path to resulting validation report
59
+ [required]
60
+ --target-class TEXT The root class name
61
+ --install-completion [bash|zsh|fish|powershell|pwsh]
62
+ Install completion for the specified shell.
63
+ --show-completion [bash|zsh|fish|powershell|pwsh]
64
+ Show completion for the specified shell, to
65
+ copy it or customize the installation.
66
+ --help Show this message and exit.
67
+ ```
68
+
69
+ ## Development
70
+ For setting up the development environment, we rely on the
71
+ [devcontainer feature](https://code.visualstudio.com/docs/remote/containers) of vscode
72
+ in combination with Docker Compose.
73
+
74
+ To use it, you have to have Docker Compose as well as vscode with its "Remote - Containers"
75
+ extension (`ms-vscode-remote.remote-containers`) installed.
76
+ Then open this repository in vscode and run the command
77
+ `Remote-Containers: Reopen in Container` from the vscode "Command Palette".
78
+
79
+ This will give you a full-fledged, pre-configured development environment including:
80
+ - infrastructural dependencies of the service (databases, etc.)
81
+ - all relevant vscode extensions pre-installed
82
+ - pre-configured linting and auto-formating
83
+ - a pre-configured debugger
84
+ - automatic license-header insertion
85
+
86
+ Moreover, inside the devcontainer, a convenience commands `dev_install` is available.
87
+ It installs the service with all development dependencies, installs pre-commit.
88
+
89
+ The installation is performed automatically when you build the devcontainer. However,
90
+ if you update dependencies in the [`./setup.cfg`](./setup.cfg) or the
91
+ [`./requirements-dev.txt`](./requirements-dev.txt), please run it again.
92
+
93
+ ## License
94
+ This repository is free to use and modify according to the
95
+ [Apache 2.0 License](./LICENSE).
96
+
97
+ ## Readme Generation
98
+ This readme is autogenerate, please see [`readme_generation.md`](./readme_generation.md)
99
+ for details.
@@ -0,0 +1,81 @@
1
+
2
+ [![tests](https://github.com/ghga-de/ghga-validator/actions/workflows/unit_and_int_tests.yaml/badge.svg)](https://github.com/ghga-de/ghga-validator/actions/workflows/unit_and_int_tests.yaml)
3
+ [![Coverage Status](https://coveralls.io/repos/github/ghga-de/ghga-validator/badge.svg?branch=main)](https://coveralls.io/github/ghga-de/ghga-validator?branch=main)
4
+
5
+ # Ghga Validator
6
+
7
+ GHGA Validator
8
+
9
+ ## Description
10
+
11
+ <!-- Please provide a short overview of the features of this service.-->
12
+
13
+ ghga-validator is a Python library and command line utility to validate metadata
14
+ w.r.t. its compliance to the [GHGA Metadata
15
+ Model](github.com/ghga-de/ghga-metadata-schema). It takes metadata encoded in JSON of YAML format and produces a validation report in JSON format.
16
+
17
+
18
+ ## Installation
19
+ We recommend installing the latest version of ghga-validator using pip:
20
+ ```
21
+ pip install -U ghga-validator
22
+ ```
23
+
24
+ ## Usage
25
+
26
+ ```
27
+ Usage: ghga-validator [OPTIONS]
28
+
29
+ GHGA Validator
30
+
31
+ ghga-validator is a command line utility to validate metadata w.r.t. its
32
+ compliance to the GHGA Metadata Model. It takes metadata encoded in JSON of
33
+ YAML format and produces a validation report in JSON format.
34
+
35
+ Options:
36
+ -s, --schema PATH Path to metadata schema (modelled using
37
+ LinkML) [required]
38
+ -i, --input FILE Path to submission file in JSON format to be
39
+ validated [required]
40
+ -r, --report FILE Path to resulting validation report
41
+ [required]
42
+ --target-class TEXT The root class name
43
+ --install-completion [bash|zsh|fish|powershell|pwsh]
44
+ Install completion for the specified shell.
45
+ --show-completion [bash|zsh|fish|powershell|pwsh]
46
+ Show completion for the specified shell, to
47
+ copy it or customize the installation.
48
+ --help Show this message and exit.
49
+ ```
50
+
51
+ ## Development
52
+ For setting up the development environment, we rely on the
53
+ [devcontainer feature](https://code.visualstudio.com/docs/remote/containers) of vscode
54
+ in combination with Docker Compose.
55
+
56
+ To use it, you have to have Docker Compose as well as vscode with its "Remote - Containers"
57
+ extension (`ms-vscode-remote.remote-containers`) installed.
58
+ Then open this repository in vscode and run the command
59
+ `Remote-Containers: Reopen in Container` from the vscode "Command Palette".
60
+
61
+ This will give you a full-fledged, pre-configured development environment including:
62
+ - infrastructural dependencies of the service (databases, etc.)
63
+ - all relevant vscode extensions pre-installed
64
+ - pre-configured linting and auto-formating
65
+ - a pre-configured debugger
66
+ - automatic license-header insertion
67
+
68
+ Moreover, inside the devcontainer, a convenience commands `dev_install` is available.
69
+ It installs the service with all development dependencies, installs pre-commit.
70
+
71
+ The installation is performed automatically when you build the devcontainer. However,
72
+ if you update dependencies in the [`./setup.cfg`](./setup.cfg) or the
73
+ [`./requirements-dev.txt`](./requirements-dev.txt), please run it again.
74
+
75
+ ## License
76
+ This repository is free to use and modify according to the
77
+ [Apache 2.0 License](./LICENSE).
78
+
79
+ ## Readme Generation
80
+ This readme is autogenerate, please see [`readme_generation.md`](./readme_generation.md)
81
+ for details.
@@ -0,0 +1,23 @@
1
+ # Copyright 2021 - 2023 Universität Tübingen, DKFZ, EMBL, and Universität zu Köln
2
+ # for the German Human Genome-Phenome Archive (GHGA)
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+
16
+ """The package provides the functionality required for the ghga_validator
17
+ command line utility."""
18
+
19
+ __version__ = "1.0.0"
20
+
21
+ from pathlib import Path
22
+
23
+ BASE_DIR = Path(__file__).parent.parent.resolve()
@@ -0,0 +1,27 @@
1
+ # Copyright 2021 - 2023 Universität Tübingen, DKFZ, EMBL, and Universität zu Köln
2
+ # for the German Human Genome-Phenome Archive (GHGA)
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+
16
+ """Entrypoint of the package"""
17
+
18
+ from ghga_validator.cli import cli
19
+
20
+
21
+ def run():
22
+ """Run the application (used in setup.cfg)."""
23
+ cli()
24
+
25
+
26
+ if __name__ == "__main__":
27
+ run()
@@ -0,0 +1,130 @@
1
+ # Copyright 2021 - 2023 Universität Tübingen, DKFZ, EMBL, and Universität zu Köln
2
+ # for the German Human Genome-Phenome Archive (GHGA)
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+
17
+ """Entrypoint of the package"""
18
+
19
+ import json
20
+ from pathlib import Path
21
+ from typing import Optional
22
+
23
+ import typer
24
+ import yaml
25
+
26
+ from ghga_validator.core.validation import get_target_class, validate
27
+ from ghga_validator.plugins import (
28
+ GHGAJsonSchemaValidationPlugin,
29
+ RefValidationPlugin,
30
+ UniqueIdentifierValidationPlugin,
31
+ )
32
+
33
+ cli = typer.Typer()
34
+
35
+ DEFAULT_PLUGINS = [{"plugin_class": GHGAJsonSchemaValidationPlugin, "plugin_args": {}}]
36
+
37
+ VALIDATION_PLUGINS = [
38
+ {"plugin_class": RefValidationPlugin, "plugin_args": {}},
39
+ {"plugin_class": UniqueIdentifierValidationPlugin, "plugin_args": {}},
40
+ ]
41
+
42
+
43
+ def validate_json(file: Path, schema: Path, report: Path, target_class: str) -> bool:
44
+ """
45
+ Validate JSON object against a given schema. Store the errors to the validation report.
46
+ Args:
47
+ file: The URL or path to submission file
48
+ schema: The URL or path to YAML file (submission schema)
49
+ report: The URL or path to store the validation results
50
+ """
51
+ with open(file, "r", encoding="utf8") as json_file:
52
+ submission_json = yaml.safe_load(json_file)
53
+ if submission_json is None:
54
+ raise EOFError(f"<{file}> is empty! Nothing to validate!")
55
+ validation_report = validate(
56
+ str(Path(schema).resolve()),
57
+ target_class=target_class,
58
+ obj=submission_json,
59
+ plugins=DEFAULT_PLUGINS,
60
+ )
61
+ if validation_report.valid:
62
+ default_validation_results = validation_report.validation_results
63
+ validation_report = validate(
64
+ str(Path(schema).resolve()),
65
+ target_class=target_class,
66
+ obj=submission_json,
67
+ plugins=VALIDATION_PLUGINS,
68
+ )
69
+ validation_report.validation_results = (
70
+ default_validation_results + validation_report.validation_results
71
+ )
72
+ else:
73
+ typer.echo(
74
+ "JSON schema validation failed. Subsequent validations skipped.", err=True
75
+ )
76
+ with open(report, "w", encoding="utf-8") as sub:
77
+ json.dump(
78
+ validation_report.dict(exclude_unset=True, exclude_none=True),
79
+ sub,
80
+ ensure_ascii=False,
81
+ indent=4,
82
+ )
83
+ return validation_report.valid
84
+
85
+
86
+ @cli.command()
87
+ def main(
88
+ schema: Path = typer.Option(
89
+ ..., "--schema", "-s", help="Path to metadata schema (modelled using LinkML)"
90
+ ),
91
+ input_file: Path = typer.Option(
92
+ ...,
93
+ "--input",
94
+ "-i",
95
+ file_okay=True,
96
+ dir_okay=False,
97
+ help="Path to submission file in JSON format to be validated",
98
+ ),
99
+ report: Path = typer.Option(
100
+ ...,
101
+ "--report",
102
+ "-r",
103
+ file_okay=True,
104
+ dir_okay=False,
105
+ writable=True,
106
+ help="Path to resulting validation report",
107
+ ),
108
+ target_class: Optional[str] = typer.Option(None, help="The root class name"),
109
+ ):
110
+ """
111
+ GHGA Validator
112
+
113
+ ghga-validator is a command line utility to validate metadata w.r.t. its
114
+ compliance to the GHGA Metadata Model. It takes metadata encoded in JSON of
115
+ YAML format and produces a validation report in JSON format.
116
+ """
117
+ typer.echo("Start validating...")
118
+ if not target_class:
119
+ target_class = get_target_class(str(Path(schema).resolve()))
120
+ if not target_class:
121
+ raise TypeError(
122
+ "Target class cannot be inferred,"
123
+ + "please specify the 'target_class' argument"
124
+ )
125
+ if validate_json(input_file, schema, report, target_class):
126
+ typer.echo(f"<{input_file}> is valid!")
127
+ else:
128
+ typer.echo(
129
+ f"<{input_file}> is invalid! Look at <{report}> for validation report"
130
+ )
@@ -0,0 +1,19 @@
1
+ # Copyright 2021 - 2023 Universität Tübingen, DKFZ, EMBL, and Universität zu Köln
2
+ # for the German Human Genome-Phenome Archive (GHGA)
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+
16
+ """
17
+ This sub-package contains the main business functionality of this service.
18
+ It should not contain any service API-related code.
19
+ """
@@ -0,0 +1,83 @@
1
+ # Copyright 2021 - 2023 Universität Tübingen, DKFZ, EMBL, and Universität zu Köln
2
+ # for the German Human Genome-Phenome Archive (GHGA)
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+ # Copyright 2021 - 2023 Universität Tübingen, DKFZ, EMBL, and Universität zu Köln
17
+ # for the German Human Genome-Phenome Archive (GHGA)
18
+ #
19
+ # Licensed under the Apache License, Version 2.0 (the "License");
20
+ # you may not use this file except in compliance with the License.
21
+ # You may obtain a copy of the License at
22
+ #
23
+ # http://www.apache.org/licenses/LICENSE-2.0
24
+ #
25
+ # Unless required by applicable law or agreed to in writing, software
26
+ # distributed under the License is distributed on an "AS IS" BASIS,
27
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
28
+ # See the License for the specific language governing permissions and
29
+ # limitations under the License.
30
+ #
31
+
32
+ """Validation utilities"""
33
+
34
+ from typing import Dict, List, Optional
35
+
36
+ from linkml.utils.datautils import infer_root_class
37
+ from linkml_runtime.utils.schemaview import SchemaView
38
+ from linkml_validator.models import ValidationReport
39
+ from linkml_validator.validator import Validator
40
+
41
+
42
+ def get_validator(schema: str, plugins: List[Dict]) -> Validator:
43
+ """
44
+ Get an instance of Validator.
45
+ Args:
46
+ schema: The schema YAML
47
+ plugins: A list of plugins to use
48
+ Returns:
49
+ Validator: An instance of Validator
50
+ """
51
+ validator = Validator(schema, plugins=plugins)
52
+ return validator
53
+
54
+
55
+ def validate(
56
+ schema: str, target_class: Optional[str], obj: Dict, plugins: List[Dict]
57
+ ) -> ValidationReport:
58
+ """
59
+ Validate an object of a particular type against a given schema.
60
+ Args:
61
+ schema: The URL or path to the schema YAML
62
+ obj: The object to validate
63
+ obj_type: The object type (schema type)
64
+ """
65
+ validator = get_validator(schema=schema, plugins=plugins)
66
+ report = validator.validate(
67
+ obj, target_class, exclude_object=True, truncate_message=True
68
+ )
69
+ return report
70
+
71
+
72
+ def get_target_class(schema: str) -> Optional[str]:
73
+ """
74
+ Infer the root class from schema
75
+ Args:
76
+ schema (str): YAML schema as the string
77
+
78
+ Returns:
79
+ class name for root class, if found in the scheme
80
+ """
81
+ with open(schema, "r", encoding="utf8") as file:
82
+ input_schema = file.read()
83
+ return infer_root_class(SchemaView(input_schema))