forked from axolotl-ai-cloud/axolotl
-
Notifications
You must be signed in to change notification settings - Fork 0
feat(cli): new launch banner with repo + build metadata #26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
thad0ctor
wants to merge
3
commits into
main
Choose a base branch
from
worktree-axolotl-banner
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+80
−15
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,30 +1,93 @@ | ||
| """Axolotl ASCII logo utils.""" | ||
|
|
||
| import os | ||
| import subprocess # nosec B404 | ||
| from pathlib import Path | ||
|
|
||
| import axolotl | ||
| from axolotl.utils.distributed import is_main_process | ||
|
|
||
| AXOLOTL_LOGO = """ | ||
| #@@ #@@ @@# @@# | ||
| @@ @@ @@ @@ =@@# @@ #@ =@@#. | ||
| @@ #@@@@@@@@@ @@ #@#@= @@ #@ .=@@ | ||
| #@@@@@@@@@@@@@@@@@ =@# @# ##= ## =####=+ @@ =#####+ =#@@###. @@ | ||
| @@@@@@@@@@/ +@@/ +@@ #@ =@= #@= @@ =@#+ +#@# @@ =@#+ +#@# #@. @@ | ||
| @@@@@@@@@@ ##@@ ##@@ =@# @# =@# @# @@ @@ @@ @@ #@ #@ @@ | ||
| @@@@@@@@@@@@@@@@@@@@ #@=+++#@= =@@# @@ @@ @@ @@ #@ #@ @@ | ||
| =@#=====@@ =@# @# @@ @@ @@ @@ #@ #@ @@ | ||
| @@@@@@@@@@@@@@@@ @@@@ #@ #@= #@= +@@ #@# =@# @@. =@# =@# #@. @@ | ||
| =@# @# #@= #@ =#@@@@#= +#@@= +#@@@@#= .##@@+ @@ | ||
| @@@@ @@@@@@@@@@@@@@@@ | ||
| """ | ||
| GITHUB_URL = "https://github.com/axolotl-ai-cloud/axolotl" | ||
|
|
||
| _AXOLOTL_LOGO_HEAD = "\n".join( | ||
| [ | ||
| " ┌─┐┌─┐ ┌─┐┌─┐", | ||
| " │ ││ │ │ ││ │ █████ ██ ██ █████ ██ █████ ███████ ██", | ||
| " │ └┘ └────┘ └┘ │ ██ ██ ██ ██ ██ ██ ██ ██ ██ ███ ██", | ||
| " │ │ ███████ ███ ██ ██ ██ ██ ██ ███ ██", | ||
| " │ ◉ ◉ │ ██ ██ ██ ██ ██ ██ ██ ██ ██ ███ ██", | ||
| " └──────────────┘ ██ ██ ██ ██ █████ ███████ █████ ███ ███████", | ||
| ] | ||
| ) | ||
|
|
||
| _BARS_TOP = " ▄▄▄▄▄▄▄▄▄▄ ▄▄▄" | ||
| _BARS_BOTTOM = " ▄▄▄ ▄▄▄▄▄▄▄▄▄▄" | ||
|
|
||
| _LETTERS_START_COL = len(" └──────────────┘ ") | ||
| _LETTERS_END_COL = len( | ||
| " └──────────────┘ ██ ██ ██ ██ █████ ███████ █████ ███ ███████" | ||
| ) | ||
|
|
||
| HAS_PRINTED_LOGO = False | ||
|
|
||
|
|
||
| def _get_git_info() -> tuple[str | None, str | None]: | ||
| """Return (short_sha, commit_date) or (None, None) when not a git checkout.""" | ||
| repo_root = Path(axolotl.__file__).resolve().parents[2] | ||
| if not (repo_root / ".git").exists(): | ||
| return None, None | ||
| try: | ||
| sha = subprocess.check_output( # nosec B603 B607 | ||
| ["git", "-C", str(repo_root), "rev-parse", "--short", "HEAD"], | ||
| stderr=subprocess.DEVNULL, | ||
| text=True, | ||
| ).strip() | ||
| date = subprocess.check_output( # nosec B603 B607 | ||
| ["git", "-C", str(repo_root), "log", "-1", "--format=%cs"], | ||
| stderr=subprocess.DEVNULL, | ||
| text=True, | ||
| ).strip() | ||
| return sha or None, date or None | ||
| except (subprocess.CalledProcessError, FileNotFoundError, OSError): | ||
| return None, None | ||
|
|
||
|
|
||
| def _centered_under_letters(text: str, *, bars: str = "") -> str: | ||
| """Pad `text` so it sits centered under the AXOLOTL letters, optionally after bars.""" | ||
| available = _LETTERS_END_COL - _LETTERS_START_COL | ||
| pad = max(0, (available - len(text)) // 2) | ||
| text_col = _LETTERS_START_COL + pad | ||
| gap = max(1, text_col - len(bars)) | ||
| return bars + " " * gap + text | ||
|
|
||
|
|
||
| def _build_logo() -> str: | ||
| sha, date = _get_git_info() | ||
| parts = [f"v{axolotl.__version__}"] | ||
| if sha: | ||
| parts.append(sha) | ||
| if date: | ||
| parts.append(date) | ||
| build = " · ".join(parts) | ||
| return "\n".join( | ||
| [ | ||
| "", | ||
| _AXOLOTL_LOGO_HEAD, | ||
| _BARS_TOP, | ||
| _centered_under_letters(GITHUB_URL, bars=_BARS_BOTTOM), | ||
| _centered_under_letters(build), | ||
| "", | ||
| ] | ||
| ) | ||
|
|
||
|
|
||
| def print_axolotl_text_art(): | ||
| """Prints axolotl ASCII art.""" | ||
|
|
||
| global HAS_PRINTED_LOGO | ||
| if HAS_PRINTED_LOGO: | ||
| if HAS_PRINTED_LOGO or os.environ.get("AXOLOTL_BANNER_PRINTED"): | ||
| return | ||
| if is_main_process(): | ||
| HAS_PRINTED_LOGO = True | ||
| print(AXOLOTL_LOGO) | ||
| os.environ["AXOLOTL_BANNER_PRINTED"] = "1" | ||
| print(_build_logo()) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a timeout (and handle
TimeoutExpired) to_get_git_info()best-effortgitprobessubprocess.check_output()calls insrc/axolotl/cli/art.py(lines 40 and 45) have no timeout and_get_git_info()doesn’t catchsubprocess.TimeoutExpired, so startup can block ifgithangs. Add a short timeout to both calls and treatTimeoutExpiredlike the other fallbacks.Suggested fix
try: sha = subprocess.check_output( # nosec B603 B607 ["git", "-C", str(repo_root), "rev-parse", "--short", "HEAD"], stderr=subprocess.DEVNULL, text=True, + timeout=1, ).strip() date = subprocess.check_output( # nosec B603 B607 ["git", "-C", str(repo_root), "log", "-1", "--format=%cs"], stderr=subprocess.DEVNULL, text=True, + timeout=1, ).strip() return sha or None, date or None - except (subprocess.CalledProcessError, FileNotFoundError, OSError): + except ( + subprocess.CalledProcessError, + subprocess.TimeoutExpired, + FileNotFoundError, + OSError, + ): return None, None🧰 Tools
🪛 Ruff (0.15.13)
[error] 40-40:
subprocesscall: check for execution of untrusted input(S603)
[error] 41-41: Starting a process with a partial executable path
(S607)
[error] 45-45:
subprocesscall: check for execution of untrusted input(S603)
[error] 46-46: Starting a process with a partial executable path
(S607)
🤖 Prompt for AI Agents