-
Notifications
You must be signed in to change notification settings - Fork 346
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
__version__
attribute to Python module (#675)
Add __version__ attribute to Python module Signed-off-by: Tim Moon <[email protected]>
- Loading branch information
Showing
5 changed files
with
83 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
1.5.0dev | ||
1.5.0.dev0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# Copyright (c) 2022-2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
# | ||
# See LICENSE for license information. | ||
|
||
"""Transformer Engine version string.""" | ||
import os | ||
from pathlib import Path | ||
import subprocess | ||
|
||
def te_version() -> str: | ||
"""Transformer Engine version string | ||
Includes Git commit as local version, unless suppressed with | ||
NVTE_NO_LOCAL_VERSION environment variable. | ||
""" | ||
root_path = Path(__file__).resolve().parent | ||
with open(root_path / "VERSION", "r") as f: | ||
version = f.readline().strip() | ||
if not int(os.getenv("NVTE_NO_LOCAL_VERSION", "0")): | ||
try: | ||
output = subprocess.run( | ||
["git", "rev-parse" , "--short", "HEAD"], | ||
capture_output=True, | ||
cwd=root_path, | ||
check=True, | ||
universal_newlines=True, | ||
) | ||
except (subprocess.CalledProcessError, OSError): | ||
pass | ||
else: | ||
commit = output.stdout.strip() | ||
version += f"+{commit}" | ||
return version |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# Copyright (c) 2022-2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
# | ||
# See LICENSE for license information. | ||
|
||
"""Version information""" | ||
import sys | ||
from packaging.version import Version | ||
|
||
if sys.version_info >= (3, 8): | ||
from importlib import metadata | ||
else: | ||
import importlib_metadata as metadata | ||
|
||
def _version_str() -> str: | ||
"""Transformer Engine version string""" | ||
|
||
# Try getting version from package metadata | ||
version_str = None | ||
try: | ||
version_str = metadata.version("transformer_engine") | ||
except: | ||
pass | ||
if version_str: | ||
return version_str | ||
|
||
# Try getting version from Git root directory | ||
try: | ||
from te_version import te_version | ||
version_str = te_version() | ||
except: | ||
pass | ||
if version_str: | ||
return version_str | ||
|
||
# Could not deduce version | ||
return "0.dev0+unknown" | ||
|
||
# Transformer Engine version | ||
__version__: Version = Version(_version_str()) |