feature: cli generate uv.lock on new service
This commit is contained in:
@@ -1,4 +1,7 @@
|
||||
import logging
|
||||
import shutil
|
||||
import subprocess
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
import copier
|
||||
@@ -13,6 +16,8 @@ from core.git import (
|
||||
from core.models import MasterHLANames, Service, ServiceRegistry
|
||||
from core.utils import get_git_root
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
REPO_ROOT = get_git_root(__file__)
|
||||
SERVICE_TEMPLATES_DIR = REPO_ROOT / "templates" / "service"
|
||||
SERVICE_DEST_DIR = REPO_ROOT / "services"
|
||||
@@ -54,6 +59,7 @@ class ServiceCreator:
|
||||
ioc_port=self.ioc_port,
|
||||
user=self.user,
|
||||
)
|
||||
self._generate_uv_lock(service=service)
|
||||
registry.write_to_config()
|
||||
hla_names.write_to_config()
|
||||
|
||||
@@ -98,3 +104,33 @@ class ServiceCreator:
|
||||
"user": user,
|
||||
},
|
||||
)
|
||||
|
||||
def _generate_uv_lock(self, service: Service):
|
||||
"""
|
||||
Generates a uv.lock file by running 'uv lock' in the target directory.
|
||||
"""
|
||||
project_path = Path(SERVICE_DEST_DIR / service.dir_name).resolve()
|
||||
logger.info(f"Generating uv.lock inside: {project_path}")
|
||||
|
||||
try:
|
||||
result = subprocess.run(
|
||||
["uv", "lock"],
|
||||
cwd=project_path, # Changes the working directory for the command
|
||||
capture_output=True, # Captures stdout and stderr
|
||||
text=True, # Returns strings instead of raw bytes
|
||||
check=True, # Raises CalledProcessError if the exit code is non-zero
|
||||
)
|
||||
|
||||
logger.info("Success! uv.lock has been generated/updated.")
|
||||
if result.stderr:
|
||||
# uv prints its progress and resolution metrics to stderr
|
||||
logger.warning(result.stderr.strip())
|
||||
|
||||
except FileNotFoundError:
|
||||
logger.error(
|
||||
"The 'uv' command-line tool is not installed or not in your PATH.",
|
||||
)
|
||||
except subprocess.CalledProcessError as e:
|
||||
logger.error("'uv lock' failed to execute successfully.")
|
||||
logger.error(f"Exit Code: {e.returncode}")
|
||||
logger.error(f"Details:\n{e.stderr}")
|
||||
|
||||
Reference in New Issue
Block a user