From c613ed217f1dfb16fc63fa7b06af4ddf4f3dd0b8 Mon Sep 17 00:00:00 2001 From: "Dr. K. D. Murray" <1560490+kdm9@users.noreply.github.com> Date: Thu, 1 Sep 2022 14:04:54 +0200 Subject: [PATCH] fix: catch errors in remote.AUTO provider list (#1834) * remote: catch errors in AUTO provider list The AUTO remote imports and initialises all remote providers, however some remote providers assume they will only be imported or instantiated if their dependencies and/or configuration is set within the environment. This leads to a situation where *all* remote dependencies and *all* remote configuration must be installed/configured before using the AUTO provider. This patch avoids this issue by skipping remote providers that raise exceptions when either imported or instantiated. * tests: add tests of snakemake.remote.AUTO --- snakemake/remote/__init__.py | 12 ++++++++---- tests/test_remote_auto/Snakefile | 10 ++++++++++ tests/test_remote_auto/expected-results/logo.png | Bin 0 -> 3210 bytes 3 files changed, 18 insertions(+), 4 deletions(-) create mode 100644 tests/test_remote_auto/Snakefile create mode 100644 tests/test_remote_auto/expected-results/logo.png diff --git a/snakemake/remote/__init__.py b/snakemake/remote/__init__.py index 19a4bf7f5..b3ba59e3e 100644 --- a/snakemake/remote/__init__.py +++ b/snakemake/remote/__init__.py @@ -471,10 +471,14 @@ def protocol_mapping(self): # assemble scheme mapping protocol_dict = {} for Provider in provider_list: - for protocol in Provider().available_protocols: - protocol_short = protocol[:-3] # remove "://" suffix - protocol_dict[protocol_short] = Provider - + try: + for protocol in Provider().available_protocols: + protocol_short = protocol[:-3] # remove "://" suffix + protocol_dict[protocol_short] = Provider + except Exception as e: + # If for any reason Provider() fails (e.g. missing python + # packages or config env vars), skip this provider. + logger.debug(f"Instantiating {Provider.__class__.__name__} failed: {e}") return protocol_dict def remote(self, value, *args, provider_kws=None, **kwargs): diff --git a/tests/test_remote_auto/Snakefile b/tests/test_remote_auto/Snakefile new file mode 100644 index 000000000..212206946 --- /dev/null +++ b/tests/test_remote_auto/Snakefile @@ -0,0 +1,10 @@ +#import re, os, sys +shell.executable("bash") + +from snakemake.remote import AUTO + +rule all: + input: + AUTO.remote("https://github.com/snakemake/snakemake/raw/main/images/logo.png") + run: + shell("cp {input} ./") diff --git a/tests/test_remote_auto/expected-results/logo.png b/tests/test_remote_auto/expected-results/logo.png new file mode 100644 index 0000000000000000000000000000000000000000..90388b4fb54b144db6065f849adb654ec4007e68 GIT binary patch literal 3210 zcmbtX`8U*U8~=XCFk@@1;jxSCyC|kHX;jEojGeI+k0sfsAtPnTAR|IyD#=b0Nwz6Z zljV^$+lYAz*%Kmb@4WAM|A66vmTf%_TmV5=Mj0T$*wf zprI8}YQblL4oT>vR5+3KP_M*4yI=)e_38yyaM> z$jB>9tW3l!X%V0&oiH~AOR=+M9snb+i5^4D7q#ApI%_EW{^?Y?F77+UTLoNkFp#J3 zD6AtA8q{nE-q=tUD)^1s|YcGo; zrtFL4S+9zo`zql3_rRyhF~e_BJ8I^dZuR+BbcRWIVE}r%{0Rlfhah#eBaNAH8fk{RA?u|y0~sL z84wKET>F+TVWAtp%b`RNW4+efvK*w%czBHDr66y8{^aExXA94W0Y$ETd7oPx=ZSgc zV9-8DX{0`}R=;EPu-30uIEz#{CYtq-SgbnEw9giU{{vSlDWV%Y8F+R^MmY40$VC27VIcsMIXZhx~@FMxH*EkJsYohda=01xq4jxqqH{JPb zFyP_`6zmIUEt^9ZkA0ubU`Q*3r;&UN5IU**5wvRtAky}*X(FcccKCaS+?WN_YxjWp04Z*4-zTzl7+Z<(uyxr*-<=)?fW_{upg}qfFW= zhGT+6i%C}LcVVkLgm^k$w1U#Pj?QH;(V-RcNyDCqcp>`TB6INXr zkTUcO2704t>O7=I1}D3D`J9;%=qihA$%IfDS;R`NogbP+?quG`CjsGIW8;V+0L!BJaBK8)PHJJ2IHz6z@NsGo z6c?0cya2{=Q{7AwO~ekgwQsKjQBq$ghEZtkx~H{fY?(9_*mR6chDpa0Z45!y3kkS9 z(RkAIVjKdu@x((Os7Ba50O}iceni&atw!_*B3L0>baP+=TlWTv+f!V6D$&0MMSnX@ zXEW%!ATc_rq6okqW%^|!#LA`l8k!0_G(A*z?Ojh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