MCPcopy Create free account
hub / github.com/tensorflow/datasets / _str_to_version

Function _str_to_version

tensorflow_datasets/core/utils/version.py:244–265  ·  view source on GitHub ↗

Return the tuple (major, minor, patch) version extracted from the str.

(
    version_str: str, allow_wildcard=False
)

Source from the content-addressed store, hash-verified

242
243
244def _str_to_version(
245 version_str: str, allow_wildcard=False
246) -> tuple[int | str, int | str, int | str]:
247 """Return the tuple (major, minor, patch) version extracted from the str."""
248 if not isinstance(version_str, str):
249 raise TypeError(
250 "Can only convert strings to versions. "
251 f"Got: {type(version_str)} with value {version_str}."
252 )
253 reg = _VERSION_WILDCARD_REG if allow_wildcard else _VERSION_RESOLVED_REG
254 res = reg.match(version_str)
255 if not res:
256 msg = "Invalid version '{}'. Format should be x.y.z".format(version_str)
257 if allow_wildcard:
258 msg += " with {x,y,z} being digits or wildcard."
259 else:
260 msg += " with {x,y,z} being numbers without leading zeros."
261 raise ValueError(msg)
262 return tuple(
263 v if v == "*" else int(v) # pylint:disable=g-complex-comprehension
264 for v in [res.group("major"), res.group("minor"), res.group("patch")]
265 )
266
267
268def list_all_versions(root_dir: epath.PathLike) -> list[Version]:

Callers 2

__init__Method · 0.85
matchMethod · 0.85

Calls 1

matchMethod · 0.45

Tested by

no test coverage detected