Skip to content
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

Add python 3.13, Remove python 3.8 #345

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
8 changes: 5 additions & 3 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest]
python-version: ["3.8", "3.9", "3.10", "3.12"]
python-version: ["3.9", "3.10", "3.12", "3.13"]
exclude:
- os: windows-latest
python-version: "3.8"
python-version: "3.10"
- os: windows-latest
python-version: "3.12"

runs-on: ${{ matrix.os }}

Expand All @@ -34,7 +36,7 @@ jobs:
uses: actions/checkout@v3

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
cache: 'poetry'
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pypi-publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
- name: Set up Python
uses: actions/[email protected]
with:
python-version: 3.8
python-version: 3.12

- name: Install Poetry
run: pipx install poetry
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/test-upstream.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ jobs:
strategy:
matrix:
os: [ ubuntu-latest, windows-latest ]
python-version: [ "3.8", "3.9", "3.10", "3.11", "3.12" ]
python-version: [ "3.9", "3.10", "3.11", "3.12", "3.13" ]
exclude:
- os: windows-latest
python-version: "3.9"
- os: windows-latest
python-version: "3.10"
- os: windows-latest
python-version: "3.11"
- os: windows-latest
python-version: "3.12"
runs-on: ${{ matrix.os }}
env:
POETRY_VIRTUALENVS_IN_PROJECT: true
Expand Down
4 changes: 4 additions & 0 deletions linkml_runtime/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
from linkml_runtime.utils.schemaview import SchemaView
from rdflib import RDF, RDFS, SKOS, XSD, OWL

__all__ = [
"SchemaView",
]

# use importlib.metadata to read the version provided
# by the package during installation. Do not hardcode
# the version in the code
Expand Down
1 change: 0 additions & 1 deletion linkml_runtime/dumpers/delimited_file_dumper.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import io
import yaml
import json
from abc import ABC, abstractmethod
from typing import Union
Expand Down
10 changes: 5 additions & 5 deletions linkml_runtime/dumpers/json_dumper.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import json
from decimal import Decimal
from typing import Dict, Union
from typing import Union
from pydantic import BaseModel

from deprecated.classic import deprecated
Expand Down Expand Up @@ -30,7 +30,7 @@ def dump(self, element: Union[BaseModel, YAMLRoot], to_file: str, contexts: CONT
* A list containing elements of any type named above
"""
if isinstance(element, BaseModel):
element = element.dict()
element = element.model_dump()
super().dump(element, to_file, contexts=contexts, **kwargs)

def dumps(self, element: Union[BaseModel, YAMLRoot], contexts: CONTEXTS_PARAM_TYPE = None, inject_type=True) -> str:
Expand All @@ -50,7 +50,7 @@ def dumps(self, element: Union[BaseModel, YAMLRoot], contexts: CONTEXTS_PARAM_TY

def default(o):
if isinstance(o, BaseModel):
return remove_empty_items(o.dict(), hide_protected_keys=True)
return remove_empty_items(o.model_dump(), hide_protected_keys=True)
if isinstance(o, YAMLRoot):
return remove_empty_items(o, hide_protected_keys=True)
elif isinstance(o, Decimal):
Expand All @@ -59,15 +59,15 @@ def default(o):
else:
return json.JSONDecoder().decode(o)
if isinstance(element, BaseModel):
element = element.dict()
element = element.model_dump()
return json.dumps(as_json_object(element, contexts, inject_type=inject_type),
default=default,
ensure_ascii=False,
indent=' ')

@staticmethod
@deprecated("Use `utils/formatutils/remove_empty_items` instead")
def remove_empty_items(obj: Dict) -> Dict:
def remove_empty_items(obj: dict) -> dict:
"""
Remove empty items from obj
:param obj:
Expand Down
4 changes: 2 additions & 2 deletions linkml_runtime/dumpers/rdf_dumper.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def dump(self, element: Union[BaseModel, YAMLRoot], to_file: str, contexts: CONT
:param fmt: RDF format
"""
if isinstance(element, BaseModel):
element = element.dict()
element = element.model_dump()
super().dump(element, to_file, contexts=contexts, fmt=fmt)

def dumps(self, element: Union[BaseModel, YAMLRoot], contexts: CONTEXTS_PARAM_TYPE = None, fmt: Optional[str] = 'turtle') -> str:
Expand All @@ -91,6 +91,6 @@ def dumps(self, element: Union[BaseModel, YAMLRoot], contexts: CONTEXTS_PARAM_TY
:return: rdflib Graph containing element
"""
if isinstance(element, BaseModel):
element = element.dict()
element = element.model_dump()
return self.as_rdf_graph(remove_empty_items(element, hide_protected_keys=True), contexts).\
serialize(format=fmt)
9 changes: 4 additions & 5 deletions linkml_runtime/dumpers/rdflib_dumper.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import logging
import urllib
from abc import abstractmethod
from typing import Optional, Any, Dict, Union
from typing import Optional, Any, Union
from pydantic import BaseModel

from curies import Converter
Expand Down Expand Up @@ -31,7 +30,7 @@ def as_rdf_graph(
self,
element: Union[BaseModel, YAMLRoot],
schemaview: SchemaView,
prefix_map: Union[Dict[str, str], Converter, None] = None,
prefix_map: Union[dict[str, str], Converter, None] = None,
) -> Graph:
"""
Dumps from element to an rdflib Graph,
Expand Down Expand Up @@ -154,7 +153,7 @@ def dump(
to_file: str,
schemaview: SchemaView = None,
fmt: str = 'turtle',
prefix_map: Union[Dict[str, str], Converter, None] = None,
prefix_map: Union[dict[str, str], Converter, None] = None,
**args,
) -> None:
"""
Expand All @@ -174,7 +173,7 @@ def dumps(
element: Union[BaseModel, YAMLRoot],
schemaview: SchemaView = None,
fmt: Optional[str] = 'turtle',
prefix_map: Union[Dict[str, str], Converter, None] = None,
prefix_map: Union[dict[str, str], Converter, None] = None,
) -> str:
"""
Convert element into an RDF graph guided by the schema
Expand Down
11 changes: 6 additions & 5 deletions linkml_runtime/index/object_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"""
import logging
import inspect
from typing import Mapping, Any, Optional, Tuple, List, Iterator, Union
from typing import Any, Union
from collections.abc import Mapping, Iterator

from linkml_runtime import SchemaView
from linkml_runtime.utils import eval_utils
Expand Down Expand Up @@ -54,8 +55,8 @@ def __init__(self, obj: YAMLRoot, schemaview: SchemaView):
self._schemaview = schemaview
self._class_map = schemaview.class_name_mappings()
self._source_object_cache: Mapping[str, Any] = {}
self._proxy_object_cache: Mapping[str, "ProxyObject"] = {}
self._child_to_parent: Mapping[str, List[Tuple[str, str]]] = {}
self._proxy_object_cache: Mapping[str, ProxyObject] = {}
self._child_to_parent: Mapping[str, list[tuple[str, str]]] = {}
self._index(obj)

def _index(self, obj: Any, parent_key=None, parent=None):
Expand Down Expand Up @@ -112,7 +113,7 @@ def bless(self, obj: Any) -> "ProxyObject":
else:
return ProxyObject(obj, _db=self)

def _key(self, obj: Any) -> Tuple[Union[str, YAMLRoot], str]:
def _key(self, obj: Any) -> tuple[Union[str, YAMLRoot], str]:
"""
Returns primary key value for this object.

Expand Down Expand Up @@ -265,6 +266,6 @@ def _map(self, obj: Any, in_range: str) -> Any:
return cls(obj)
return obj

def _attributes(self) -> List[str]:
def _attributes(self) -> list[str]:
return list(vars(self._shadowed).keys())

46 changes: 46 additions & 0 deletions linkml_runtime/linkml_model/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,49 @@
Definition, EnumDefinition, SlotDefinition, ClassDefinition, Prefix, LocalName, Example, AltDescription, \
PermissibleValue, PvFormulaOptions

__all__ = [
"String",
"Integer",
"Boolean",
"Float",
"Double",
"Decimal",
"Time",
"Date",
"Datetime",
"Uriorcurie",
"Uri",
"Ncname",
"Objectidentifier",
"Nodeidentifier",
"Extension",
"Extensible",
"Annotation",
"Annotatable",
"ElementName",
"SchemaDefinitionName",
"TypeDefinitionName",
"SubsetDefinitionName",
"DefinitionName",
"EnumDefinitionName",
"SlotDefinitionName",
"ClassDefinitionName",
"PrefixPrefixPrefix",
"LocalNameLocalNameSource",
"AltDescriptionSource",
"PermissibleValueText",
"Element",
"SchemaDefinition",
"TypeDefinition",
"SubsetDefinition",
"Definition",
"EnumDefinition",
"SlotDefinition",
"ClassDefinition",
"Prefix",
"LocalName",
"Example",
"AltDescription",
"PermissibleValue",
"PvFormulaOptions",
]
32 changes: 11 additions & 21 deletions linkml_runtime/linkml_model/annotations.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,19 @@
# license: https://creativecommons.org/publicdomain/zero/1.0/

import dataclasses
import re
from jsonasobj2 import JsonObj, as_dict
from typing import Optional, List, Union, Dict, ClassVar, Any
from typing import Optional, Union, ClassVar, Any
from dataclasses import dataclass

from linkml_runtime.utils.slot import Slot
from linkml_runtime.utils.metamodelcore import empty_list, empty_dict, bnode
from linkml_runtime.utils.yamlutils import YAMLRoot, extended_str, extended_float, extended_int
from linkml_runtime.utils.dataclass_extensions_376 import dataclasses_init_fn_with_kwargs
from linkml_runtime.utils.formatutils import camelcase, underscore, sfx
from linkml_runtime.utils.enumerations import EnumDefinitionImpl
from rdflib import Namespace, URIRef
from linkml_runtime.utils.metamodelcore import empty_dict
from linkml_runtime.utils.yamlutils import YAMLRoot
from rdflib import URIRef
from linkml_runtime.utils.curienamespace import CurieNamespace
from .extensions import AnyValue, Extension, ExtensionTag
from .types import Uriorcurie
from linkml_runtime.utils.metamodelcore import URIorCURIE

metamodel_version = "1.7.0"
version = "2.0.0"

# Overwrite dataclasses _init_fn to add **kwargs in __init__
dataclasses._init_fn = dataclasses_init_fn_with_kwargs

# Namespaces
LINKML = CurieNamespace('linkml', 'https://w3id.org/linkml/')
DEFAULT_ = LINKML
Expand All @@ -47,16 +37,16 @@ class Annotatable(YAMLRoot):
"""
mixin for classes that support annotations
"""
_inherited_slots: ClassVar[List[str]] = []
_inherited_slots: ClassVar[list[str]] = []

class_class_uri: ClassVar[URIRef] = LINKML["Annotatable"]
class_class_curie: ClassVar[str] = "linkml:Annotatable"
class_name: ClassVar[str] = "annotatable"
class_model_uri: ClassVar[URIRef] = LINKML.Annotatable

annotations: Optional[Union[Dict[Union[str, AnnotationTag], Union[dict, "Annotation"]], List[Union[dict, "Annotation"]]]] = empty_dict()
annotations: Optional[Union[dict[Union[str, AnnotationTag], Union[dict, "Annotation"]], list[Union[dict, "Annotation"]]]] = empty_dict()

def __post_init__(self, *_: List[str], **kwargs: Dict[str, Any]):
def __post_init__(self, *_: list[str], **kwargs: dict[str, Any]):
self._normalize_inlined_as_dict(slot_name="annotations", slot_type=Annotation, key_name="tag", keyed=True)

super().__post_init__(**kwargs)
Expand All @@ -67,7 +57,7 @@ class Annotation(Extension):
"""
a tag/value pair with the semantics of OWL Annotation
"""
_inherited_slots: ClassVar[List[str]] = []
_inherited_slots: ClassVar[list[str]] = []

class_class_uri: ClassVar[URIRef] = LINKML["Annotation"]
class_class_curie: ClassVar[str] = "linkml:Annotation"
Expand All @@ -76,9 +66,9 @@ class Annotation(Extension):

tag: Union[str, AnnotationTag] = None
value: Union[dict, AnyValue] = None
annotations: Optional[Union[Dict[Union[str, AnnotationTag], Union[dict, "Annotation"]], List[Union[dict, "Annotation"]]]] = empty_dict()
annotations: Optional[Union[dict[Union[str, AnnotationTag], Union[dict, "Annotation"]], list[Union[dict, "Annotation"]]]] = empty_dict()

def __post_init__(self, *_: List[str], **kwargs: Dict[str, Any]):
def __post_init__(self, *_: list[str], **kwargs: dict[str, Any]):
if self._is_empty(self.tag):
self.MissingRequiredField("tag")
if not isinstance(self.tag, AnnotationTag):
Expand All @@ -97,4 +87,4 @@ class slots:
pass

slots.annotations = Slot(uri=LINKML.annotations, name="annotations", curie=LINKML.curie('annotations'),
model_uri=LINKML.annotations, domain=None, range=Optional[Union[Dict[Union[str, AnnotationTag], Union[dict, "Annotation"]], List[Union[dict, "Annotation"]]]])
model_uri=LINKML.annotations, domain=None, range=Optional[Union[dict[Union[str, AnnotationTag], Union[dict, "Annotation"]], list[Union[dict, "Annotation"]]]])
Loading
Loading