"include/vscode:/vscode.git/clone" did not exist on "e6ee659488f8a6368273d8f664057ec5b8e724f5"
Unverified Commit e2c5906e authored by Lei Wang's avatar Lei Wang Committed by GitHub
Browse files

[Enhancement] Refactor version retrieval logic in tilelang package (#1227)



* Introduced a new function, _compute_version, to determine the package version with a clear preference order, enhancing version management.
* The function checks for a VERSION file in the source checkout, falls back to importlib.metadata for installed distributions, and defaults to a development version if all else fails.
* Updated the __version__ variable assignment to utilize the new function, improving clarity and maintainability of version handling.
Co-authored-by: default avatarZhiwen Mo <zm125@ic.ac.uk>
parent 7045f1d6
...@@ -4,24 +4,51 @@ import ctypes ...@@ -4,24 +4,51 @@ import ctypes
import logging import logging
import warnings import warnings
from pathlib import Path
from tqdm.auto import tqdm from tqdm.auto import tqdm
from importlib.metadata import PackageNotFoundError, version
try: def _compute_version() -> str:
__version__ = version('tilelang') """Return the package version without being polluted by unrelated installs.
except PackageNotFoundError:
Preference order:
1) If running from a source checkout (VERSION file present at repo root),
use the dynamic version from version_provider (falls back to plain VERSION).
2) Otherwise, use importlib.metadata for the installed distribution.
3) As a last resort, return a dev sentinel.
"""
try: try:
from version_provider import dynamic_metadata repo_root = Path(__file__).resolve().parent.parent
version_file = repo_root / "VERSION"
print("version_file:", version_file)
if version_file.is_file():
try:
import version_provider
print("version_provider ", version_provider.__file__)
from version_provider import dynamic_metadata # type: ignore
print("dynamic_metadata:", dynamic_metadata, "version:",
dynamic_metadata("version"))
return dynamic_metadata("version")
except Exception:
# Fall back to the raw VERSION file if provider isn't available.
return version_file.read_text().strip()
except Exception:
# If any of the above fails, fall through to installed metadata.
pass
__version__ = dynamic_metadata('version') try:
from importlib.metadata import version as _dist_version # py3.8+
return _dist_version("tilelang")
except Exception as exc: except Exception as exc:
warnings.warn( warnings.warn(
f"tilelang version metadata unavailable ({exc!r}); using development version.", f"tilelang version metadata unavailable ({exc!r}); using development version.",
RuntimeWarning, RuntimeWarning,
stacklevel=2, stacklevel=2,
) )
__version__ = "0.0.dev0" return "0.0.dev0"
__version__ = _compute_version()
class TqdmLoggingHandler(logging.Handler): class TqdmLoggingHandler(logging.Handler):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment