Skip to content

Commit da1082e

Browse files
committed
RFC #30: remove annotation names and use $id URLs instead.
1 parent a395797 commit da1082e

File tree

1 file changed

+6
-18
lines changed

1 file changed

+6
-18
lines changed

text/0000-component-metadata.md

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,6 @@ An `Annotation` class has a name (e.g. `"org.amaranth-lang.amaranth-soc.memory-m
178178

179179
```python3
180180
class AsyncSerialAnnotation(Annotation):
181-
name = "com.example.foo.serial"
182181
schema = {
183182
"$schema": "https://json-schema.org/draft/2020-12/schema",
184183
"$id": "https://example.com/schema/foo/1.0/serial.json",
@@ -311,7 +310,7 @@ The JSON object returned by ``serial.metadata.as_json()`` will now use this anno
311310
}
312311
},
313312
"annotations": {
314-
"com.example.foo.serial": {
313+
"https://example.com/schema/foo/1.0/serial.json": {
315314
"data_bits": 8,
316315
"parity": "none"
317316
}
@@ -320,9 +319,9 @@ The JSON object returned by ``serial.metadata.as_json()`` will now use this anno
320319
}
321320
```
322321

323-
#### Annotation names and schema URLs
322+
#### Annotation schema URLs
324323

325-
An `Annotation` schema must have a `"$id"` property, which holds an URL that serves as its unique identifier. This URL must have the following format:
324+
An `Annotation` schema must have a `"$id"` property, which holds an URL that serves as its unique identifier. The following convention is required for the `"$id"` of schemas hosted at https://amaranth-lang.org, and suggested otherwise:
326325

327326
`<protocol>://<domain>/schema/<package>/<version>/<path>.json`
328327

@@ -333,17 +332,10 @@ where:
333332
* `<version>` is the version of the aforementioned package;
334333
* `<path>` is a non-empty string.
335334

336-
An `Annotation` name should be retrievable from the `"$id"` property of its schema. Its name is the concatenation of the following parts, separated by `"."`:
335+
For example:
337336

338-
* `<domain>`, reversed (e.g. "com.example");
339-
* `<package>`;
340-
* `<path>`, split using `"/"` as separator.
341-
342-
Some examples of valid schema URLs:
343-
344-
- "https://example.github.io/schema/foo/1.0/serial.json" for the "io.github.example.foo.serial" annotation;
345-
- "https://amaranth-lang.org/schema/amaranth/0.4/fifo.json" for "org.amaranth-lang.amaranth.fifo";
346-
- "https://amaranth-lang.org/schema/amaranth-soc/0.1/memory-map.json" for "org.amaranth-lang.amaranth-soc.memory-map".
337+
- "https://amaranth-lang.org/schema/amaranth/0.5/fifo.json";
338+
- "https://amaranth-lang.org/schema/amaranth-soc/0.1/memory-map.json".
347339

348340
Changes to schema definitions hosted at https://amaranth-lang.org should follow the [RFC process](https://github.com/amaranth-lang/rfcs).
349341

@@ -353,11 +345,9 @@ Changes to schema definitions hosted at https://amaranth-lang.org should follow
353345
### Annotations
354346

355347
- add an `Annotation` base class to `amaranth.lib.meta`, with:
356-
* a `.name` "abstract" class attribute, which must be a string (e.g. "org.amaranth-lang.amaranth-soc.memory-map").
357348
* a `.schema` "abstract" class attribute, which must be a JSON schema, as a dict.
358349
* a `.__init_subclass__()` class method, which raises an exception if:
359350
- `.schema` does not comply with the [2020-12 draft](https://json-schema.org/specification-links#2020-12) of the JSON Schema specification.
360-
- `.name` cannot be extracted from the `.schema["$id"]` URL (as explained [here](#annotation-names-and-schema-urls)).
361351
- a `.origin` attribute, which returns the Python object described by an annotation instance.
362352
* a `.validate()` class method, which takes a JSON instance as argument. An exception is raised if the instance does not comply with the schema.
363353
* a `.as_json()` abstract method, which must return a JSON instance, as a dict. This instance must be compliant with `.schema`, i.e. `self.validate(self.as_json())` must succeed.
@@ -369,7 +359,6 @@ The following changes are made to `amaranth.lib.wiring`:
369359

370360
The following changes are made to `amaranth.lib.wiring`:
371361
- add a `ComponentMetadata` class, with:
372-
- a `.name` class attribute, which returns `"org.amaranth-lang.amaranth.component"`.
373362
- a `.schema` class attribute, which returns a JSON schema of component metadata. Its definition is detailed [below](#component-metadata-schema).
374363
- a `.validate()` class method, which takes a JSON instance as argument. An exception is raised if the instance does not comply with the schema.
375364
- `.__init__()` takes a `Component` object as parameter.
@@ -381,7 +370,6 @@ The following changes are made to `amaranth.lib.wiring`:
381370

382371
```python3
383372
class ComponentMetadata(Annotation):
384-
name = "org.amaranth-lang.amaranth.component"
385373
schema = {
386374
"$schema": "https://json-schema.org/draft/2020-12/schema",
387375
"$id": "https://amaranth-lang.org/schema/amaranth/0.5/component.json",

0 commit comments

Comments
 (0)