#1697·clearml

Version crashes with IndexError on PEP 440 local versions (e.g. torch "2.1.0+cu121")

Author: jaideeppyneCreated Aug 21, 2026Updated Aug 21, 2026

Summary

clearml.utilities.version.Version raises IndexError: tuple index out of range when parsing a valid PEP 440 version that has a local segment, such as PyTorch's CUDA/CPU wheels (2.1.0+cu121, 1.0+cpu, 2.0.1+cu118). These are ubiquitous in the ML environments ClearML instruments.

Reproduction

python
from clearml.utilities.version import Version

Version.is_valid_version_string("2.1.0+cu121")   # True
Version("2.1.0+cu121")                            # IndexError: tuple index out of range

The parser validates the string as legal but then crashes when constructing it.

Cause

In Version._cmpkey (clearml/utilities/version.py:323), the local segment is handled with local = local[1], but _parse_local_version returns the local segment as a tuple — "cu121"("cu121",) — which has no index 1. Single-segment local versions (the common case) therefore crash; multi-segment ones silently keep only the 2nd element, giving wrong ordering.

Fix

Parse the local segment the way packaging.version does (absent local sorts before present; alphanumeric parts sort before numeric). PR to follow.

(Reported with AI assistance; verified against packaging.version.)