You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hamilton.apache.org by sk...@apache.org on 2026/03/06 06:08:42 UTC
(hamilton) 23/39: Use uv run python for consistent environment in UI scripts
This is an automated email from the ASF dual-hosted git repository.
skrawcz pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/hamilton.git
commit ee3fff34f1ee5600798f46ee19a32ad99c3f5d16
Author: Stefan Krawczyk <st...@cs.stanford.edu>
AuthorDate: Tue Feb 24 17:36:26 2026 -0800
Use uv run python for consistent environment in UI scripts
Replaces all python3 invocations with 'uv run python' in:
- ui/admin.py: build and publish commands
- ui/backup_hamilton_data.sh: JSON validation and record counting
- ui/restore_hamilton_data.sh: JSON validation and record counting
- ui/migrate_postgres_simple.sh: record counting
Benefits:
- Ensures scripts use project's managed Python environment
- Consistent with ui/backend/server/entrypoint.sh pattern
- Makes it easy to recreate environment: uv handles dependencies
- Uses Python version specified in pyproject.toml (>=3.10)
This aligns with the project's use of uv for dependency management
(uv.lock at repo root) and ensures all scripts work with the same
Python environment.
---
ui/admin.py | 6 ++++--
ui/backup_hamilton_data.sh | 6 +++---
ui/migrate_postgres_simple.sh | 2 +-
ui/restore_hamilton_data.sh | 6 +++---
4 files changed, 11 insertions(+), 9 deletions(-)
diff --git a/ui/admin.py b/ui/admin.py
index fc9e1583..31c54995 100644
--- a/ui/admin.py
+++ b/ui/admin.py
@@ -156,9 +156,11 @@ def build_and_publish(prod: bool, no_wipe_dist: bool):
if not no_wipe_dist:
logger.info("Wiping dist/ directory for a clean publish.")
shutil.rmtree("dist", ignore_errors=True)
- _command("python3 -m build", capture_output=False)
+ _command("uv run python -m build", capture_output=False)
repository = "pypi" if prod else "testpypi"
- _command(f"python3 -m twine upload --repository {repository} dist/*", capture_output=False)
+ _command(
+ f"uv run python -m twine upload --repository {repository} dist/*", capture_output=False
+ )
logger.info(f"Published to {repository}! 🎉")
diff --git a/ui/backup_hamilton_data.sh b/ui/backup_hamilton_data.sh
index 87e601e3..b94e8469 100755
--- a/ui/backup_hamilton_data.sh
+++ b/ui/backup_hamilton_data.sh
@@ -90,13 +90,13 @@ if [ ! -s "$BACKUP_FILE" ]; then
fi
# Check if it's valid JSON
-if ! python3 -m json.tool "$BACKUP_FILE" > /dev/null 2>&1; then
+if ! uv run python -m json.tool "$BACKUP_FILE" > /dev/null 2>&1; then
echo "Error: Backup file contains invalid JSON"
exit 1
fi
# Count records
-RECORD_COUNT=$(python3 -c "import json; print(len(json.load(open('$BACKUP_FILE'))))")
+RECORD_COUNT=$(uv run python -c "import json; print(len(json.load(open('$BACKUP_FILE'))))")
FILE_SIZE=$(du -h "$BACKUP_FILE" | cut -f1)
echo "✓ Backup complete"
@@ -108,7 +108,7 @@ echo ""
# Show breakdown by model
echo "Records by model:"
-python3 -c "
+uv run python -c "
import json
from collections import Counter
diff --git a/ui/migrate_postgres_simple.sh b/ui/migrate_postgres_simple.sh
index 4acd60c5..8e331abd 100755
--- a/ui/migrate_postgres_simple.sh
+++ b/ui/migrate_postgres_simple.sh
@@ -93,7 +93,7 @@ if [ ! -s "$BACKUP_FILE" ]; then
exit 1
fi
-RECORD_COUNT=$(python3 -c "import json; print(len(json.load(open('$BACKUP_FILE'))))")
+RECORD_COUNT=$(uv run python -c "import json; print(len(json.load(open('$BACKUP_FILE'))))")
if [ "$RECORD_COUNT" -eq 0 ]; then
echo "Warning: Backup contains 0 records"
echo "This is OK if you have no data yet, but unexpected if you've been using Hamilton UI"
diff --git a/ui/restore_hamilton_data.sh b/ui/restore_hamilton_data.sh
index dd045c4a..1045a781 100755
--- a/ui/restore_hamilton_data.sh
+++ b/ui/restore_hamilton_data.sh
@@ -44,12 +44,12 @@ echo ""
# Validate JSON
echo "Validating backup file..."
-if ! python3 -m json.tool "$BACKUP_FILE" > /dev/null 2>&1; then
+if ! uv run python -m json.tool "$BACKUP_FILE" > /dev/null 2>&1; then
echo "Error: Backup file contains invalid JSON"
exit 1
fi
-RECORD_COUNT=$(python3 -c "import json; print(len(json.load(open('$BACKUP_FILE'))))")
+RECORD_COUNT=$(uv run python -c "import json; print(len(json.load(open('$BACKUP_FILE'))))")
echo "✓ Found $RECORD_COUNT records"
echo ""
@@ -165,7 +165,7 @@ echo " Templates: $ADDED_TEMPLATES (total: $POST_TEMPLATES)"
echo ""
# Sanity check - if we expected to add data but nothing changed
-EXPECTED_RECORDS=$(python3 -c "
+EXPECTED_RECORDS=$(uv run python -c "
import json
data = json.load(open('$BACKUP_FILE'))
models = [item['model'] for item in data]