Skip to content

Commit 2ec1b85

Browse files
override exclude-newer-package for groundhog only (#124)
1 parent 7d124c1 commit 2ec1b85

3 files changed

Lines changed: 44 additions & 0 deletions

File tree

src/groundhog_hpc/templates/shell_command.sh.jinja

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,12 @@ mkdir -p "$UV_CACHE_DIR" "$UV_PYTHON_INSTALL_DIR"
3737
{% if log_level %}
3838
# Local override - use value from dispatching environment
3939
export GROUNDHOG_LOG_LEVEL="{{ log_level }}"
40+
export RUST_LOG=uv="${{GROUNDHOG_LOG_LEVEL}}"
4041
{% else %}
4142
{% raw %}
4243
# Respect remote environment if set, otherwise default to WARNING
4344
export GROUNDHOG_LOG_LEVEL="${{GROUNDHOG_LOG_LEVEL:-WARNING}}"
45+
export RUST_LOG=uv="${{GROUNDHOG_LOG_LEVEL:-WARNING}}"
4446
{% endraw %}
4547
{% endif %}
4648

@@ -57,6 +59,7 @@ cat > {{ script_name }}.in << 'PAYLOAD_EOF'
5759
PAYLOAD_EOF
5860

5961
"$UV_BIN" run --with {{ version_spec }} \
62+
--exclude-newer-package groundhog-hpc={{ groundhog_timestamp }} \
6063
{{ runner_name }}.py
6164

6265
echo "__GROUNDHOG_RESULT__"

src/groundhog_hpc/templating.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import logging
1111
import os
1212
import uuid
13+
from datetime import datetime, timezone
1314
from hashlib import sha1
1415
from pathlib import Path
1516

@@ -74,6 +75,10 @@ def template_shell_command(script_path: str, function_name: str, payload: str) -
7475
version_spec = get_groundhog_version_spec()
7576
logger.debug(f"Using groundhog version spec: {version_spec}")
7677

78+
# Generate timestamp for groundhog-hpc exclude-newer override
79+
# This allows groundhog to bypass user's exclude-newer restrictions
80+
groundhog_timestamp = datetime.now(timezone.utc).strftime("%Y-%m-%dT%H:%M:%SZ")
81+
7782
# Load runner template
7883
templates_dir = Path(__file__).parent / "templates"
7984
jinja_env = Environment(loader=FileSystemLoader(templates_dir))
@@ -106,6 +111,7 @@ def template_shell_command(script_path: str, function_name: str, payload: str) -
106111
version_spec=version_spec,
107112
payload=payload,
108113
log_level=local_log_level,
114+
groundhog_timestamp=groundhog_timestamp,
109115
)
110116

111117
logger.debug(f"Generated shell command ({len(shell_command_string)} chars)")

tests/test_templating.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,41 @@ def func2():
342342
# They should have different hashes since content differs
343343
assert command1 != command2
344344

345+
def test_includes_exclude_newer_package_flag(self, tmp_path):
346+
"""Test that shell command always includes --exclude-newer-package for groundhog-hpc.
347+
348+
This prevents user's exclude-newer settings from blocking groundhog installation.
349+
"""
350+
script_path = tmp_path / "script.py"
351+
script_content = """# /// script
352+
# requires-python = ">=3.12"
353+
# dependencies = []
354+
#
355+
# [tool.uv]
356+
# exclude-newer = "2020-01-01T00:00:00Z"
357+
# ///
358+
359+
import groundhog_hpc as hog
360+
361+
@hog.function()
362+
def func():
363+
return 1
364+
"""
365+
script_path.write_text(script_content)
366+
367+
shell_command = template_shell_command(str(script_path), "func", "test_payload")
368+
369+
# Should include the package-specific exclude-newer override
370+
assert "--exclude-newer-package groundhog-hpc=" in shell_command
371+
# Timestamp should be in ISO format (basic validation)
372+
import re
373+
374+
match = re.search(
375+
r"--exclude-newer-package groundhog-hpc=(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z)",
376+
shell_command,
377+
)
378+
assert match, "exclude-newer-package timestamp should be in ISO 8601 format"
379+
345380

346381
class TestDottedQualnames:
347382
"""Test that templating handles dotted qualnames (class methods)."""

0 commit comments

Comments
 (0)