1+ import logging
12import subprocess
23from pathlib import Path
34
45from setuptools import build_meta as orig
56
67_root = Path (__file__ ).parent .resolve ()
8+ logger = logging .getLogger (__name__ )
79
810
911def is_git_repo ():
@@ -15,7 +17,7 @@ def get_git_commit_hash(cwd: Path | None, length: int = 10) -> str:
1517 cmd = ["git" , "rev-parse" , f"--short={ length } " , "HEAD" ]
1618 return subprocess .check_output (cmd , cwd = cwd ).strip ().decode ("utf-8" )
1719 except Exception :
18- return ""
20+ return "unknown "
1921
2022
2123def get_git_branch (cwd : Path | None = None ) -> str :
@@ -29,7 +31,7 @@ def get_git_branch(cwd: Path | None = None) -> str:
2931def get_git_tag (cwd : Path | None = None ) -> str :
3032 try :
3133 cmd = ["git" , "describe" , "--tags" , "--match" , "v*" , "--exact-match" ]
32- return subprocess .check_output (cmd , cwd = cwd , stderr = subprocess . DEVNULL ).strip ().decode ("utf-8" )
34+ return subprocess .check_output (cmd , cwd = cwd ).strip ().decode ("utf-8" )
3335 except Exception :
3436 return ""
3537
@@ -54,20 +56,19 @@ def _generate_version_info():
5456
5557 # If file exists and not in git repo (installing from sdist), keep existing file
5658 if _version_file .exists () and not is_git_repo ():
57- print ("The _version file already exists (not in git repo), keeping it" )
59+ logger . info ("The _version file already exists (not in git repo), keeping it" )
5860 return version
5961
6062 # In git repo (editable) or file doesn't exist, create/update it
6163 with open (_version_file , "w" ) as f :
62- f .write ('"""Build _version for nemo_automodel package ."""\n ' )
64+ f .write ('"""Generate version info file with git metadata ."""\n ' )
6365 if git_branch .startswith ("release" ) or git_tag :
64- # Release version or tag version may be push to PyPI, it shouldn't has git hash suffix which will affect wheel name.
66+ # Release version or tag version may be pushed to PyPI; it shouldn't have a git hash suffix, which will affect the wheel name.
6567 f .write (f'__version__ = "{ version } "\n ' )
6668 else :
6769 f .write (f'__version__ = "{ version } +{ git_commit_hash } "\n ' )
68- git_commit_hash = git_commit_hash or "unknown"
6970 f .write (f'__git_version__ = "{ git_commit_hash } "\n ' )
70- print (f"Created _version file with version { version } " )
71+ logger . info (f"Created _version file with version { version } " )
7172 return version
7273
7374
0 commit comments