-
Notifications
You must be signed in to change notification settings - Fork 1.2k
chore: add pre-commit hook to enforce llama_stack.log logger #2868
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -145,6 +145,24 @@ repos: | |
pass_filenames: false | ||
require_serial: true | ||
files: ^.github/workflows/.*$ | ||
- id: check-log-usage | ||
name: Check for proper log usage (use llama_stack.log instead) | ||
entry: bash | ||
language: system | ||
types: [python] | ||
pass_filenames: true | ||
args: | ||
- -c | ||
- | | ||
matches=$(grep -EnH '^[^#]*\b(import logging|from logging\b)' "$@" | grep -v '# allow-direct-logging' || true) | ||
if [ -n "$matches" ]; then | ||
# GitHub Actions annotation format | ||
while IFS=: read -r file line_num rest; do | ||
echo "::error file=$file,line=$line_num::Do not use 'import logging' or 'from logging import' in $file. Use the custom log instead: from llama_stack.log import get_logger; logger = get_logger(). If direct logging is truly needed, add: # allow-direct-logging" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Elbehery Can you please also use If you want to rename all instances from IMO, one should always assess the value of a change to the size of the change, which needs to be in balance. This is not the case here IMO as the value ( But if you detangle both concerns (add a recommit check vs. _rename all There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. thanks so much for your review 🙏🏽 makes perfect sense to me 👍🏽 I actually initally made the I am fine with the renaming, and I can do it in a separate PR as you suggested just could we agree on a name (i.e. thanks in advance There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. raised #3060 👍🏽 |
||
done <<< "$matches" | ||
exit 1 | ||
fi | ||
exit 0 | ||
|
||
ci: | ||
autofix_commit_msg: 🎨 [pre-commit.ci] Auto format from pre-commit.com hooks | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,7 +15,7 @@ | |
|
||
REPO_ROOT = Path(__file__).parent.parent.parent.parent | ||
|
||
logger = get_logger(name=__name__, category="server") | ||
log = get_logger(name=__name__, category="server") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah why this spurious change? please move it back to It is extremely important that you don't add gratuitous changes when making PRs. Stick to the core thesis of the PR. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i am preserving this commit here for your ref. This commit was using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Elbehery let me rephrase myself and be extremely clear. This PR should only have changes which look like this:
There should be no other changes in the PR. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. lgtm 👍🏽 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. raised #3060 👍🏽 |
||
|
||
|
||
class StackRun(Subcommand): | ||
|
@@ -126,7 +126,7 @@ def _run_stack_run_cmd(self, args: argparse.Namespace) -> None: | |
self.parser.error("Config file is required for venv environment") | ||
|
||
if config_file: | ||
logger.info(f"Using run configuration: {config_file}") | ||
log.info(f"Using run configuration: {config_file}") | ||
|
||
try: | ||
config_dict = yaml.safe_load(config_file.read_text()) | ||
|
@@ -145,7 +145,7 @@ def _run_stack_run_cmd(self, args: argparse.Namespace) -> None: | |
# If neither image type nor image name is provided, assume the server should be run directly | ||
# using the current environment packages. | ||
if not image_type and not image_name: | ||
logger.info("No image type or image name provided. Assuming environment packages.") | ||
log.info("No image type or image name provided. Assuming environment packages.") | ||
from llama_stack.core.server.server import main as server_main | ||
|
||
# Build the server args from the current args passed to the CLI | ||
|
@@ -185,11 +185,11 @@ def _run_stack_run_cmd(self, args: argparse.Namespace) -> None: | |
run_command(run_args) | ||
|
||
def _start_ui_development_server(self, stack_server_port: int): | ||
logger.info("Attempting to start UI development server...") | ||
log.info("Attempting to start UI development server...") | ||
# Check if npm is available | ||
npm_check = subprocess.run(["npm", "--version"], capture_output=True, text=True, check=False) | ||
if npm_check.returncode != 0: | ||
logger.warning( | ||
log.warning( | ||
f"'npm' command not found or not executable. UI development server will not be started. Error: {npm_check.stderr}" | ||
) | ||
return | ||
|
@@ -214,13 +214,13 @@ def _start_ui_development_server(self, stack_server_port: int): | |
stderr=stderr_log_file, | ||
env={**os.environ, "NEXT_PUBLIC_LLAMA_STACK_BASE_URL": f"http://localhost:{stack_server_port}"}, | ||
) | ||
logger.info(f"UI development server process started in {ui_dir} with PID {process.pid}.") | ||
logger.info(f"Logs: stdout -> {ui_stdout_log_path}, stderr -> {ui_stderr_log_path}") | ||
logger.info(f"UI will be available at http://localhost:{os.getenv('LLAMA_STACK_UI_PORT', 8322)}") | ||
log.info(f"UI development server process started in {ui_dir} with PID {process.pid}.") | ||
log.info(f"Logs: stdout -> {ui_stdout_log_path}, stderr -> {ui_stderr_log_path}") | ||
log.info(f"UI will be available at http://localhost:{os.getenv('LLAMA_STACK_UI_PORT', 8322)}") | ||
|
||
except FileNotFoundError: | ||
logger.error( | ||
log.error( | ||
"Failed to start UI development server: 'npm' command not found. Make sure npm is installed and in your PATH." | ||
) | ||
except Exception as e: | ||
logger.error(f"Failed to start UI development server in {ui_dir}: {e}") | ||
log.error(f"Failed to start UI development server in {ui_dir}: {e}") |
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.
you could make the regexp more robust by allowing an arbitrary amount of spaces like with
\s+
. Also you might want allow#allow-direct-logging
and# allow-direct-logging
, too (so maybe grep -v -e '#\s*allow-direct-logging')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.
lgtm 👍🏽
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.
raised #3061 👍🏽