mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2026-11-06 19:01:54 +00:00
Refactor scripts/install/lint.sh (~870 LOC bash) into a Python package
under utils/install/. scripts/install/lint.sh becomes a 7-line wrapper
that delegates to `python3 -m utils.install.lint`.
Layout:
- utils/install/{primitives,pip,npm,github_release,system_pkg}.py:
channel-agnostic installers
- utils/install/lint/<tool>.py: one ensure() per tool (actionlint,
shfmt, mbake, ruff, ansible_lint, galaxy_importer, markdownlint_cli2,
eslint, shellcheck, ansible_commands, ansible_collections)
- utils/install/lint/__main__.py: CLI + group dispatch + stamp logic
INFINITO_LINT_RUNNER dispatch:
- New env var (host | docker, default docker), tracked in env/static.env
+ passthrough handler + drift test.
- scripts/install/wrapper.sh routes `make install-lint` to host or
container based on the runner.
- scripts/lint/wrapper.sh already dispatched; container branch now uses
bash (not --login) so /etc/profile does not reset PATH, and forwards
BASH_ENV so the .env keys land in the lint script's env.
Stamp logic:
- Per-interpreter stamp at build/install-lint-<sha256(sys.executable)>.stamp
so host venv and container venv track installs independently despite
bind-mounted build/.
- `--force` drops the stamp; group args bypass the stamp.
Tests + docs:
- 43 unit tests under tests/unit/utils/install/{,lint/} cover primitives,
pip/npm/github_release/system_pkg fallback chains, and the main CLI
(stamp logic, group dispatch, error path).
- utils/install/README.md + utils/install/lint/README.md document the
structure and the per-tool ensure() contract.
- docs/contributing/tools/make.md install-lint row updated to mention
the runner dispatch + per-env stamp + install-lint-force.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
64 lines
1.9 KiB
Python
64 lines
1.9 KiB
Python
"""npm-based installer helpers."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import shutil
|
|
import subprocess
|
|
from pathlib import Path
|
|
|
|
from utils.install.primitives import ensure_dir_on_path, install_with_optional_sudo, log
|
|
|
|
|
|
def ensure_npm_present() -> None:
|
|
if shutil.which("npm") is not None:
|
|
return
|
|
|
|
log("npm missing; attempting Node.js/npm install via system package manager.")
|
|
from utils.install.system_pkg import install_command_via_pkg
|
|
|
|
install_command_via_pkg("npm")
|
|
|
|
if shutil.which("npm") is None:
|
|
raise RuntimeError("npm not found and could not be installed")
|
|
|
|
|
|
def npm_install_global(package: str) -> None:
|
|
ensure_npm_present()
|
|
log(f"Installing '{package}' via npm (global)")
|
|
try:
|
|
install_with_optional_sudo(["npm", "install", "-g", package])
|
|
except subprocess.CalledProcessError:
|
|
pass
|
|
else:
|
|
return
|
|
|
|
prefix = Path("~/.npm-global").expanduser()
|
|
prefix.mkdir(parents=True, exist_ok=True)
|
|
try:
|
|
subprocess.run(
|
|
["npm", "install", "-g", "--prefix", str(prefix), package],
|
|
check=True,
|
|
)
|
|
except subprocess.CalledProcessError as exc:
|
|
raise RuntimeError(
|
|
f"npm install -g {package} failed (both global and --prefix)"
|
|
) from exc
|
|
ensure_dir_on_path(str(prefix / "bin"))
|
|
|
|
|
|
def npm_install_local_in_repo(repo_root: str) -> None:
|
|
ensure_npm_present()
|
|
has_lock = (Path(repo_root) / "package-lock.json").is_file()
|
|
argv = (
|
|
["npm", "ci", "--no-fund", "--no-audit"]
|
|
if has_lock
|
|
else ["npm", "install", "--no-fund", "--no-audit"]
|
|
)
|
|
try:
|
|
subprocess.run(argv, check=True, cwd=repo_root)
|
|
except subprocess.CalledProcessError as exc:
|
|
raise RuntimeError(f"npm install in {repo_root} failed") from exc
|
|
|
|
|
|
__all__ = ["ensure_npm_present", "npm_install_global", "npm_install_local_in_repo"]
|