From a39ac93726494c029d80a39780cc8464c0937b67 Mon Sep 17 00:00:00 2001 From: Chris Jackson Date: Tue, 31 Dec 2024 08:09:13 +0000 Subject: [PATCH] feat: added uv option to create_server_installer.py --- create_server_installer.py | 24 +++++++++++++++++++++++- uv_stub.py | 5 +++++ 2 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 uv_stub.py diff --git a/create_server_installer.py b/create_server_installer.py index 435143b..9199514 100755 --- a/create_server_installer.py +++ b/create_server_installer.py @@ -18,6 +18,9 @@ # Place public keys here ssh_authorized_keys = [] +# Use uv +uv = false + # The format is TOML """.strip() @@ -58,10 +61,24 @@ doas_permission = [] +uv_stub = None +if toml_config.get("uv", False): + uv_stub = pathlib.Path(f"{current_path}/uv_stub.py").read_text("utf-8").strip() + "\n" + + +def copy(src: str, dest: str): + if uv_stub: + src_str = pathlib.Path(src).read_text("utf-8").removeprefix("#!/usr/bin/env python3").strip() + dest_str = f'{uv_stub}{src_str}' + "\n" + pathlib.Path(dest).write_text(dest_str, 'utf-8') + else: + shutil.copy(src, dest) + + for run_deploy_path in pathlib.Path(f"{current_path}/{toml_config['edition']}").glob('*.py'): run_deploy_path = str(run_deploy_path) run_deploy_target_path = f"opt/run-deploy/bin/{os.path.basename(run_deploy_path).removesuffix('.py')}" - shutil.copy(run_deploy_path, run_deploy_target_path) + copy(run_deploy_path, run_deploy_target_path) os.chmod(run_deploy_target_path, 0o700) if run_deploy_target_path.endswith("-cli"): doas_permission.append( @@ -75,6 +92,11 @@ if os.path.exists(f"{current_path}/{toml_config['edition']}/_opt"): shutil.copytree(f"{current_path}/{toml_config['edition']}/_opt", "opt/run-deploy", dirs_exist_ok=True) +if uv_stub: + for python_script in pathlib.Path("opt/run-deploy/script").glob("*.py"): + python_script = str(python_script) + copy(python_script, python_script) + systemd_symlinks = [] systemd_cmd = [] systemd_paths = pathlib.Path("opt/run-deploy/systemd/system").glob("run-deploy-*") diff --git a/uv_stub.py b/uv_stub.py new file mode 100644 index 0000000..797854f --- /dev/null +++ b/uv_stub.py @@ -0,0 +1,5 @@ +#!/usr/bin/env -S uv run --quiet --script +# /// script +# requires-python = ">=3.13" +# dependencies = [] +# /// \ No newline at end of file