|
4 | 4 | # See https://llvm.org/LICENSE.txt for license information.
|
5 | 5 | # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
6 | 6 |
|
7 |
| -from distutils.core import setup, Extension |
8 |
| -import sys |
| 7 | +import json |
| 8 | +import os |
9 | 9 | import shutil
|
10 | 10 | import subprocess
|
11 |
| -import os |
12 |
| -from pathlib import Path |
| 11 | +import sys |
13 | 12 | from distutils.command.build import build as _build
|
| 13 | +from distutils.core import setup, Extension |
| 14 | +from pathlib import Path |
14 | 15 | from setuptools import find_namespace_packages
|
15 |
| -from setuptools.command.build_ext import build_ext as _build_ext |
16 | 16 | from setuptools.command.build_py import build_py as _build_py
|
| 17 | +from setuptools.command.build_ext import build_ext as _build_ext |
17 | 18 |
|
18 | 19 |
|
19 | 20 | def get_env_boolean(name: str, default_value: bool = False) -> bool:
|
@@ -126,11 +127,43 @@ def run(self):
|
126 | 127 |
|
127 | 128 |
|
128 | 129 | class NoopBuildExtension(_build_ext):
|
129 |
| - def build_extension(self, ext): |
130 |
| - ... |
| 130 | + def build_extension(self, ext): ... |
| 131 | + |
| 132 | + def copy_extensions_to_source(self, *args, **kwargs): ... |
| 133 | + |
| 134 | + |
| 135 | +# Setup and get version information. |
| 136 | +VERSION_INFO_FILE = os.path.join(SOURCE_DIR, "version_info.json") |
| 137 | + |
| 138 | + |
| 139 | +def load_version_info(): |
| 140 | + with open(VERSION_INFO_FILE, "rt") as f: |
| 141 | + return json.load(f) |
| 142 | + |
| 143 | + |
| 144 | +def find_git_version(): |
| 145 | + try: |
| 146 | + return ( |
| 147 | + subprocess.check_output(["git", "rev-parse", "HEAD"], cwd=SOURCE_DIR) |
| 148 | + .decode("utf-8") |
| 149 | + .strip() |
| 150 | + ) |
| 151 | + except subprocess.SubprocessError as e: |
| 152 | + print(f"ERROR: Could not get git revision: {e}", file=sys.stderr) |
| 153 | + return None |
| 154 | + |
| 155 | + |
| 156 | +try: |
| 157 | + version_info = load_version_info() |
| 158 | +except FileNotFoundError: |
| 159 | + print("version_info.json not found. Using defaults", file=sys.stderr) |
| 160 | + version_info = {} |
| 161 | +git_version = find_git_version() |
131 | 162 |
|
132 |
| - def copy_extensions_to_source(self, *args, **kwargs): |
133 |
| - ... |
| 163 | +PACKAGE_SUFFIX = version_info.get("package-suffix") or "" |
| 164 | +PACKAGE_VERSION = version_info.get("package-version") |
| 165 | +if not PACKAGE_VERSION: |
| 166 | + PACKAGE_VERSION = f"0.dev0+{git_version or '0'}" |
134 | 167 |
|
135 | 168 |
|
136 | 169 | def maybe_nuke_cmake_cache(cmake_build_dir):
|
@@ -324,7 +357,7 @@ def populate_built_package(abs_dir):
|
324 | 357 |
|
325 | 358 | setup(
|
326 | 359 | name="shortfin",
|
327 |
| - version="0.9", |
| 360 | + version=f"{PACKAGE_VERSION}", |
328 | 361 | description="Shortfin native library implementation",
|
329 | 362 | author="SHARK Authors",
|
330 | 363 | packages=packages,
|
|
0 commit comments