656dc88d76
test / run tests/run_tests.py (pull_request) Successful in 14s
resolve_env_into(...) becomes resolve_env(manifest, agent) -> ResolvedEnv (forwarded names + literals). The docker backend now owns env-file / argv serialization and the --env-file newline check. Also drops stray Docker references from manifest.py, pipelock.py, util.py, and trims the duplicated command list from cli.py's docstring (usage() in claude_bottle/cli/__init__.py is now the only listing).
32 lines
953 B
Python
32 lines
953 B
Python
"""Cross-cutting utility helpers used by multiple modules.
|
|
|
|
Top-level (i.e. backend-agnostic) — backend-specific helpers live one
|
|
level deeper, under their backend package."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import os
|
|
import re
|
|
|
|
|
|
def expand_tilde(path: str) -> str:
|
|
"""Expand a leading '~' to $HOME. Leaves paths without a leading
|
|
tilde unchanged. Falls back to the empty string if $HOME is unset
|
|
(callers should already have checked HOME if they care)."""
|
|
if path.startswith("~"):
|
|
home = os.environ.get("HOME", "")
|
|
return home + path[1:]
|
|
return path
|
|
|
|
|
|
_IPV4_RE = re.compile(r"^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$")
|
|
|
|
|
|
def is_ipv4_literal(s: str) -> bool:
|
|
"""True iff `s` looks like a dotted-quad IPv4 literal. Does not
|
|
validate octet ranges; consumers that care about that should run
|
|
a stricter check. Empty input returns False."""
|
|
if not s:
|
|
return False
|
|
return bool(_IPV4_RE.match(s))
|