oarepo-runtime 1.5.129__py3-none-any.whl → 1.5.130__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.
@@ -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(service_name, record_file, verbose):
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
- for idx, d in enumerate(data):
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
- click.secho(
77
- f"Marshmallow validation of record idx {idx+1} has been successful",
78
- fg="green",
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
- rec: Record = config.record_cls(loaded)
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
- click.secho(
91
- f"Pre-commit hook of record idx {idx+1} has been successful", fg="green"
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)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: oarepo-runtime
3
- Version: 1.5.129
3
+ Version: 1.5.130
4
4
  Summary: A set of runtime extensions of Invenio repository
5
5
  Description-Content-Type: text/markdown
6
6
  License-File: LICENSE
@@ -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=HpSvHQCGHlrdgdpKix9cIlzlBoJEiT1vACZdMnOUGEY,2827
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
@@ -150,9 +150,9 @@ tests/marshmallow_to_json/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJW
150
150
  tests/marshmallow_to_json/test_datacite_ui_schema.py,sha256=82iLj8nW45lZOUewpWbLX3mpSkpa9lxo-vK-Qtv_1bU,48552
151
151
  tests/marshmallow_to_json/test_simple_schema.py,sha256=izZN9p0v6kovtSZ6AdxBYmK_c6ZOti2_z_wPT_zXIr0,1500
152
152
  tests/pkg_data/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
153
- oarepo_runtime-1.5.129.dist-info/LICENSE,sha256=h2uWz0OaB3EN-J1ImdGJZzc7yvfQjvHVYdUhQ-H7ypY,1064
154
- oarepo_runtime-1.5.129.dist-info/METADATA,sha256=MEE87EgTSva-yYSr22h56-RtZxqaM9r1VQG0HEtOleg,4721
155
- oarepo_runtime-1.5.129.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
156
- oarepo_runtime-1.5.129.dist-info/entry_points.txt,sha256=k7O5LZUOGsVeSpB7ulU0txBUNp1CVQG7Q7TJIVTPbzU,491
157
- oarepo_runtime-1.5.129.dist-info/top_level.txt,sha256=bHhlkT1_RQC4IkfTQCqA3iN4KCB6cSFQlsXpQMSP-bE,21
158
- oarepo_runtime-1.5.129.dist-info/RECORD,,
153
+ oarepo_runtime-1.5.130.dist-info/LICENSE,sha256=h2uWz0OaB3EN-J1ImdGJZzc7yvfQjvHVYdUhQ-H7ypY,1064
154
+ oarepo_runtime-1.5.130.dist-info/METADATA,sha256=z3g1h_tsoffkQAq5whumI2ejrVxXc5uxs_2L5wV0-mo,4721
155
+ oarepo_runtime-1.5.130.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
156
+ oarepo_runtime-1.5.130.dist-info/entry_points.txt,sha256=k7O5LZUOGsVeSpB7ulU0txBUNp1CVQG7Q7TJIVTPbzU,491
157
+ oarepo_runtime-1.5.130.dist-info/top_level.txt,sha256=bHhlkT1_RQC4IkfTQCqA3iN4KCB6cSFQlsXpQMSP-bE,21
158
+ oarepo_runtime-1.5.130.dist-info/RECORD,,