@@ -24,7 +24,8 @@ def _generate_next_value_(name, start, count, last_values):
2424
2525
2626class Source (_AutoName ):
27- """ LinkML package source name """
27+ """LinkML package source name"""
28+
2829 META = auto ()
2930 TYPES = auto ()
3031 MAPPINGS = auto ()
@@ -33,7 +34,8 @@ class Source(_AutoName):
3334
3435
3536class Format (_AutoName ):
36- """ LinkML package formats """
37+ """LinkML package formats"""
38+
3739 EXCEL = auto ()
3840 GRAPHQL = auto ()
3941 JSON = auto ()
@@ -55,48 +57,51 @@ class Format(_AutoName):
5557 SQLSCHEMA = auto ()
5658 YAML = auto ()
5759
60+
5861@dataclass
5962class FormatPath :
6063 path : str
6164 extension : str
6265
63- def model_path (self , model :str ) -> Path :
66+ def model_path (self , model : str ) -> Path :
6467 return (Path (self .path ) / model ).with_suffix (self .extension )
6568
69+
6670class _Path :
67- """ LinkML Relative paths"""
68- EXCEL = FormatPath ("excel" ,"xlsx" )
69- GRAPHQL = FormatPath ("graphql" ,"graphql" )
70- JSON = FormatPath ("json" ,"json" )
71- JSONLD = FormatPath ("jsonld" ,"context.jsonld" )
72- JSON_SCHEMA = FormatPath ("jsonschema" , "schema.json" )
73- NATIVE_JSONLD = FormatPath ("jsonld" , "context.jsonld" )
74- NATIVE_RDF = FormatPath ("rdf" ,"ttl" )
75- NATIVE_SHEXC = FormatPath ("shex" ,"shex" )
76- NATIVE_SHEXJ = FormatPath ("shex" ,"shexj" )
77- OWL = FormatPath ("owl" ,"owl.ttl" )
78- PREFIXMAP = FormatPath ('prefixmap' ,'yaml' )
79- PROTOBUF = FormatPath ("protobuf" ,"proto" )
80- PYTHON = FormatPath ("" ,"py" )
81- RDF = FormatPath ("rdf" ,"ttl" )
82- SHACL = FormatPath ("shacl" ,"shacl.ttl" )
83- SHEXC = FormatPath ("shex" ,"shex" )
84- SHEXJ = FormatPath ("shex" ,"shexj" )
85- SQLDDL = FormatPath ("sqlddl" ,"sql" )
86- SQLSCHEMA = FormatPath ("sqlschema" ,"sql" )
87- YAML = FormatPath ((Path ("model" ) / "schema" ).as_posix (),"yaml" )
71+ """LinkML Relative paths"""
72+
73+ EXCEL = FormatPath ("excel" , "xlsx" )
74+ GRAPHQL = FormatPath ("graphql" , "graphql" )
75+ JSON = FormatPath ("json" , "json" )
76+ JSONLD = FormatPath ("jsonld" , "context.jsonld" )
77+ JSON_SCHEMA = FormatPath ("jsonschema" , "schema.json" )
78+ NATIVE_JSONLD = FormatPath ("jsonld" , "context.jsonld" )
79+ NATIVE_RDF = FormatPath ("rdf" , "ttl" )
80+ NATIVE_SHEXC = FormatPath ("shex" , "shex" )
81+ NATIVE_SHEXJ = FormatPath ("shex" , "shexj" )
82+ OWL = FormatPath ("owl" , "owl.ttl" )
83+ PREFIXMAP = FormatPath ("prefixmap" , "yaml" )
84+ PROTOBUF = FormatPath ("protobuf" , "proto" )
85+ PYTHON = FormatPath ("" , "py" )
86+ RDF = FormatPath ("rdf" , "ttl" )
87+ SHACL = FormatPath ("shacl" , "shacl.ttl" )
88+ SHEXC = FormatPath ("shex" , "shex" )
89+ SHEXJ = FormatPath ("shex" , "shexj" )
90+ SQLDDL = FormatPath ("sqlddl" , "sql" )
91+ SQLSCHEMA = FormatPath ("sqlschema" , "sql" )
92+ YAML = FormatPath ((Path ("model" ) / "schema" ).as_posix (), "yaml" )
8893
8994 @classmethod
9095 def items (cls ) -> dict [str , FormatPath ]:
91- return {k :v for k ,v in cls .__dict__ .items () if not k .startswith ('_' )}
96+ return {k : v for k , v in cls .__dict__ .items () if not k .startswith ("_" )}
9297
9398 @classmethod
94- def get (cls , item :Union [str ,Format ]) -> FormatPath :
99+ def get (cls , item : Union [str , Format ]) -> FormatPath :
95100 if isinstance (item , Format ):
96101 item = item .name .upper ()
97102 return getattr (cls , item )
98103
99- def __class_getitem__ (cls , item :str ) -> FormatPath :
104+ def __class_getitem__ (cls , item : str ) -> FormatPath :
100105 return getattr (cls , item )
101106
102107
@@ -108,14 +113,15 @@ def __class_getitem__(cls, item:str) -> FormatPath:
108113 Format .PROTOBUF ,
109114 Format .SHACL ,
110115 Format .SQLDDL ,
111- Format .SQLSCHEMA
116+ Format .SQLSCHEMA ,
112117)
113118
114119
115120class ReleaseTag (_AutoName ):
116- """ Release tags
121+ """Release tags
117122 LATEST - the absolute latest in the supplied branch
118- CURRENT - the latest _released_ version in the supplied branch """
123+ CURRENT - the latest _released_ version in the supplied branch"""
124+
119125 LATEST = auto ()
120126 CURRENT = auto ()
121127
@@ -137,12 +143,12 @@ def _build_path(source: Source, fmt: Format) -> PathParts:
137143def _build_loc (base : str , source : Source , fmt : Format ) -> str :
138144 """A github location"""
139145 # urls are always forward slash separated, so hardcoding is appropriate here
140- path = '/' .join (_build_path (source , fmt ))
141- return urljoin (base , path ).replace (' blob/' , '' )
146+ path = "/" .join (_build_path (source , fmt ))
147+ return urljoin (base , path ).replace (" blob/" , "" )
142148
143149
144150def URL_FOR (source : Source , fmt : Format ) -> str :
145- """ Return the URL to retrieve source in format """
151+ """Return the URL to retrieve source in format"""
146152 fmt_path : FormatPath = _Path .get (fmt .name )
147153 return f"{ LINKML_URL_BASE } { source .value } .{ fmt_path .extension } "
148154
@@ -152,14 +158,16 @@ def LOCAL_PATH_FOR(source: Source, fmt: Format) -> str:
152158
153159
154160def GITHUB_IO_PATH_FOR (source : Source , fmt : Format , version = "latest" ) -> str :
155- path = '/' .join ([version , ' linkml_model' , * _build_path (source , fmt )])
161+ path = "/" .join ([version , " linkml_model" , * _build_path (source , fmt )])
156162 return urljoin (GITHUB_IO_BASE , path )
157163
158164
159- def GITHUB_PATH_FOR (source : Source ,
160- fmt : Format ,
161- release : Optional [Union [ReleaseTag , str ]] = ReleaseTag .CURRENT ,
162- branch : Optional [str ] = "main" ) -> str :
165+ def GITHUB_PATH_FOR (
166+ source : Source ,
167+ fmt : Format ,
168+ release : Optional [Union [ReleaseTag , str ]] = ReleaseTag .CURRENT ,
169+ branch : Optional [str ] = "main" ,
170+ ) -> str :
163171 def do_request (url ) -> object :
164172 resp = requests .get (url )
165173 if resp .ok :
@@ -169,7 +177,7 @@ def do_request(url) -> object:
169177 def tag_to_commit (tag : str ) -> str :
170178 tags = do_request (f"{ GITHUB_API_BASE } tags?per_page=100" )
171179 for tagent in tags :
172- if tagent [' name' ] == tag :
180+ if tagent [" name" ] == tag :
173181 return _build_loc (f"{ GITHUB_BASE } blob/{ tagent ['commit' ]['sha' ]} /" , source , fmt )
174182 raise ValueError (f"Tag: { tag } not found!" )
175183
@@ -178,13 +186,13 @@ def tag_to_commit(tag: str) -> str:
178186
179187 # Return the absolute latest entry for branch
180188 if release is ReleaseTag .LATEST or (release is ReleaseTag .CURRENT and branch != "main" ):
181- path = '/' .join ([branch , ' linkml_model' , * _build_path (source , fmt )])
189+ path = "/" .join ([branch , " linkml_model" , * _build_path (source , fmt )])
182190 return urljoin (GITHUB_BASE , path )
183191
184192 # Return the latest published version
185193 elif release is ReleaseTag .CURRENT :
186194 release = do_request (f"{ GITHUB_API_BASE } releases/latest" )
187- return tag_to_commit (release [' tag_name' ])
195+ return tag_to_commit (release [" tag_name" ])
188196
189197 # Return a specific tag
190198 else :
@@ -212,7 +220,9 @@ def url(self) -> str:
212220 def file (self ) -> str :
213221 return LOCAL_PATH_FOR (self ._model , self ._format )
214222
215- def github_loc (self , tag : Optional [str ] = None , branch : Optional [str ] = None , release : ReleaseTag = None ) -> str :
223+ def github_loc (
224+ self , tag : Optional [str ] = None , branch : Optional [str ] = None , release : ReleaseTag = None
225+ ) -> str :
216226 if not tag and not branch and not release :
217227 return GITHUB_IO_PATH_FOR (self ._model , self ._format )
218228 if tag :
0 commit comments