17
17
from typing import List , Dict , Tuple
18
18
19
19
20
- def get_release_and_version (package_path : str ) -> Tuple [bool , bool , str , str , str , str ]:
21
- """
22
- Load version and release info from compressed-tensors package
23
- """
24
- # compressed-tensors/src/compressed_tensors/version.py always exists, default source of truth
25
- version_path = os .path .join (package_path , "version.py" )
26
-
27
- # exec() cannot set local variables so need to manually
28
- locals_dict = {}
29
- exec (open (version_path ).read (), globals (), locals_dict )
30
- is_release = locals_dict .get ("is_release" , False )
31
- version = locals_dict .get ("version" , "unknown" )
32
- version_major = locals_dict .get ("version_major" , "unknown" )
33
- version_minor = locals_dict .get ("version_minor" , "unknown" )
34
- version_bug = locals_dict .get ("version_bug" , "unknown" )
35
-
36
- print (f"Loaded version { version } from { version_path } " )
37
-
38
- return (
39
- is_release ,
40
- version ,
41
- version_major ,
42
- version_minor ,
43
- version_bug ,
20
+ # Set the build type using an environment variable to give us
21
+ # different package names based on the reason for the build.
22
+ VALID_BUILD_TYPES = {"release" , "nightly" , "dev" }
23
+ BUILD_TYPE = os .environ .get ("BUILD_TYPE" , "dev" )
24
+ if BUILD_TYPE not in VALID_BUILD_TYPES :
25
+ raise ValueError (
26
+ f"Unsupported build type { BUILD_TYPE !r} , must be one of { VALID_BUILD_TYPES } "
44
27
)
45
28
29
+ from setuptools_scm import ScmVersion
30
+
31
+ def version_func (version : ScmVersion ) -> str :
32
+ from setuptools_scm .version import guess_next_version
33
+
34
+ if BUILD_TYPE == "nightly" :
35
+ # Nightly builds use alpha versions to ensure they are marked
36
+ # as pre-releases on pypi.org.
37
+ return version .format_next_version (
38
+ guess_next = guess_next_version ,
39
+ fmt = "{guessed}.a{node_date:%Y%m%d}" ,
40
+ )
41
+
42
+ if (
43
+ BUILD_TYPE == "release"
44
+ and not version .dirty
45
+ and (version .exact or version .node is None )
46
+ ):
47
+ # When we have a tagged version, use that without modification.
48
+ return version .format_with ("{tag}" )
49
+
50
+ # In development mode or when the local repository is dirty, treat
51
+ # it is as local development version.
52
+ return version .format_next_version (
53
+ guess_next = guess_next_version ,
54
+ fmt = "{guessed}.dev{distance}" ,
55
+ )
46
56
47
- package_path = os .path .join (
48
- os .path .dirname (os .path .realpath (__file__ )), "src" , "compressed_tensors"
49
- )
50
- (
51
- is_release ,
52
- version ,
53
- version_major ,
54
- version_minor ,
55
- version_bug ,
56
- ) = get_release_and_version (package_path )
57
57
58
- version_nm_deps = f"{ version_major } .{ version_minor } .0"
58
+ def localversion_func (version : ScmVersion ) -> str :
59
+ from setuptools_scm .version import get_local_node_and_date
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 ""
59
75
60
- if is_release :
61
- _PACKAGE_NAME = "compressed-tensors"
62
- else :
63
- _PACKAGE_NAME = "compressed-tensors-nightly"
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 )
64
80
65
81
66
82
def _setup_long_description () -> Tuple [str , str ]:
@@ -81,8 +97,11 @@ def _setup_extras() -> Dict:
81
97
}
82
98
83
99
setup (
84
- name = _PACKAGE_NAME ,
85
- version = version ,
100
+ name = "compressed-tensors" ,
101
+ use_scm_version = {
102
+ "version_scheme" : version_func ,
103
+ "local_scheme" : localversion_func ,
104
+ },
86
105
author = "Neuralmagic, Inc." ,
87
106
author_email = "support@neuralmagic.com" ,
88
107
license = "Apache 2.0" ,
0 commit comments