oarepo-runtime 1.5.129__py3-none-any.whl → 1.5.131__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.
- oarepo_runtime/cli/validate.py +58 -11
- oarepo_runtime/records/pid_providers.py +22 -0
- {oarepo_runtime-1.5.129.dist-info → oarepo_runtime-1.5.131.dist-info}/METADATA +3 -2
- {oarepo_runtime-1.5.129.dist-info → oarepo_runtime-1.5.131.dist-info}/RECORD +8 -7
- {oarepo_runtime-1.5.129.dist-info → oarepo_runtime-1.5.131.dist-info}/WHEEL +1 -1
- {oarepo_runtime-1.5.129.dist-info → oarepo_runtime-1.5.131.dist-info}/entry_points.txt +0 -0
- {oarepo_runtime-1.5.129.dist-info → oarepo_runtime-1.5.131.dist-info/licenses}/LICENSE +0 -0
- {oarepo_runtime-1.5.129.dist-info → oarepo_runtime-1.5.131.dist-info}/top_level.txt +0 -0
oarepo_runtime/cli/validate.py
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
import sys
|
2
|
+
import traceback
|
2
3
|
|
3
4
|
import click
|
4
5
|
import yaml
|
@@ -6,6 +7,7 @@ from flask.cli import with_appcontext
|
|
6
7
|
from invenio_db import db
|
7
8
|
from invenio_records import Record
|
8
9
|
from invenio_records_resources.proxies import current_service_registry
|
10
|
+
from tqdm import tqdm
|
9
11
|
|
10
12
|
from .base import oarepo
|
11
13
|
|
@@ -14,7 +16,6 @@ try:
|
|
14
16
|
except ImportError:
|
15
17
|
import json
|
16
18
|
|
17
|
-
import sys
|
18
19
|
from io import StringIO
|
19
20
|
|
20
21
|
|
@@ -34,9 +35,18 @@ def dump_data(d):
|
|
34
35
|
)
|
35
36
|
@click.argument("service-name")
|
36
37
|
@click.argument("record-file", required=False)
|
38
|
+
@click.option("--community", help="Community name")
|
37
39
|
@click.option("--verbose/--no-verbose", is_flag=True)
|
40
|
+
@click.option("--with-stacktrace", is_flag=True)
|
41
|
+
@click.option(
|
42
|
+
"--fail-on-error",
|
43
|
+
is_flag=True,
|
44
|
+
help="Fail on the first error (for multiple records)",
|
45
|
+
)
|
38
46
|
@with_appcontext
|
39
|
-
def validate(
|
47
|
+
def validate(
|
48
|
+
service_name, record_file, community, verbose, with_stacktrace, fail_on_error
|
49
|
+
):
|
40
50
|
try:
|
41
51
|
service = current_service_registry.get(service_name)
|
42
52
|
except KeyError:
|
@@ -61,7 +71,13 @@ def validate(service_name, record_file, verbose):
|
|
61
71
|
|
62
72
|
if not isinstance(data, list):
|
63
73
|
data = [data]
|
64
|
-
|
74
|
+
|
75
|
+
errors_count = 0
|
76
|
+
for idx, d in enumerate(tqdm(data)):
|
77
|
+
if community:
|
78
|
+
d.setdefault("parent", {}).setdefault("communities", {})[
|
79
|
+
"default"
|
80
|
+
] = community
|
65
81
|
try:
|
66
82
|
loaded = schema().load(d)
|
67
83
|
except Exception as e:
|
@@ -71,25 +87,44 @@ def validate(service_name, record_file, verbose):
|
|
71
87
|
)
|
72
88
|
click.secho(dump_data(d))
|
73
89
|
click.secho(e)
|
90
|
+
if with_stacktrace:
|
91
|
+
traceback.print_exc()
|
92
|
+
if fail_on_error:
|
93
|
+
sys.exit(1)
|
94
|
+
errors_count += 1
|
74
95
|
continue
|
75
96
|
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
97
|
+
if verbose:
|
98
|
+
click.secho(
|
99
|
+
f"Marshmallow validation of record idx {idx+1} has been successful",
|
100
|
+
fg="green",
|
101
|
+
)
|
80
102
|
|
81
|
-
|
103
|
+
if hasattr(config, "draft_cls"):
|
104
|
+
record_cls = config.draft_cls
|
105
|
+
else:
|
106
|
+
record_cls = config.record_cls
|
82
107
|
|
83
108
|
# Run pre create extensions to check vocabularies
|
84
109
|
try:
|
85
110
|
with db.session.begin_nested():
|
111
|
+
|
112
|
+
rec: Record = record_cls(
|
113
|
+
loaded, model=record_cls.model_cls(id=None, data=data)
|
114
|
+
)
|
115
|
+
if record_cls.parent_record_cls:
|
116
|
+
parent = record_cls.parent_record_cls(loaded["parent"])
|
117
|
+
rec.parent = parent
|
118
|
+
|
86
119
|
for e in rec._extensions:
|
87
120
|
e.pre_commit(rec)
|
88
121
|
raise CheckOk()
|
89
122
|
except CheckOk:
|
90
|
-
|
91
|
-
|
92
|
-
|
123
|
+
if verbose:
|
124
|
+
click.secho(
|
125
|
+
f"Pre-commit hook of record idx {idx+1} has been successful",
|
126
|
+
fg="green",
|
127
|
+
)
|
93
128
|
except Exception as e:
|
94
129
|
click.secho(
|
95
130
|
f"Pre-commit validation of record idx {idx + 1} failed",
|
@@ -97,7 +132,19 @@ def validate(service_name, record_file, verbose):
|
|
97
132
|
)
|
98
133
|
click.secho(dump_data(d))
|
99
134
|
click.secho(e)
|
135
|
+
if with_stacktrace:
|
136
|
+
traceback.print_exc()
|
137
|
+
if fail_on_error:
|
138
|
+
sys.exit(1)
|
139
|
+
errors_count += 1
|
100
140
|
continue
|
101
141
|
|
102
142
|
if verbose:
|
103
143
|
yaml.safe_dump(loaded, sys.stdout, allow_unicode=True)
|
144
|
+
|
145
|
+
if errors_count:
|
146
|
+
click.secho(f"Validation finished with {errors_count} errors", fg="red")
|
147
|
+
sys.exit(1)
|
148
|
+
else:
|
149
|
+
click.secho("Validation finished successfully", fg="green")
|
150
|
+
sys.exit(0)
|
@@ -0,0 +1,22 @@
|
|
1
|
+
from invenio_pidstore.models import PersistentIdentifier, PIDStatus
|
2
|
+
|
3
|
+
|
4
|
+
class UniversalPIDMixin:
|
5
|
+
unpid_pid_type = "unpid"
|
6
|
+
unpid_default_status = PIDStatus.REGISTERED
|
7
|
+
|
8
|
+
@classmethod
|
9
|
+
def create(cls, object_type=None, object_uuid=None, options=None, **kwargs):
|
10
|
+
pid = super().create(
|
11
|
+
object_type=object_type, object_uuid=object_uuid, options=options, **kwargs
|
12
|
+
)
|
13
|
+
assert pid.pid.pid_value is not None
|
14
|
+
control_pid = PersistentIdentifier.create(
|
15
|
+
cls.unpid_pid_type,
|
16
|
+
pid.pid.pid_value,
|
17
|
+
pid_provider=None,
|
18
|
+
object_type=object_type,
|
19
|
+
object_uuid=object_uuid,
|
20
|
+
status=cls.unpid_default_status,
|
21
|
+
)
|
22
|
+
return pid
|
@@ -1,6 +1,6 @@
|
|
1
|
-
Metadata-Version: 2.
|
1
|
+
Metadata-Version: 2.4
|
2
2
|
Name: oarepo-runtime
|
3
|
-
Version: 1.5.
|
3
|
+
Version: 1.5.131
|
4
4
|
Summary: A set of runtime extensions of Invenio repository
|
5
5
|
Description-Content-Type: text/markdown
|
6
6
|
License-File: LICENSE
|
@@ -22,6 +22,7 @@ Requires-Dist: oarepo-tools; extra == "dev"
|
|
22
22
|
Provides-Extra: tests
|
23
23
|
Requires-Dist: pytest>=7.1.2; extra == "tests"
|
24
24
|
Requires-Dist: psutil; extra == "tests"
|
25
|
+
Dynamic: license-file
|
25
26
|
|
26
27
|
# OARepo runtime
|
27
28
|
|
@@ -13,7 +13,7 @@ oarepo_runtime/cli/check.py,sha256=sCe2PeokSHvNOXHFZ8YHF8NMhsu5nYjyuZuvXHJ6X18,5
|
|
13
13
|
oarepo_runtime/cli/configuration.py,sha256=M_19zrS0vo-7uHi047a3i4rQsK6pmp4QS0IEBAxMLZ0,2039
|
14
14
|
oarepo_runtime/cli/fixtures.py,sha256=_aMQqPnspG0JuL5ewYTBa3HY1RaoOAI0V2R5q7e5frw,5570
|
15
15
|
oarepo_runtime/cli/index.py,sha256=8Q2KZlAWjoMyZ9Ft9WIBJDws0ce15VF12o1tdYUP7AI,8936
|
16
|
-
oarepo_runtime/cli/validate.py,sha256=
|
16
|
+
oarepo_runtime/cli/validate.py,sha256=vcN7uj9tXOeQ4_vRv-ZYLc-aW43_qRYltJR8NiPLZKk,4318
|
17
17
|
oarepo_runtime/cli/permissions/__init__.py,sha256=2qufYdUoCb9kG7Zy0gKNW5lpRyqbVQSNsf7shLwrThM,198
|
18
18
|
oarepo_runtime/cli/permissions/base.py,sha256=Q5txKaofSzAlTVHn1fu5YurwF16Pkh63YB9U6xWYVAU,804
|
19
19
|
oarepo_runtime/cli/permissions/evaluate.py,sha256=gxkHySd1vM7lSjR-xXzcACkCKDYurl5c567Kq5FVzpM,2086
|
@@ -54,6 +54,7 @@ oarepo_runtime/info/permissions/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm
|
|
54
54
|
oarepo_runtime/info/permissions/debug.py,sha256=2gak5W64g_AAZoX8cCII2di4G_jBo1ZvnU5ceP_u6z4,6722
|
55
55
|
oarepo_runtime/records/__init__.py,sha256=JUf9_o09_6q4vuG43JzhSeTu7c-m_CVDSmgTQ7epYEo,1776
|
56
56
|
oarepo_runtime/records/drafts.py,sha256=8BRmxXcKyVMBQbMMhVScPS_T7lwvR8kGKYQAxaVaD1k,1371
|
57
|
+
oarepo_runtime/records/pid_providers.py,sha256=V9KIeffLoFwjh7PDEBkpmVQb2j7w9pgKr9OlHV5g8S4,736
|
57
58
|
oarepo_runtime/records/dumpers/__init__.py,sha256=OmzNhLdMNKibmCksnj9eTX9xPBG30dziiK3j3bAAp3k,233
|
58
59
|
oarepo_runtime/records/dumpers/edtf_interval.py,sha256=8bE3JlaR7b33rxDc7LW9R8jcwNI66Zb07Jee6YUmlrE,1231
|
59
60
|
oarepo_runtime/records/dumpers/multilingual_dumper.py,sha256=PbNFCLsiH4XV3E1v8xga_fzlcEImHy8OXn_UKh_8VBU,1090
|
@@ -146,13 +147,13 @@ oarepo_runtime/translations/en/LC_MESSAGES/messages.po,sha256=7-5S3iINOSFSI5gVdR
|
|
146
147
|
oarepo_runtime/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
147
148
|
oarepo_runtime/utils/functools.py,sha256=gKS9YZtlIYcDvdNA9cmYO00yjiXBYV1jg8VpcRUyQyg,1324
|
148
149
|
oarepo_runtime/utils/path.py,sha256=V1NVyk3m12_YLbj7QHYvUpE1wScO78bYsX1LOLeXDkI,3108
|
150
|
+
oarepo_runtime-1.5.131.dist-info/licenses/LICENSE,sha256=h2uWz0OaB3EN-J1ImdGJZzc7yvfQjvHVYdUhQ-H7ypY,1064
|
149
151
|
tests/marshmallow_to_json/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
150
152
|
tests/marshmallow_to_json/test_datacite_ui_schema.py,sha256=82iLj8nW45lZOUewpWbLX3mpSkpa9lxo-vK-Qtv_1bU,48552
|
151
153
|
tests/marshmallow_to_json/test_simple_schema.py,sha256=izZN9p0v6kovtSZ6AdxBYmK_c6ZOti2_z_wPT_zXIr0,1500
|
152
154
|
tests/pkg_data/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
153
|
-
oarepo_runtime-1.5.
|
154
|
-
oarepo_runtime-1.5.
|
155
|
-
oarepo_runtime-1.5.
|
156
|
-
oarepo_runtime-1.5.
|
157
|
-
oarepo_runtime-1.5.
|
158
|
-
oarepo_runtime-1.5.129.dist-info/RECORD,,
|
155
|
+
oarepo_runtime-1.5.131.dist-info/METADATA,sha256=L5WjE2XqzWZFq_xhsIJwdo7NwozJhSNbaT-iZpyCjS4,4743
|
156
|
+
oarepo_runtime-1.5.131.dist-info/WHEEL,sha256=0CuiUZ_p9E4cD6NyLD6UG80LBXYyiSYZOKDm5lp32xk,91
|
157
|
+
oarepo_runtime-1.5.131.dist-info/entry_points.txt,sha256=k7O5LZUOGsVeSpB7ulU0txBUNp1CVQG7Q7TJIVTPbzU,491
|
158
|
+
oarepo_runtime-1.5.131.dist-info/top_level.txt,sha256=bHhlkT1_RQC4IkfTQCqA3iN4KCB6cSFQlsXpQMSP-bE,21
|
159
|
+
oarepo_runtime-1.5.131.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|