MCPcopy Create free account
hub / github.com/Project-MONAI/MONAI / parse_version_strs

Function parse_version_strs

monai/utils/module.py:512–535  ·  view source on GitHub ↗

Parse the version strings.

(lhs: str, rhs: str)

Source from the content-addressed store, hash-verified

510
511
512def parse_version_strs(lhs: str, rhs: str) -> tuple[Iterable[int | str], Iterable[int | str]]:
513 """
514 Parse the version strings.
515 """
516
517 def _try_cast(val: str) -> int | str:
518 val = val.strip()
519 try:
520 m = match("(\\d+)(.*)", val)
521 if m is not None:
522 val = m.groups()[0]
523 return int(val)
524 return val
525 except ValueError:
526 return val
527
528 # remove git version suffixes if present
529 lhs = lhs.split("+", 1)[0]
530 rhs = rhs.split("+", 1)[0]
531
532 # parse the version strings in this basic way without `packaging` package
533 lhs_ = map(_try_cast, lhs.split("."))
534 rhs_ = map(_try_cast, rhs.split("."))
535 return lhs_, rhs_
536
537
538def version_leq(lhs: str, rhs: str) -> bool:

Callers 2

version_leqFunction · 0.85
version_geqFunction · 0.85

Calls 1

splitMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…