diff --git a/hud/cli/init.py b/hud/cli/init.py index a665ccada..8647ed9a1 100644 --- a/hud/cli/init.py +++ b/hud/cli/init.py @@ -21,17 +21,12 @@ import typer from hud.utils.hud_console import HUDConsole +from hud.utils.naming import normalize_environment_name from .presets import ENVIRONMENT_PRESETS, PRESETS_BY_ID, EnvironmentPreset, materialize_preset from .templates import DOCKERFILE_HUD, ENV_PY, PYPROJECT_TOML, TASKS_PY -def _python_name(name: str) -> str: - """Normalize a package name into a Python-identifier-ish env name.""" - name = name.replace("-", "_").replace(" ", "_") - return "".join(c if c.isalnum() or c == "_" else "_" for c in name) - - def _resolve_preset(preset: str | None, hud_console: HUDConsole) -> EnvironmentPreset | None: """Pick the starter: an explicit ``--preset`` id, an interactive choice, or ``None`` when there's no TTY to prompt. @@ -157,7 +152,7 @@ def init_command( raise typer.Exit(1) from exc hud_console.status_item(f"{chosen.owner}/{chosen.repo}", "✓") else: - _write_local_scaffold(target, _python_name(target.name), hud_console) + _write_local_scaffold(target, normalize_environment_name(target.name), hud_console) hud_console.section_title("Next Steps") hud_console.info("") diff --git a/hud/cli/tests/test_init.py b/hud/cli/tests/test_init.py index 1e4f8710e..27b60a44c 100644 --- a/hud/cli/tests/test_init.py +++ b/hud/cli/tests/test_init.py @@ -40,7 +40,7 @@ def test_init_scaffolds_a_runnable_package(tmp_path: Path) -> None: } env_py = (target / "env.py").read_text() - assert 'Environment(name="my_cool_env")' in env_py + assert 'Environment(name="my-cool-env")' in env_py assert (target / "tasks.py").read_text().startswith('"""') assert 'name = "my-cool-env"' in (target / "pyproject.toml").read_text()