Skip to content

Commit

Permalink
Merge pull request #530 from MetaCell/upgrade-python-3.11
Browse files Browse the repository at this point in the history
Upgrade dependencies and code for pygeppetto to deal with Python 3.11
  • Loading branch information
enicolasgomez authored Mar 19, 2024
2 parents 276a5e7 + 7caa23f commit 024387a
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 30 deletions.
3 changes: 2 additions & 1 deletion pygeppetto/pygeppetto/model/geppetto_resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ class GeppettoResource(JsonResource):
variables.eClassifiers]
chain = ChainMap(*packages)

def serialize_eclass(self, eclass):
@staticmethod
def serialize_eclass(eclass):
return eclass.name

@lru_cache()
Expand Down
8 changes: 6 additions & 2 deletions pygeppetto/pygeppetto/model/model_serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ def serialize(geppetto_model, onlySerialiseDelta=False):
# we now create a resource to save the geppetto model and serialize it to a JSON string
rset = ResourceSet()
uri = BytesURI('geppetto_model.json')
rset.resource_factory['*'] = lambda uri: GeppettoResource(uri, indent=2)
JsonGeppettoResource = lambda uri: GeppettoResource(uri, indent=2)
rset.resource_factory['json'] = JsonGeppettoResource
rset.resource_factory['*'] = JsonGeppettoResource
resource = rset.create_resource(uri)
resource.append(geppetto_model)
if onlySerialiseDelta:
Expand All @@ -61,5 +63,7 @@ def serialize(geppetto_model, onlySerialiseDelta=False):
def load(json):
rset = ResourceSet()
uri = BytesURI('geppetto_model.json')
rset.resource_factory['*'] = lambda uri: GeppettoResource(uri, indent=2)
JsonGeppettoResource = lambda uri: GeppettoResource(uri, indent=2)
rset.resource_factory['json'] = JsonGeppettoResource
rset.resource_factory['*'] = JsonGeppettoResource
resource = rset.create_resource(uri)
30 changes: 15 additions & 15 deletions pygeppetto/pygeppetto/model/utils/pointer_utility.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
https://github.com/openworm/org.geppetto.model/blob/master/src/main/java/org/geppetto/model/util/java"""
import sys

from multimethod import multidispatch
from multimethod import multimethod

from ..exceptions import GeppettoModelException
from ..model import GeppettoLibrary, GeppettoModel
Expand All @@ -14,8 +14,8 @@
PointerUtility = sys.modules[__name__]


@multidispatch
def get_pointer(variable: Variable, type_, index):
@multimethod
def get_pointer(variable: Variable, type_: Type, index: int):
pointerElement = PointerElement()
pointerElement.index = index
pointerElement.variable = variable
Expand All @@ -25,8 +25,8 @@ def get_pointer(variable: Variable, type_, index):
return pointer


@get_pointer.register(GeppettoModel, str)
def get_pointer_model(model: GeppettoModel, instance_path):
@get_pointer.register
def get_pointer_model(model: GeppettoModel, instance_path: str):
pointer = Pointer(path=instance_path)

st = iter(instance_path.split("."))
Expand Down Expand Up @@ -68,7 +68,7 @@ def get_pointer_model(model: GeppettoModel, instance_path):
return pointer


@multidispatch
@multimethod
def get_type(model, path):
st = iter(path.split('.'))
lastType = None
Expand Down Expand Up @@ -100,15 +100,15 @@ def get_type(model, path):
raise GeppettoModelException("Couldn't find a type for the path " + path)


@get_type.register(str)
@get_type.register
def get_type_str(token: str):
if "(" in token:
return token[token.find("(") + 1: token.find(")")]
else:
return None


@get_type.register(Pointer)
@get_type.register
def get_type_pointer(pointer: Pointer):
return pointer.elements[-1].type

Expand Down Expand Up @@ -169,7 +169,7 @@ def find_library(model, libraryId):
# * @param pointer2
# * @return true if the two pointers point to the same variables and types
#
@multidispatch
@multimethod
def equals(pointer: Pointer, pointer2: Pointer):
if not pointer == pointer2:
if len(pointer.elements) != len(pointer2.elements):
Expand All @@ -190,7 +190,7 @@ def equals(pointer: Pointer, pointer2: Pointer):
# * @param pointer2
# * @return
#
@equals.register(PointerElement, PointerElement)
@equals.register
def equals_pointer(pointer: PointerElement, pointer2: PointerElement):
sameType = pointer.type == pointer2.type or pointer.type == pointer2.type
sameVar = pointer.variable == pointer2.variable or pointer.variable == pointer2.variable
Expand All @@ -202,12 +202,12 @@ def equals_pointer(pointer: PointerElement, pointer2: PointerElement):
# * @param pointer
# * @return
#
@multidispatch
@multimethod
def get_variable(pointer: Pointer):
return pointer.elements[-1].variable


@get_variable.register(str)
@get_variable.register
def get_variable_str(token: str) -> str:
if "(" in token:
return token[0: token.find("(")]
Expand All @@ -233,7 +233,7 @@ def get_instance_path(variable, type_):
return variable.id + "(" + type_.id + ")"


@multidispatch
@multimethod
def find_type(type_, variable: Variable) -> Type:
if type_ is None:
types = []
Expand All @@ -257,8 +257,8 @@ def find_type(type_, variable: Variable) -> Type:
raise GeppettoModelException("The type {} was not found in the variable {}".format(type_, variable.id))


@find_type.register(str, GeppettoLibrary)
def find_type_library(typeId, library: GeppettoLibrary):
@find_type.register
def find_type_library(typeId: str, library: GeppettoLibrary):
return next((type_ for type_ in library.types if type_.id == typeId), None)


Expand Down
14 changes: 7 additions & 7 deletions pygeppetto/pygeppetto/model/utils/url_reader.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
""" generated source for class URLReader """
SERVER_ROOT_TOKEN = "SERVER_ROOT"
from multimethod import multidispatch
from multimethod import multimethod


#
#
# * @param urlString
# * @param baseURL
# * @return
#
@multidispatch
def getURL(urlString, baseURL):
@multimethod
def getURL(urlString: str, baseURL: str | None):
""" generated source for method getURL """
url = urlString

Expand All @@ -22,12 +22,12 @@ def getURL(urlString, baseURL):
return getURL(url)


#
#
# * @param urlString
# * @return
#
@getURL.register(object, str)
def getURL_0(urlString):
@getURL.register
def getURL_0(urlString: str, baseURL: str | None=None):
""" generated source for method getURL_0 """
url = None
if urlString.startsWith("https://") or urlString.startsWith("http://"):
Expand Down
10 changes: 5 additions & 5 deletions pygeppetto/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
airspeed==0.5.16
Deprecated==1.2.10
multimethod==1.1
pyecore==0.11.6
requests==2.23.0
airspeed==0.6.0
Deprecated==1.2.14
multimethod==1.11.2
pyecore==0.15.1
requests==2.31.0

0 comments on commit 024387a

Please sign in to comment.