-
Notifications
You must be signed in to change notification settings - Fork 0
Set up infrastructure for supporting multiple schemas #38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| """Module defining different schemas available for use.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from functools import singledispatch | ||
|
|
||
| from schema import Schema as Schema | ||
|
|
||
| from .base import base_schema | ||
|
|
||
| SCHEMAS = { | ||
| "base": base_schema, | ||
| "default": base_schema, | ||
| } | ||
|
|
||
|
|
||
| @singledispatch | ||
| def get_schema(schema) -> Schema: | ||
| """ | ||
| Get schema. | ||
|
|
||
| Parameters | ||
| ---------- | ||
| schema : Schema | str | ||
| Schema to get. | ||
|
|
||
| Returns | ||
| ------- | ||
| Schema | ||
| Desired schema. | ||
|
|
||
| Raises | ||
| ------ | ||
| NotImplementedError | ||
| Passed an invalid type. | ||
|
|
||
| Examples | ||
| -------- | ||
| >>> get_schema(base_schema) | ||
| >>> get_schema("default") | ||
| """ | ||
| raise NotImplementedError(f"Cannot find schema with {type(schema).__name__}") | ||
|
|
||
|
|
||
| @get_schema.register | ||
| def _(schema: Schema) -> Schema: | ||
| return schema | ||
|
|
||
|
|
||
| @get_schema.register | ||
| def _(schema: str) -> Schema: | ||
| return SCHEMAS[schema] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,108 @@ | ||
| """Parsing schema for metadata.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from datetime import date | ||
| from urllib.parse import urlparse, urlunparse | ||
|
|
||
| from schema import And, Literal, Optional, Or, Regex, Schema, Use | ||
|
|
||
| ORCID_ID_RE = r"(\d{4}-){3}\d{4}" | ||
| UUID_RE = r"\d{8}-(\d{4}-){3}\d{12}" | ||
|
|
||
| id_schema = Or( | ||
| { | ||
| Literal("scheme", description="ID scheme."): "orcid", | ||
| Literal("identifier", description="An [ORCID](https://orcid.org)."): Regex(ORCID_ID_RE), | ||
| }, | ||
| { | ||
| Optional(Literal("scheme", description="ID scheme."), default="doi"): "doi", | ||
| Literal("identifier", description="A [DOI](https://www.doi.org)"): And( | ||
| Use(urlparse), lambda x: x.scheme and x.netloc, Use(urlunparse) | ||
| ), | ||
| }, | ||
| ) | ||
|
|
||
| creator_schema = Schema( | ||
| { | ||
| Optional(Literal("affiliations", description="Member affiliations.")): [ | ||
| { | ||
| Literal("name", description="Name of institution."): str, | ||
| }, | ||
| ], | ||
| Literal("person_or_org", description="Person or organisation."): { | ||
| Or( | ||
| Literal("name", description="Full set of given names."), | ||
| Literal("family_name", description="Family name(s)."), | ||
| ): And(str, len), | ||
| Optional(Literal("given_name", description="Given name(s).")): And(str, len), | ||
| Optional(Literal("identifiers", description="ORCIDs or other IDs")): [id_schema], | ||
| Literal("type", description="Personal or organisation."): Or("personal"), | ||
| }, | ||
| }, | ||
| ignore_extra_keys=True, | ||
| ) | ||
|
|
||
| metadata_schema = Schema( | ||
| { | ||
| Literal("title", description="Title of resource."): And(str, len), | ||
| Literal("description", description="Summary of resource."): And(str, len), | ||
| Literal("creators", description="List of creators."): [creator_schema], | ||
| Literal("rights", description="Rights or license."): [ | ||
| { | ||
| Literal("id", description="ID of rights or license."): Or("cc-by-4.0"), | ||
| }, | ||
| ], | ||
| Literal("resource_type", description="Type of resource."): { | ||
| Literal("id", description="Resource class."): Or("model"), | ||
| }, | ||
| Optional( | ||
| Literal("subjects", description="List of keywords defining subjects resource covers."), | ||
| default=[], | ||
| ): [{Literal("subject", description="Subject keyword."): str}], | ||
| Literal("version", description="Current version of resource."): Regex(r"^v\d+(\.\d+)*"), | ||
| Optional(Literal("publisher", description="Publisher of resource.")): str, | ||
| Optional(Literal("publication_date", description="Date of publication of resource.")): Or( | ||
| date.fromisoformat, date.fromtimestamp | ||
| ), | ||
| Optional( | ||
| Literal("identifiers", description="Resource identifiers such as ORCID or DOI.") | ||
| ): [id_schema], | ||
| }, | ||
| ) | ||
|
|
||
| base_schema = Schema( | ||
| { | ||
| Optional( | ||
| Literal("access", description="Accessibility of data outside of owners."), | ||
| default={"files": "public", "record": "public"}, | ||
| ): { | ||
| Optional(Literal("embargo", description="Details of resource embargo.")): { | ||
| Literal("active", description="Whether resource is under embargo."): bool, | ||
| Literal("reason", description="Cause for embargo."): Or(str, None), | ||
| }, | ||
| Optional( | ||
| Literal("files", description="Accessibility to individual files."), default="public" | ||
| ): Or("public", "private"), | ||
| Optional( | ||
| Literal("record", description="Accessibility to record as a whole."), | ||
| default="public", | ||
| ): Or("public", "private"), | ||
| Optional(Literal("status", description="Current status or resource.")): Or( | ||
| "open", "closed" | ||
| ), | ||
| }, | ||
| Optional(Literal("files", description="Details of files.")): { | ||
| Literal("enabled", description="Whether file is enabled."): bool | ||
| }, | ||
| Literal("custom_fields", description="Block for custom data."): { | ||
| Literal("dsmd", description="Domain specific metadata (dsmd)."): [dict] | ||
| }, | ||
| Literal("metadata", description="Resource metadata."): metadata_schema, | ||
| Optional( | ||
| Literal("community", description="UUID of community associated with resource.") | ||
| ): Regex(UUID_RE), | ||
| }, | ||
| description="Base schema from which community specific schemas are built.", | ||
| name="base", | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| data\_collections\_api.cli package | ||
| ================================== | ||
|
|
||
| Submodules | ||
| ---------- | ||
|
|
||
| data\_collections\_api.cli.data\_collections\_main module | ||
| --------------------------------------------------------- | ||
|
|
||
| .. automodule:: data_collections_api.cli.data_collections_main | ||
| :members: | ||
| :show-inheritance: | ||
| :undoc-members: | ||
|
|
||
| data\_collections\_api.cli.record\_upload module | ||
| ------------------------------------------------ | ||
|
|
||
| .. automodule:: data_collections_api.cli.record_upload | ||
| :members: | ||
| :show-inheritance: | ||
| :undoc-members: | ||
|
|
||
| Module contents | ||
| --------------- | ||
|
|
||
| .. automodule:: data_collections_api.cli | ||
| :members: | ||
| :show-inheritance: | ||
| :undoc-members: |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.