Skip to content

Commit 65eb4a1

Browse files
committed
apply copilot's review
Signed-off-by: ooooo <[email protected]>
1 parent 90d4a0d commit 65eb4a1

File tree

3 files changed

+16
-9
lines changed

3 files changed

+16
-9
lines changed

MANIFEST.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
include build_backend.py
2+
include version.txt

build_backend.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1+
import logging
12
import subprocess
23
from pathlib import Path
34

45
from setuptools import build_meta as orig
56

67
_root = Path(__file__).parent.resolve()
8+
logger = logging.getLogger(__name__)
79

810

911
def 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

2123
def get_git_branch(cwd: Path | None = None) -> str:
@@ -29,7 +31,7 @@ def get_git_branch(cwd: Path | None = None) -> str:
2931
def 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

nemo_automodel/package_info.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,13 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
from ._version import __git_version__ as __git_version__
16-
from ._version import __version__ as __version__
15+
try:
16+
from ._version import __git_version__ as __git_version__
17+
from ._version import __version__ as __version__
18+
except ModuleNotFoundError:
19+
# Fallbacks for running directly from the source tree before _version.py is generated
20+
__git_version__ = "unknown"
21+
__version__ = "0.0.0"
1722

1823
__package_name__ = "nemo_automodel"
1924
__contact_names__ = "NVIDIA"

0 commit comments

Comments
 (0)