Add package installation: pipenv install with wrapped failures
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
"""Create new python projects from the versioned template."""
|
||||
|
||||
import re
|
||||
import subprocess
|
||||
from collections.abc import Sequence
|
||||
from pathlib import Path
|
||||
|
||||
NAME_PATTERN = re.compile(r"^[a-z]+(-[a-z]+)*$")
|
||||
@@ -34,3 +36,13 @@ def parent_dir(explicit: Path | None) -> Path:
|
||||
if not explicit.is_dir():
|
||||
raise ScaffoldError(f"--dir is not an existing directory: {explicit}")
|
||||
return explicit
|
||||
|
||||
|
||||
def install_packages(packages: Sequence[str], cwd: Path) -> None:
|
||||
"""Install runtime *packages* into the project at *cwd* via pipenv."""
|
||||
if not packages:
|
||||
return
|
||||
try:
|
||||
subprocess.run(["pipenv", "install", *packages], cwd=cwd, check=True)
|
||||
except subprocess.CalledProcessError as exc:
|
||||
raise ScaffoldError(f"pipenv install failed with exit code {exc.returncode}") from exc
|
||||
|
||||
Reference in New Issue
Block a user