mirror of
https://github.com/alicevision/Meshroom.git
synced 2025-04-29 02:08:08 +02:00
[core] add Version class to help manipulate version names
This commit is contained in:
parent
20be401110
commit
e0ad807d84
2 changed files with 95 additions and 2 deletions
|
@ -84,6 +84,99 @@ def loadPlugins(folder, packageName, classType):
|
|||
return pluginTypes
|
||||
|
||||
|
||||
class Version(object):
|
||||
"""
|
||||
Version provides convenient properties and methods to manipulate and compare version names.
|
||||
"""
|
||||
def __init__(self, versionName):
|
||||
"""
|
||||
Args:
|
||||
versionName (str): the name of the version as a string
|
||||
"""
|
||||
self.name = versionName
|
||||
self.components = Version.toComponents(self.name)
|
||||
|
||||
def __repr__(self):
|
||||
return self.name
|
||||
|
||||
def __neg__(self):
|
||||
return not self.name
|
||||
|
||||
def __len__(self):
|
||||
return len(self.components)
|
||||
|
||||
def __eq__(self, other):
|
||||
"""
|
||||
Test equality between 'self' with 'other'.
|
||||
|
||||
Args:
|
||||
other (Version): the version to compare to
|
||||
|
||||
Returns:
|
||||
bool: whether the versions are equal
|
||||
"""
|
||||
return self.name == other.name
|
||||
|
||||
def __lt__(self, other):
|
||||
"""
|
||||
Test 'self' inferiority to 'other'.
|
||||
|
||||
Args:
|
||||
other (Version): the version to compare to
|
||||
|
||||
Returns:
|
||||
bool: whether self is inferior to other
|
||||
"""
|
||||
# sequence comparison works natively for this use-case
|
||||
return self.name < other.name
|
||||
|
||||
def __le__(self, other):
|
||||
"""
|
||||
Test 'self' inferiority or equality to 'other'.
|
||||
|
||||
Args:
|
||||
other (Version): the version to compare to
|
||||
|
||||
Returns:
|
||||
bool: whether self is inferior or equal to other
|
||||
"""
|
||||
return self.name <= other.name
|
||||
|
||||
@staticmethod
|
||||
def toComponents(versionName):
|
||||
"""
|
||||
Split 'versionName' as a tuple of individual components.
|
||||
|
||||
Args:
|
||||
versionName (str): version name
|
||||
|
||||
Returns:
|
||||
tuple of str: split version numbers
|
||||
"""
|
||||
if not versionName:
|
||||
return ()
|
||||
return tuple(versionName.split("."))
|
||||
|
||||
@property
|
||||
def major(self):
|
||||
""" Version major number. """
|
||||
return self.components[0]
|
||||
|
||||
@property
|
||||
def minor(self):
|
||||
""" Version minor number. """
|
||||
if len(self) < 2:
|
||||
return ""
|
||||
return self.components[1]
|
||||
|
||||
@property
|
||||
def micro(self):
|
||||
""" Version micro number. """
|
||||
if len(self) < 3:
|
||||
return ""
|
||||
return self.components[2]
|
||||
|
||||
|
||||
def moduleVersion(moduleName, default=None):
|
||||
""" Return the version of a module indicated with '__version__' keyword.
|
||||
|
||||
|
|
|
@ -15,7 +15,7 @@ from enum import Enum
|
|||
|
||||
import meshroom
|
||||
from meshroom.common import Signal, Variant, Property, BaseObject, Slot, ListModel, DictModel
|
||||
from meshroom.core import desc, stats, hashValue, pyCompatibility, nodeVersion
|
||||
from meshroom.core import desc, stats, hashValue, pyCompatibility, nodeVersion, Version
|
||||
from meshroom.core.attribute import attribute_factory, ListAttribute, GroupAttribute, Attribute
|
||||
from meshroom.core.exception import NodeUpgradeError, UnknownNodeTypeError
|
||||
|
||||
|
@ -897,7 +897,7 @@ def node_factory(nodeDict, name=None):
|
|||
# compare serialized node version with current node version
|
||||
currentNodeVersion = meshroom.core.nodeVersion(nodeDesc)
|
||||
# if both versions are available, check for incompatibility in major version
|
||||
if version and currentNodeVersion and version.split('.')[0] != currentNodeVersion.split('.')[0]:
|
||||
if version and currentNodeVersion and Version(version).major != Version(currentNodeVersion).major:
|
||||
compatibilityIssue = CompatibilityIssue.VersionConflict
|
||||
# in other cases, check attributes compatibility between serialized node and its description
|
||||
else:
|
||||
|
|
Loading…
Add table
Reference in a new issue