Skip to content

Commit

Permalink
fix: catch errors in remote.AUTO provider list (#1834)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
kdm9 committed Sep 1, 2022
1 parent c26c4b6 commit c613ed2
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
12 changes: 8 additions & 4 deletions snakemake/remote/__init__.py
Expand Up @@ -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):
Expand Down
10 changes: 10 additions & 0 deletions 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} ./")
Binary file added tests/test_remote_auto/expected-results/logo.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit c613ed2

Please sign in to comment.