Support detailed version tracking that captures git repository information (#639)

#### Version Format

The package version includes the git commit hash directly in the version
string for development builds:
- **Release version**: `0.7.0`
- **Development version**: `0.7.0.dev36+g6e2360d69` (includes short
commit hash)
- **Development with uncommitted changes**:
`0.7.0.dev36+g6e2360d69.dirty`

#### Checking Version Information

After installation, you can check the version information in several
ways:

**From Python:**
```python
import mscclpp

# Access individual attributes
print(f"Version: {mscclpp.__version__}")           # Full version with commit
Version: 0.7.0.dev36+g6e2360d69

# Get as dictionary
mscclpp.version()
{'version': '0.7.0.dev46+gb0d27c58f', 'base_version': '0.7.0', 'git_commit': 'b0d27c58f'}
```

#### Version Information Details

The version tracking captures:
- **Package Version** (`mscclpp.__version__`): Full version string
including git commit (e.g., `0.7.0.dev36+g6e2360d69`)

This information is embedded during the package build process and
remains accessible even after distribution, making it easier to debug
issues and ensure reproducibility.

---------

Co-authored-by: Binyang Li <binyli@microsoft.com>
This commit is contained in:
Qinghua Zhou
2025-09-30 09:00:33 -07:00
committed by GitHub
parent 70b8297c56
commit 16a96ea77b
4 changed files with 237 additions and 8 deletions

View File

@@ -5,8 +5,59 @@
import os
import warnings
import re
from functools import wraps
# Get version
def _get_version():
"""Get version from the best available source"""
# Try setuptools-scm generated _version.py (most reliable)
try:
from ._version import __version__
return __version__
except ImportError:
raise RuntimeError("Could not determine MSCCL++ version from setuptools-scm generated _version.py.")
# Parse version components
def _parse_version(version_string):
"""Parse version components from setuptools-scm generated version"""
# Pattern for versions like "0.7.0.dev36+g6e2360d69" (without .dYYYYMMDD)
pattern = r"^v?(?P<base>[\d\.]+)(?:\.dev(?P<distance>\d+))?(?:\+g(?P<commit>[a-f0-9]+))?(?P<dirty>\.dirty)?$"
match = re.match(pattern, version_string)
if match:
return {"base_version": match.group("base"), "git_commit": match.group("commit") or "unknown"}
else:
# Fallback parsing - try to extract what we can
base = version_string.split("+")[0].lstrip("v").split(".dev")[0]
commit = "unknown"
return {"base_version": base, "git_commit": commit}
__version__ = _get_version()
# Parse the version
_version_info = _parse_version(__version__)
__base_version__ = _version_info["base_version"]
__git_commit__ = _version_info["git_commit"]
def _version():
"""Get complete version information as a dictionary"""
return {
"version": __version__,
"base_version": __base_version__,
"git_commit": __git_commit__,
}
version: dict = _version()
from ._mscclpp import (
Env,
ErrorCode,
@@ -40,12 +91,10 @@ from ._mscclpp import (
PacketType,
RawGpuBuffer,
env,
version,
is_nvls_supported,
npkit,
)
__all__ = [
"Device",
"DeviceType",
@@ -69,11 +118,12 @@ __all__ = [
"Executor",
"ExecutionPlan",
"PacketType",
"version",
"is_nvls_supported",
"alloc_shared_physical_cuda",
"npkit",
# Version information
"__version__",
"version",
"get_include",
"get_lib",
### Deprecated ###
@@ -82,8 +132,6 @@ __all__ = [
"SmDevice2DeviceSemaphore",
]
__version__: str = str(version())
if os.environ.get("MSCCLPP_HOME", None) is None:
os.environ["MSCCLPP_HOME"] = os.path.abspath(os.path.dirname(__file__))