|
25 | 25 | _data_dir = _root / "flashinfer" / "data"
|
26 | 26 |
|
27 | 27 |
|
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 |
30 | 38 | dev_suffix = os.environ.get("FLASHINFER_DEV_RELEASE_SUFFIX", "")
|
31 | 39 | if dev_suffix:
|
32 |
| - package_version = f"{package_version}.dev{dev_suffix}" |
33 |
| - return package_version |
| 40 | + version = f"{version}.dev{dev_suffix}" |
34 | 41 |
|
| 42 | + # Get git version |
| 43 | + git_version = get_git_version(cwd=_root) |
35 | 44 |
|
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() |
42 | 70 |
|
43 | 71 |
|
44 | 72 | def write_if_different(path: Path, content: str) -> None:
|
@@ -74,11 +102,6 @@ def ln(source: str, target: str) -> None:
|
74 | 102 | ln("csrc", "csrc")
|
75 | 103 | ln("include", "include")
|
76 | 104 |
|
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 |
| - |
82 | 105 |
|
83 | 106 | def _prepare_for_wheel():
|
84 | 107 | # For wheel, copy actual files instead of symlinks so they are included in the wheel
|
|
0 commit comments