Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ source = "vcs"

[tool.pixi.project]
channels = ["conda-forge", "bioconda"]
platforms = ["linux-64", "osx-arm64"]
platforms = ["linux-64", "osx-arm64", "osx-64"]

[tool.pixi.dependencies]
xrootd = ">=5.7.3,<6"
Expand Down
19 changes: 14 additions & 5 deletions snakemake_storage_plugin_xrootd/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import os
import re
from typing import Any, Iterable, Optional, List, Type
import importlib

from reretry import retry

Expand Down Expand Up @@ -88,9 +89,9 @@ class StorageProviderSettings(StorageProviderSettingsBase):
default=None,
metadata={
"help": (
"A Python expression (given as str) to decorate the URL (which is "
"available as variable `url` in the expression) e.g. to decorate it "
"with an auth token."
"Entry point to a function that expects a single string"
"argument (URL) and returns the decorated URL as a string,"
"e.g. `url_decorator='apd.snakemake:url_decorator'`."
),
"env_var": False,
"required": False,
Expand Down Expand Up @@ -129,10 +130,18 @@ def __post_init__(self):
3031,
3032,
]
self.dec_func = None
if self.settings.url_decorator is not None:
self.dec_func = self.load_decorator()

def load_decorator(self):
module_name, func_name = self.settings.url_decorator.split(":")
module = importlib.import_module(module_name)
return getattr(module, func_name)

def url_decorator(self, url: str) -> str:
if self.settings.url_decorator is not None:
return eval(self.settings.url_decorator, {"url": url})
if self.dec_func is not None:
return self.dec_func(url)
return url

def _check_status(self, status: XRootDStatus, error_preamble: str):
Expand Down
3 changes: 3 additions & 0 deletions tests/test_decorators.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# decorator must be a string with an importable function so put one here
def add_decorator(url: str) -> str:
return url + "?authz=anonymous"
2 changes: 1 addition & 1 deletion tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,5 @@ def get_storage_provider_settings(self) -> Optional[StorageProviderSettingsBase]
return StorageProviderSettings(
host="localhost",
port=XROOTD_TEST_PORT,
url_decorator="url + '?authz=anonymous'",
url_decorator="test_decorators:add_decorator",
)