Skip to content

Commit d4de480

Browse files
committed
checkpoint
1 parent eef9297 commit d4de480

File tree

96 files changed

+6697
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

96 files changed

+6697
-0
lines changed

linkml_model/__init__.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from linkml_model.types import String, Integer, Boolean, Float, Double, Decimal, Time, Date, Datetime, Uriorcurie, Uri, \
2+
Ncname, Objectidentifier, Nodeidentifier
3+
from linkml_model.extensions import Extension, Extensible
4+
from linkml_model.annotations import Annotation, Annotatable
5+
from linkml_model.meta import ElementName, SchemaDefinitionName, TypeDefinitionName, SubsetDefinitionName, DefinitionName, \
6+
EnumDefinitionName, SlotDefinitionName, ClassDefinitionName, PrefixPrefixPrefix, LocalNameLocalNameSource, \
7+
AltDescriptionSource, PermissibleValueText, Element, SchemaDefinition, TypeDefinition, SubsetDefinition, \
8+
Definition, EnumDefinition, SlotDefinition, ClassDefinition, Prefix, LocalName, Example, AltDescription, \
9+
PermissibleValue, PvFormulaOptions
10+

linkml_model/annotations.py

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
# Auto generated from annotations.yaml by pythongen.py version: 0.9.0
2+
# Generation date: 2021-03-25 11:34
3+
# Schema: annotations
4+
#
5+
# id: https://w3id.org/linkml/annotations
6+
# description: Annotations mixin
7+
# license: https://creativecommons.org/publicdomain/zero/1.0/
8+
9+
import dataclasses
10+
import sys
11+
import re
12+
from typing import Optional, List, Union, Dict, ClassVar, Any
13+
from dataclasses import dataclass
14+
15+
from linkml_runtime.utils.slot import Slot
16+
from linkml_runtime.utils.metamodelcore import empty_list, empty_dict, bnode
17+
from linkml_runtime.utils.yamlutils import YAMLRoot, extended_str, extended_float, extended_int
18+
from linkml_runtime.utils.dataclass_extensions_376 import dataclasses_init_fn_with_kwargs
19+
from linkml_runtime.utils.formatutils import camelcase, underscore, sfx
20+
from linkml_runtime.utils.enumerations import EnumDefinitionImpl
21+
from rdflib import Namespace, URIRef
22+
from linkml_runtime.utils.curienamespace import CurieNamespace
23+
from linkml_runtime.utils.metamodelcore import URIorCURIE
24+
from linkml_model.extensions import Extension
25+
from linkml_model.types import String, Uriorcurie
26+
27+
metamodel_version = "1.7.0"
28+
29+
# Overwrite dataclasses _init_fn to add **kwargs in __init__
30+
dataclasses._init_fn = dataclasses_init_fn_with_kwargs
31+
32+
# Namespaces
33+
LINKML = CurieNamespace('linkml', 'https://w3id.org/linkml/')
34+
DEFAULT_ = LINKML
35+
36+
37+
# Types
38+
39+
# Class references
40+
41+
42+
43+
@dataclass
44+
class Annotatable(YAMLRoot):
45+
"""
46+
mixin for classes that support annotations
47+
"""
48+
_inherited_slots: ClassVar[List[str]] = []
49+
50+
class_class_uri: ClassVar[URIRef] = LINKML.Annotatable
51+
class_class_curie: ClassVar[str] = "linkml:Annotatable"
52+
class_name: ClassVar[str] = "annotatable"
53+
class_model_uri: ClassVar[URIRef] = LINKML.Annotatable
54+
55+
annotations: Optional[Union[Union[dict, "Annotation"], List[Union[dict, "Annotation"]]]] = empty_list()
56+
57+
def __post_init__(self, *_: List[str], **kwargs: Dict[str, Any]):
58+
if self.annotations is None:
59+
self.annotations = []
60+
if not isinstance(self.annotations, list):
61+
self.annotations = [self.annotations]
62+
self._normalize_inlined_slot(slot_name="annotations", slot_type=Annotation, key_name="tag", inlined_as_list=True, keyed=False)
63+
64+
super().__post_init__(**kwargs)
65+
66+
67+
@dataclass
68+
class Annotation(Extension):
69+
"""
70+
a tag/value pair with the semantics of OWL Annotation
71+
"""
72+
_inherited_slots: ClassVar[List[str]] = []
73+
74+
class_class_uri: ClassVar[URIRef] = LINKML.Annotation
75+
class_class_curie: ClassVar[str] = "linkml:Annotation"
76+
class_name: ClassVar[str] = "annotation"
77+
class_model_uri: ClassVar[URIRef] = LINKML.Annotation
78+
79+
tag: Union[str, URIorCURIE] = None
80+
value: str = None
81+
annotations: Optional[Union[Union[dict, "Annotation"], List[Union[dict, "Annotation"]]]] = empty_list()
82+
83+
def __post_init__(self, *_: List[str], **kwargs: Dict[str, Any]):
84+
if self.annotations is None:
85+
self.annotations = []
86+
if not isinstance(self.annotations, list):
87+
self.annotations = [self.annotations]
88+
self._normalize_inlined_slot(slot_name="annotations", slot_type=Annotation, key_name="tag", inlined_as_list=True, keyed=False)
89+
90+
super().__post_init__(**kwargs)
91+
92+
93+
# Enumerations
94+
95+
96+
# Slots
97+

linkml_model/extensions.py

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
# Auto generated from extensions.yaml by pythongen.py version: 0.9.0
2+
# Generation date: 2021-03-25 11:34
3+
# Schema: extensions
4+
#
5+
# id: https://w3id.org/linkml/extensions
6+
# description: Extension mixin
7+
# license: https://creativecommons.org/publicdomain/zero/1.0/
8+
9+
import dataclasses
10+
import sys
11+
import re
12+
from typing import Optional, List, Union, Dict, ClassVar, Any
13+
from dataclasses import dataclass
14+
15+
from linkml_runtime.utils.slot import Slot
16+
from linkml_runtime.utils.metamodelcore import empty_list, empty_dict, bnode
17+
from linkml_runtime.utils.yamlutils import YAMLRoot, extended_str, extended_float, extended_int
18+
from linkml_runtime.utils.dataclass_extensions_376 import dataclasses_init_fn_with_kwargs
19+
from linkml_runtime.utils.formatutils import camelcase, underscore, sfx
20+
from linkml_runtime.utils.enumerations import EnumDefinitionImpl
21+
from rdflib import Namespace, URIRef
22+
from linkml_runtime.utils.curienamespace import CurieNamespace
23+
from linkml_runtime.utils.metamodelcore import URIorCURIE
24+
from linkml_model.types import String, Uriorcurie
25+
26+
metamodel_version = "1.7.0"
27+
28+
# Overwrite dataclasses _init_fn to add **kwargs in __init__
29+
dataclasses._init_fn = dataclasses_init_fn_with_kwargs
30+
31+
# Namespaces
32+
LINKML = CurieNamespace('linkml', 'https://w3id.org/linkml/')
33+
DEFAULT_ = LINKML
34+
35+
36+
# Types
37+
38+
# Class references
39+
40+
41+
42+
@dataclass
43+
class Extension(YAMLRoot):
44+
"""
45+
a tag/value pair used to add non-model information to an entry
46+
"""
47+
_inherited_slots: ClassVar[List[str]] = []
48+
49+
class_class_uri: ClassVar[URIRef] = LINKML.Extension
50+
class_class_curie: ClassVar[str] = "linkml:Extension"
51+
class_name: ClassVar[str] = "extension"
52+
class_model_uri: ClassVar[URIRef] = LINKML.Extension
53+
54+
tag: Union[str, URIorCURIE] = None
55+
value: str = None
56+
extensions: Optional[Union[Union[dict, "Extension"], List[Union[dict, "Extension"]]]] = empty_list()
57+
58+
def __post_init__(self, *_: List[str], **kwargs: Dict[str, Any]):
59+
if self.tag is None:
60+
raise ValueError("tag must be supplied")
61+
if not isinstance(self.tag, URIorCURIE):
62+
self.tag = URIorCURIE(self.tag)
63+
64+
if self.value is None:
65+
raise ValueError("value must be supplied")
66+
if not isinstance(self.value, str):
67+
self.value = str(self.value)
68+
69+
if self.extensions is None:
70+
self.extensions = []
71+
if not isinstance(self.extensions, list):
72+
self.extensions = [self.extensions]
73+
self._normalize_inlined_slot(slot_name="extensions", slot_type=Extension, key_name="tag", inlined_as_list=True, keyed=False)
74+
75+
super().__post_init__(**kwargs)
76+
77+
78+
@dataclass
79+
class Extensible(YAMLRoot):
80+
"""
81+
mixin for classes that support extension
82+
"""
83+
_inherited_slots: ClassVar[List[str]] = []
84+
85+
class_class_uri: ClassVar[URIRef] = LINKML.Extensible
86+
class_class_curie: ClassVar[str] = "linkml:Extensible"
87+
class_name: ClassVar[str] = "extensible"
88+
class_model_uri: ClassVar[URIRef] = LINKML.Extensible
89+
90+
extensions: Optional[Union[Union[dict, Extension], List[Union[dict, Extension]]]] = empty_list()
91+
92+
def __post_init__(self, *_: List[str], **kwargs: Dict[str, Any]):
93+
if self.extensions is None:
94+
self.extensions = []
95+
if not isinstance(self.extensions, list):
96+
self.extensions = [self.extensions]
97+
self._normalize_inlined_slot(slot_name="extensions", slot_type=Extension, key_name="tag", inlined_as_list=True, keyed=False)
98+
99+
super().__post_init__(**kwargs)
100+
101+
102+
# Enumerations
103+
104+
105+
# Slots
106+

linkml_model/linkml_files.py

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
import os
2+
from enum import Enum, auto
3+
from typing import Optional, Union
4+
5+
import requests
6+
from rdflib import Namespace
7+
8+
LINKML_URL_BASE = "https://w3id.org/linkml/"
9+
LINKML_NAMESPACE = Namespace(LINKML_URL_BASE)
10+
GITHUB_IO_BASE = "https://linkml.github.io/linkml-model/"
11+
GITHUB_BASE = "https://raw.githubusercontent.com/linkml/linkml-model/"
12+
LOCAL_BASE = os.path.abspath(os.path.dirname(__file__))
13+
GITHUB_API_BASE = "https://api.github.com/repos/linkml/linkml-model/"
14+
GITHUB_RELEASES = GITHUB_BASE + "releases"
15+
GITHUB_TAGS = GITHUB_BASE + "tags"
16+
17+
18+
19+
20+
class _AutoName(Enum):
21+
@staticmethod
22+
def _generate_next_value_(name, start, count, last_values):
23+
return name.lower()
24+
25+
26+
class Source(_AutoName):
27+
""" LinkML package source name """
28+
META = auto()
29+
TYPES = auto()
30+
MAPPINGS = auto()
31+
ANNOTATIONS = auto()
32+
EXTENSIONS = auto()
33+
34+
35+
class Format(Enum):
36+
""" LinkML package formats """
37+
GRAPHQL = "graphql"
38+
HTML = ""
39+
JSON = "json"
40+
JSONLD = "context.jsonld"
41+
JSON_SCHEMA = "schema.json"
42+
NATIVE_JSONLD = "model.context.jsonld"
43+
NATIVE_RDF = "model.ttl"
44+
NATIVE_SHEXC = "model.shex"
45+
NATIVE_SHEXJ = "model.shexj"
46+
OWL = "owl.ttl"
47+
PYTHON = "py"
48+
RDF = "ttl"
49+
SHEXC = "shex"
50+
SHEXJ = "shexj"
51+
YAML = "yaml"
52+
53+
54+
class _Path(Enum):
55+
""" LinkML Relative paths"""
56+
GRAPHQL = "graphql"
57+
HTML = "docs"
58+
JSON = "json"
59+
JSONLD = "jsonld"
60+
JSON_SCHEMA = "jsonschema"
61+
NATIVE_JSONLD = "jsonld"
62+
NATIVE_RDF = "ttl"
63+
NATIVE_SHEXC = "shex"
64+
NATIVE_SHEXJ = "shex"
65+
OWL = "owl"
66+
PYTHON = "linkml_model"
67+
RDF = "rdf"
68+
SHEXC = "shex"
69+
SHEXJ = "shex"
70+
YAML = "model/schema"
71+
72+
73+
class ReleaseTag(_AutoName):
74+
""" Release tags
75+
LATEST - the absolute latest in the supplied branch
76+
CURRENT - the latest _released_ version in the supplied branch """
77+
LATEST = auto()
78+
CURRENT = auto()
79+
80+
81+
def _build_path(source: Source, fmt: Format) -> str:
82+
""" Create the relative path for source and fmt """
83+
return f"{_Path[fmt.name].value}/{source.value}.{fmt.value}"
84+
85+
86+
def _build_loc(base: str, source: Source, fmt: Format) -> str:
87+
return f"{base}{_build_path(source, fmt)}"
88+
89+
90+
def URL_FOR(source: Source, fmt: Format) -> str:
91+
""" Return the URL to retrieve source in format """
92+
return f"{LINKML_URL_BASE}{source.value}.{fmt.value}"
93+
94+
95+
def LOCAL_PATH_FOR(source: Source, fmt: Format) -> str:
96+
return os.path.join(LOCAL_BASE, _build_path(source, fmt))
97+
98+
99+
def GITHUB_IO_PATH_FOR(source: Source, fmt: Format) -> str:
100+
return _build_loc(GITHUB_IO_BASE, source, fmt)
101+
102+
103+
def GITHUB_PATH_FOR(source: Source,
104+
fmt: Format,
105+
release: Optional[Union[ReleaseTag, str]] = ReleaseTag.CURRENT,
106+
branch: Optional[str] = "main") -> str:
107+
def do_request(url) -> object:
108+
resp = requests.get(url)
109+
if resp.ok:
110+
return resp.json()
111+
raise requests.HTTPError(f"{resp.status_code} - {resp.reason}: {url}")
112+
113+
def tag_to_commit(tag: str) -> str:
114+
tags = do_request(f"{GITHUB_API_BASE}tags")
115+
for tagent in tags:
116+
if tagent['name'] == tag:
117+
return _build_loc(f"{GITHUB_BASE}blob/{tagent['commit']['sha']}/", source, fmt)
118+
raise ValueError(f"Tag: {tag} not found!")
119+
120+
if release is not ReleaseTag.CURRENT and branch != "main":
121+
raise ValueError("Cannot specify both a release and a branch")
122+
123+
# Return the absolute latest entry for branch
124+
if release is ReleaseTag.LATEST or (release is ReleaseTag.CURRENT and branch != "main"):
125+
return f"{GITHUB_BASE}{branch}/{_build_path(source, fmt)}"
126+
127+
# Return the latest published version
128+
elif release is ReleaseTag.CURRENT:
129+
release = do_request(f"{GITHUB_API_BASE}releases/latest")
130+
return tag_to_commit(release['tag_name'])
131+
132+
# Return a specific tag
133+
else:
134+
return tag_to_commit(release)
135+
136+

0 commit comments

Comments
 (0)