From 922f5407257021865ff00fdf9129f404975197cc Mon Sep 17 00:00:00 2001 From: Paul Gierz Date: Wed, 27 Aug 2025 15:52:47 +0200 Subject: [PATCH 1/2] --wip-- [skip ci] --- snakedeploy/deploy.py | 5 ++++- snakedeploy/providers.py | 20 ++++++++++++++++++-- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/snakedeploy/deploy.py b/snakedeploy/deploy.py index 636ac9d..3bb7c47 100644 --- a/snakedeploy/deploy.py +++ b/snakedeploy/deploy.py @@ -21,6 +21,7 @@ def __init__( tag: Optional[str] = None, branch: Optional[str] = None, force=False, + host: Optional[str] = None, ): self.provider = get_provider(source) self.env = Environment(loader=PackageLoader("snakedeploy")) @@ -29,6 +30,7 @@ def __init__( self._cloned = None self.tag = tag self.branch = branch + self.host = host def __enter__(self): return self @@ -227,7 +229,7 @@ def deploy_snakefile(self, tmpdir: str, name: str): module_deployment = template.render( name=name, snakefile=self.provider.get_source_file_declaration( - snakefile, self.tag, self.branch + snakefile, self.tag, self.branch, self.host ), repo=self.provider.source_url, config=config, @@ -253,6 +255,7 @@ def deploy( branch: Optional[str], dest_path: Path, force=False, + host: Optional[str] = None, ): """ Deploy a given workflow to the local machine, using the Snakemake module system. diff --git a/snakedeploy/providers.py b/snakedeploy/providers.py index 8adc452..55d4b14 100644 --- a/snakedeploy/providers.py +++ b/snakedeploy/providers.py @@ -73,7 +73,9 @@ def get_raw_file(self, path: str, tag: str): ) return f"{self.source_url}/{path}" - def get_source_file_declaration(self, path: str, tag: str, branch: str): + def get_source_file_declaration( + self, path: str, tag: str, branch: str, host: Optional[str] = None + ): relative_path = path.replace(self.source_url, "").strip(os.sep) return f'"{relative_path}"' @@ -105,7 +107,9 @@ def checkout(self, path: str, ref: str): def get_raw_file(self, path: str, tag: str): return f"{self.source_url}/raw/{tag}/{path}" - def get_source_file_declaration(self, path: str, tag: str, branch: str): + def get_source_file_declaration( + self, path: str, tag: str, branch: str, host: Optional[str] = None + ): owner_repo = "/".join(self.source_url.split("/")[-2:]) if not (tag or branch): raise UserError("Either tag or branch has to be specified for deployment.") @@ -117,5 +121,17 @@ class Gitlab(Github): def get_raw_file(self, path: str, tag: str): return f"{self.source_url}/-/raw/{tag}/{path}" + def get_source_file_declaration( + self, path: str, tag: str, branch: str, host: Optional[str] = None + ): + owner_repo = "/".join(self.source_url.split("/")[-2:]) + url_host = self.source_url.split("/")[2] + breakpoint() + if not (tag or branch): + raise UserError("Either tag or branch has to be specified for deployment.") + ref_arg = f'tag="{tag}"' if tag is not None else f'branch="{branch}"' + host_arg = f'host="{host}"' if host is not None else "" + return f'{self.name}("{owner_repo}", path="{path}", {ref_arg}, {host_arg})' + PROVIDERS = [Github, Gitlab, Local] From e85658924eada90f906fdfb3614352741b02039a Mon Sep 17 00:00:00 2001 From: Paul Gierz Date: Wed, 27 Aug 2025 16:14:44 +0200 Subject: [PATCH 2/2] allows for host customization with gitlab provider --- snakedeploy/providers.py | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/snakedeploy/providers.py b/snakedeploy/providers.py index 55d4b14..a3f07d1 100644 --- a/snakedeploy/providers.py +++ b/snakedeploy/providers.py @@ -1,9 +1,11 @@ -from abc import abstractmethod, ABC -from shutil import copytree +import os import shutil -from snakedeploy.exceptions import UserError import subprocess as sp -import os +from abc import ABC, abstractmethod +from shutil import copytree +from typing import Optional + +from snakedeploy.exceptions import UserError def get_provider(source_url): @@ -31,16 +33,20 @@ def __init__(self, source_url): @classmethod @abstractmethod - def matches(cls, source_url: str): ... + def matches(cls, source_url: str): + ... @abstractmethod - def clone(self, path: str): ... + def clone(self, path: str): + ... @abstractmethod - def checkout(self, path: str, ref: str): ... + def checkout(self, path: str, ref: str): + ... @abstractmethod - def get_raw_file(self, path: str, tag: str): ... + def get_raw_file(self, path: str, tag: str): + ... def get_repo_name(self): return self.source_url.split("/")[-1] @@ -126,7 +132,8 @@ def get_source_file_declaration( ): owner_repo = "/".join(self.source_url.split("/")[-2:]) url_host = self.source_url.split("/")[2] - breakpoint() + if host is None and url_host != "gitlab.com": + host = url_host if not (tag or branch): raise UserError("Either tag or branch has to be specified for deployment.") ref_arg = f'tag="{tag}"' if tag is not None else f'branch="{branch}"'