Skip to content

Commit 8cf6f6c

Browse files
committed
upd
1 parent 23d2d6b commit 8cf6f6c

File tree

5 files changed

+61
-22
lines changed

5 files changed

+61
-22
lines changed

build_backend.py

Lines changed: 38 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,20 +25,48 @@
2525
_data_dir = _root / "flashinfer" / "data"
2626

2727

28-
def get_version():
29-
package_version = (_root / "version.txt").read_text().strip()
28+
def _create_build_metadata():
29+
"""Create build metadata file with version information."""
30+
version_file = _root / "version.txt"
31+
if version_file.exists():
32+
with open(version_file, "r") as f:
33+
version = f.read().strip()
34+
else:
35+
version = "0.0.0+unknown"
36+
37+
# Add dev suffix if specified
3038
dev_suffix = os.environ.get("FLASHINFER_DEV_RELEASE_SUFFIX", "")
3139
if dev_suffix:
32-
package_version = f"{package_version}.dev{dev_suffix}"
33-
return package_version
40+
version = f"{version}.dev{dev_suffix}"
3441

42+
# Get git version
43+
git_version = get_git_version(cwd=_root)
3544

36-
# Create _build_meta.py at import time so setuptools can read the version
37-
build_meta_file = _root / "flashinfer" / "_build_meta.py"
38-
with open(build_meta_file, "w") as f:
39-
f.write('"""Build metadata for flashinfer package."""\n')
40-
f.write(f'__version__ = "{get_version()}"\n')
41-
f.write(f'__git_version__ = "{get_git_version(cwd=_root)}"\n')
45+
# Create build metadata in the source tree
46+
package_dir = Path(__file__).parent / "flashinfer"
47+
build_meta_file = package_dir / "_build_meta.py"
48+
49+
# Check if we're in a git repository
50+
git_dir = Path(__file__).parent / ".git"
51+
in_git_repo = git_dir.exists()
52+
53+
# If file exists and not in git repo (installing from sdist), keep existing file
54+
if build_meta_file.exists() and not in_git_repo:
55+
print("Build metadata file already exists (not in git repo), keeping it")
56+
return version
57+
58+
# In git repo (editable) or file doesn't exist, create/update it
59+
with open(build_meta_file, "w") as f:
60+
f.write('"""Build metadata for flashinfer package."""\n')
61+
f.write(f'__version__ = "{version}"\n')
62+
f.write(f'__git_version__ = "{git_version}"\n')
63+
64+
print(f"Created build metadata file with version {version}")
65+
return version
66+
67+
68+
# Create build metadata as soon as this module is imported
69+
_create_build_metadata()
4270

4371

4472
def write_if_different(path: Path, content: str) -> None:
@@ -74,11 +102,6 @@ def ln(source: str, target: str) -> None:
74102
ln("csrc", "csrc")
75103
ln("include", "include")
76104

77-
# Always ensure version.txt is present
78-
version_file = _data_dir / "version.txt"
79-
if not version_file.exists() or not use_symlinks:
80-
shutil.copy(_root / "version.txt", version_file)
81-
82105

83106
def _prepare_for_wheel():
84107
# For wheel, copy actual files instead of symlinks so they are included in the wheel

docs/conf.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
from pathlib import Path
21
from typing import Any, List
32

43
import flashinfer # noqa: F401
@@ -12,7 +11,6 @@
1211
# -- Project information -----------------------------------------------------
1312
# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information
1413

15-
root = Path(__file__).parents[1].resolve()
1614
# FlashInfer is installed via pip before building docs
1715
autodoc_mock_imports = [
1816
"torch",
@@ -28,9 +26,8 @@
2826
author = "FlashInfer Contributors"
2927
copyright = f"2023-2025, {author}"
3028

31-
package_version = (root / "version.txt").read_text().strip()
32-
version = package_version
33-
release = package_version
29+
version = flashinfer.__version__
30+
release = flashinfer.__version__
3431

3532
# -- General configuration ---------------------------------------------------
3633
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration

flashinfer-cubin/build_backend.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,16 @@ def _create_build_metadata():
6666
package_dir = Path(__file__).parent / "flashinfer_cubin"
6767
build_meta_file = package_dir / "_build_meta.py"
6868

69+
# Check if we're in a git repository
70+
git_dir = Path(__file__).parent.parent / ".git"
71+
in_git_repo = git_dir.exists()
72+
73+
# If file exists and not in git repo (installing from sdist), keep existing file
74+
if build_meta_file.exists() and not in_git_repo:
75+
print("Build metadata file already exists (not in git repo), keeping it")
76+
return version
77+
78+
# In git repo (editable) or file doesn't exist, create/update it
6979
with open(build_meta_file, "w") as f:
7080
f.write('"""Build metadata for flashinfer-cubin package."""\n')
7181
f.write(f'__version__ = "{version}"\n')

flashinfer-jit-cache/build_backend.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,16 @@ def _create_build_metadata():
5454
version = f"{version}+{cuda_suffix}"
5555
build_meta_file = Path(__file__).parent / "flashinfer_jit_cache" / "_build_meta.py"
5656

57+
# Check if we're in a git repository
58+
git_dir = Path(__file__).parent.parent / ".git"
59+
in_git_repo = git_dir.exists()
60+
61+
# If file exists and not in git repo (installing from sdist), keep existing file
62+
if build_meta_file.exists() and not in_git_repo:
63+
print("Build metadata file already exists (not in git repo), keeping it")
64+
return version
65+
66+
# In git repo (editable) or file doesn't exist, create/update it
5767
with open(build_meta_file, "w") as f:
5868
f.write('"""Build metadata for flashinfer-jit-cache package."""\n')
5969
f.write(f'__version__ = "{version}"\n')

pyproject.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,7 @@ exclude = ["flashinfer-jit-cache*", "flashinfer-cubin*"]
6161
]
6262
"flashinfer.data" = [
6363
"csrc/**",
64-
"include/**",
65-
"version.txt"
64+
"include/**"
6665
]
6766
"flashinfer.data.cutlass" = [
6867
"include/**",

0 commit comments

Comments
 (0)