Merge ~jslarraz/review-tools:schema-split-definitions into review-tools:master

Proposed by Jorge Sancho Larraz
Status: Work in progress
Proposed branch: ~jslarraz/review-tools:schema-split-definitions
Merge into: review-tools:master
Diff against target: 97 lines (+28/-15)
4 files modified
bin/store-query (+4/-10)
reviewtools/schemas/definitions.json (+9/-0)
reviewtools/schemas/snap.json (+9/-2)
reviewtools/tests/schemas/test_schema_snap.py (+6/-3)
Reviewer Review Type Date Requested Status
Alex Murray Approve
Review via email: mp+466423@code.launchpad.net

Commit message

rt/schemas,bin/store-query: move architectures list to a new definitions.json

To post a comment you must log in.
Revision history for this message
Jorge Sancho Larraz (jslarraz) wrote (last edit ):

Stripping some value definitions from the snap.yaml schema will allow us to reuse them in the project (architectures, types, etc. in snap.yaml and snapcraft.yaml) or among projects (title, summary, etc. for snaps, rocks, etc.)

Reference to documents in local filesystem does not work on focal. This approach would require to move to a newer release or to place schemas in a publicly accessible location under a stable url pattern or ideally both.

Thoughts about it?

Revision history for this message
Alex Murray (alexmurray) wrote :

Perhaps I am missing something, but is it possible to load the schema and use the values directly from it rather than storing them in a separate file?

Revision history for this message
Jorge Sancho Larraz (jslarraz) wrote :

That's certainly possible as done in https://git.launchpad.net/~jslarraz/review-tools/commit/?id=22827dce8143d4e685f992c049a2935a744285ba.

However, it brings no re usability benefit. For example, looking at this MR https://code.launchpad.net/~jslarraz/review-tools/+git/review-tools/+merge/466454, ideally at some point we would like to validate that the declaration is properly formatted using a declaration schema rather than in code. In such a situation, I think it will be better (for the maintainability) to define the snap types in a separate file that can be imported by both snap.json and declaration.json rather than two separate list.

Revision history for this message
Alex Murray (alexmurray) wrote :

Ah right - so since we want to have separate JSON schemas for validating the snap declaration and for validating the snap yaml, we want to then share common type definitions between the two - this was the context I was missing.

So I am not against this change then but as we don't yet have a snap declaration schema, I think it seems a bit like premature optimisation to split out the types into a separate json schema at this time - however, since you are leading this work I am happy to go with your preferred approach. Feel free to go forward with this separate definitions.json approach :)

LGTM!

review: Approve

Unmerged commits

46940fd... by Jorge Sancho Larraz

rt/schemas,bin/store-query: move architectures list to a new definitions.json

Failed
[FAILED] test:0 (build)
[WAITING] coverage:0 (build)
12 of 2 results

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
diff --git a/bin/store-query b/bin/store-query
index e6b22b8..e1938c5 100755
--- a/bin/store-query
+++ b/bin/store-query
@@ -220,20 +220,14 @@ def _get_snap_yaml(snap_name, channel=None, arch=None):
220 headers = {"Snap-Device-Series": snap_device_series}220 headers = {"Snap-Device-Series": snap_device_series}
221 res = _fetch(url, headers)221 res = _fetch(url, headers)
222222
223 with open("reviewtools/schemas/definitions.json") as fd:
224 definitions = json.loads(fd.read())
225
223 risk = "stable"226 risk = "stable"
224 track = "latest"227 track = "latest"
225 if arch is None:228 if arch is None:
226 arch = "amd64"229 arch = "amd64"
227 if arch not in [230 if arch not in definitions["$defs"]["architecture"]["enum"]:
228 "amd64",
229 "arm64",
230 "armhf",
231 "i386",
232 "powerpc",
233 "ppc64el",
234 "riscv64",
235 "s390x",
236 ]:
237 raise ValueError("Unsupported arch '%s'" % arch)231 raise ValueError("Unsupported arch '%s'" % arch)
238232
239 if channel is not None:233 if channel is not None:
diff --git a/reviewtools/schemas/definitions.json b/reviewtools/schemas/definitions.json
240new file mode 100644234new file mode 100644
index 0000000..ae8b4a8
--- /dev/null
+++ b/reviewtools/schemas/definitions.json
@@ -0,0 +1,9 @@
1{
2 "description": "snap related definitions",
3 "$defs": {
4 "architecture": {
5 "type": "string",
6 "enum": ["amd64", "arm64", "armhf", "i386", "powerpc", "ppc64el", "riscv64", "s390x"]
7 }
8 }
9}
0\ No newline at end of file10\ No newline at end of file
diff --git a/reviewtools/schemas/snap.json b/reviewtools/schemas/snap.json
index 8d9c6bd..15809b5 100644
--- a/reviewtools/schemas/snap.json
+++ b/reviewtools/schemas/snap.json
@@ -21,8 +21,15 @@
21 "type": "array",21 "type": "array",
22 "uniqueItems": true,22 "uniqueItems": true,
23 "items": {23 "items": {
24 "type": "string",24 "anyOf": [
25 "enum": ["all", "amd64", "arm64", "armhf", "i386", "powerpc", "ppc64el", "riscv64", "s390x"]25 {
26 "type": "string",
27 "enum": ["all"]
28 },
29 {
30 "$ref": "definitions.json#/$defs/architecture"
31 }
32 ]
26 },33 },
27 "minItems": 1,34 "minItems": 1,
28 "default": ["all"]35 "default": ["all"]
diff --git a/reviewtools/tests/schemas/test_schema_snap.py b/reviewtools/tests/schemas/test_schema_snap.py
index ed4853d..c7ff6ab 100644
--- a/reviewtools/tests/schemas/test_schema_snap.py
+++ b/reviewtools/tests/schemas/test_schema_snap.py
@@ -144,19 +144,22 @@ class TestSchemaSnap(TestSchemaBase):
144 # test_check_architectures_single_ppc64el144 # test_check_architectures_single_ppc64el
145 (["ppc64el"], None),145 (["ppc64el"], None),
146 # test_check_architectures_single_nonexistent146 # test_check_architectures_single_nonexistent
147 (["nonexistent"], "'nonexistent' is not one of "),147 (
148 ["nonexistent"],
149 "'nonexistent' is not valid under any of the given schemas",
150 ),
148 # test_check_snappy_valid_arch_multi151 # test_check_snappy_valid_arch_multi
149 (["amd64", "armhf"], None),152 (["amd64", "armhf"], None),
150 # test_check_snappy_valid_arch_multi2153 # test_check_snappy_valid_arch_multi2
151 (["armhf", "arm64", "i386"], None),154 (["armhf", "arm64", "i386"], None),
152 # test_check_architectures_bad_entry155 # test_check_architectures_bad_entry
153 ([{}], "{} is not of type 'string'"),156 ([{}], "{} is not valid under any of the given schemas"),
154 # ### integer157 # ### integer
155 (2, "{value} is not of type 'array'"),158 (2, "{value} is not of type 'array'"),
156 # ### empty TODO: snapcraft does not allow empty lists, snapd does159 # ### empty TODO: snapcraft does not allow empty lists, snapd does
157 ([], "{value} is too short"),160 ([], "{value} is too short"),
158 # ### empty value161 # ### empty value
159 ([""], "'' is not one of "),162 ([""], "'' is not valid under any of the given schemas"),
160 # ### duplicated value TODO: snapcraft does not duplicated values, snapd does163 # ### duplicated value TODO: snapcraft does not duplicated values, snapd does
161 (["amd64", "amd64"], "{value} has non-unique elements"),164 (["amd64", "amd64"], "{value} has non-unique elements"),
162 ]:165 ]:

Subscribers

People subscribed via source and target branches