mirror of
https://github.com/invoke-ai/InvokeAI
synced 2024-08-30 20:32:17 +00:00
make ModelLocalSource comparisons work across platforms
This commit is contained in:
parent
620b2d477a
commit
018ccebd6f
@ -31,18 +31,34 @@ class UnknownInstallJobException(Exception):
|
|||||||
|
|
||||||
|
|
||||||
class StringLikeSource(BaseModel):
|
class StringLikeSource(BaseModel):
|
||||||
"""Base class for model sources, implements functions that lets the source be sorted and indexed."""
|
"""
|
||||||
|
Base class for model sources, implements functions that lets the source be sorted and indexed.
|
||||||
|
|
||||||
|
These shenanigans let this stuff work:
|
||||||
|
|
||||||
|
source1 = LocalModelSource(path='C:/users/mort/foo.safetensors')
|
||||||
|
mydict = {source1: 'model 1'}
|
||||||
|
assert mydict['C:/users/mort/foo.safetensors'] == 'model 1'
|
||||||
|
assert mydict[LocalModelSource(path='C:/users/mort/foo.safetensors')] == 'model 1'
|
||||||
|
|
||||||
|
source2 = LocalModelSource(path=Path('C:/users/mort/foo.safetensors'))
|
||||||
|
assert source1 == source2
|
||||||
|
assert source1 == 'C:/users/mort/foo.safetensors'
|
||||||
|
"""
|
||||||
|
|
||||||
def __hash__(self) -> int:
|
def __hash__(self) -> int:
|
||||||
"""Return hash of the path field, for indexing."""
|
"""Return hash of the path field, for indexing."""
|
||||||
return hash(str(self))
|
return hash(str(self))
|
||||||
|
|
||||||
def __lt__(self, other: Any) -> int:
|
def __lt__(self, other: object) -> int:
|
||||||
"""Return comparison of the stringified version, for sorting."""
|
"""Return comparison of the stringified version, for sorting."""
|
||||||
return str(self) < str(other)
|
return str(self) < str(other)
|
||||||
|
|
||||||
def __eq__(self, other: Any) -> bool:
|
def __eq__(self, other: object) -> bool:
|
||||||
"""Return equality on the stringified version."""
|
"""Return equality on the stringified version."""
|
||||||
|
if isinstance(other, Path):
|
||||||
|
return str(self) == other.as_posix()
|
||||||
|
else:
|
||||||
return str(self) == str(other)
|
return str(self) == str(other)
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user