|
2 | 2 | import sys |
3 | 3 |
|
4 | 4 | from setuptools import find_packages, setup |
| 5 | +from setuptools_scm import ScmVersion |
5 | 6 |
|
6 | | -sys.path.insert(0, os.path.abspath(os.path.dirname(__file__))) |
7 | | -from utils.version_extractor import extract_version_info # noqa isort:skip |
| 7 | +# Set the build type using an environment variable to give us |
| 8 | +# different package names based on the reason for the build. |
| 9 | +VALID_BUILD_TYPES = {"release", "nightly", "dev"} |
| 10 | +BUILD_TYPE = os.environ.get("BUILD_TYPE", "dev") |
| 11 | +if BUILD_TYPE not in VALID_BUILD_TYPES: |
| 12 | + raise ValueError( |
| 13 | + f"Unsupported build type {BUILD_TYPE!r}, must be one of {VALID_BUILD_TYPES}" |
| 14 | + ) |
8 | 15 |
|
9 | | -# load version info for the package |
10 | | -package_path = os.path.join( |
11 | | - os.path.dirname(os.path.realpath(__file__)), "src", "llmcompressor" |
12 | | -) |
13 | | -version_info = extract_version_info(package_path) |
14 | 16 |
|
15 | | -if version_info.build_type == "release": |
16 | | - package_name = "llmcompressor" |
17 | | -elif version_info.build_type == "dev": |
18 | | - package_name = "llmcompressor-dev" |
19 | | -elif version_info.build_type == "nightly": |
20 | | - package_name = "llmcompressor-nightly" |
21 | | -else: |
22 | | - raise ValueError(f"Unsupported build type {version_info.build_type}") |
| 17 | +def version_func(version: ScmVersion) -> str: |
| 18 | + from setuptools_scm.version import guess_next_version |
| 19 | + |
| 20 | + print( |
| 21 | + f"computing version for {BUILD_TYPE} build with " |
| 22 | + f"{'dirty' if version.dirty else 'clean'} local repository" |
| 23 | + f"{' and exact version from tag' if version.exact else ''}", |
| 24 | + file=sys.stderr, |
| 25 | + ) |
| 26 | + |
| 27 | + if BUILD_TYPE == "nightly": |
| 28 | + # Nightly builds use alpha versions to ensure they are marked |
| 29 | + # as pre-releases on pypi.org. |
| 30 | + return version.format_next_version( |
| 31 | + guess_next=guess_next_version, |
| 32 | + fmt="{guessed}.a{node_date:%Y%m%d}", |
| 33 | + ) |
| 34 | + |
| 35 | + if ( |
| 36 | + BUILD_TYPE == "release" |
| 37 | + and not version.dirty |
| 38 | + and (version.exact or version.node is None) |
| 39 | + ): |
| 40 | + # When we have a tagged version, use that without modification. |
| 41 | + return version.format_with("{tag}") |
| 42 | + |
| 43 | + # In development mode or when the local repository is dirty, treat |
| 44 | + # it is as local development version. |
| 45 | + return version.format_next_version( |
| 46 | + guess_next=guess_next_version, |
| 47 | + fmt="{guessed}.dev{distance}", |
| 48 | + ) |
| 49 | + |
| 50 | + |
| 51 | +def localversion_func(version: ScmVersion) -> str: |
| 52 | + from setuptools_scm.version import get_local_node_and_date |
| 53 | + |
| 54 | + print( |
| 55 | + f"computing local version for {BUILD_TYPE} build with " |
| 56 | + f"{'dirty' if version.dirty else 'clean'} local repository" |
| 57 | + "f{' and exact version from tag' if version.exact else ''}", |
| 58 | + file=sys.stderr, |
| 59 | + ) |
| 60 | + |
| 61 | + # When we are building nightly versions, we guess the next release |
| 62 | + # and add the date as an alpha version. We cannot publish packages |
| 63 | + # with local versions, so we do not add one. |
| 64 | + if BUILD_TYPE == "nightly": |
| 65 | + return "" |
| 66 | + |
| 67 | + # When we have an exact tag, with no local changes, do not append |
| 68 | + # anything to the local version field. |
| 69 | + if ( |
| 70 | + BUILD_TYPE == "release" |
| 71 | + and not version.dirty |
| 72 | + and (version.exact or version.node is None) |
| 73 | + ): |
| 74 | + return "" |
| 75 | + |
| 76 | + # In development mode or when the local repository is dirty, |
| 77 | + # return a string that includes the git SHA (node) and a date, |
| 78 | + # formatted as a local version tag. |
| 79 | + return get_local_node_and_date(version) |
23 | 80 |
|
24 | 81 |
|
25 | 82 | setup( |
26 | | - name=package_name, |
27 | | - version=version_info.version, |
| 83 | + name="llmcompressor", |
| 84 | + use_scm_version={ |
| 85 | + "version_scheme": version_func, |
| 86 | + "local_scheme": localversion_func, |
| 87 | + }, |
28 | 88 | author="Neuralmagic, Inc.", |
29 | 89 | author_email="support@neuralmagic.com", |
30 | 90 | description=( |
|
62 | 122 | "pillow", |
63 | 123 | ( |
64 | 124 | "compressed-tensors==0.9.3" |
65 | | - if version_info.build_type == "release" |
66 | | - else "compressed-tensors-nightly" |
| 125 | + if BUILD_TYPE == "release" |
| 126 | + else "compressed-tensors>=0.9.4a2" |
67 | 127 | ), |
68 | 128 | ], |
69 | 129 | extras_require={ |
|
0 commit comments