Skip to content

Commit 4eade7f

Browse files
committed
fix: bring back monkeypatching
1 parent f0fb3c9 commit 4eade7f

3 files changed

Lines changed: 42 additions & 1 deletion

File tree

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ dev = [
7171

7272
[tool.basedpyright]
7373
reportImplicitStringConcatenation = false
74-
ignore = ["tests"]
74+
ignore = ["tests", "src/snakemake_storage_plugin_cached_http/monkeypatch.py"]
7575
reportUnusedCallResult = false
7676
reportAny = false
7777
reportMissingTypeStubs = false

src/snakemake_storage_plugin_cached_http/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
from tqdm_loggable.auto import tqdm
3838
from typing_extensions import override
3939

40+
from . import monkeypatch # noqa: F401
4041
from .cache import Cache
4142

4243
logger = get_logger()
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# SPDX-FileCopyrightText: Contributors to PyPSA-Eur <https://github.com/pypsa/pypsa-eur>
2+
#
3+
# SPDX-License-Identifier: MIT
4+
5+
"""
6+
Warn if snakemake-storage-plugin-http is installed and patch it to refuse all URLs.
7+
8+
Since cached-http now accepts all HTTP(S) URLs, having snakemake-storage-plugin-http
9+
installed at the same time causes Snakemake to raise "Multiple suitable storage
10+
providers found". This module detects that situation, warns the user, and patches the
11+
HTTP plugin to refuse every URL so that cached-http wins unconditionally.
12+
"""
13+
14+
import warnings
15+
16+
from snakemake_interface_storage_plugins.storage_provider import (
17+
StorageQueryValidationResult,
18+
)
19+
20+
try:
21+
import snakemake_storage_plugin_http
22+
23+
warnings.warn(
24+
"snakemake-storage-plugin-http is installed alongside "
25+
"snakemake-storage-plugin-cached-http. Because cached-http from v0.5 handles "
26+
"all HTTP(S) URLs, the http plugin has been disabled for this session. "
27+
"Please uninstall snakemake-storage-plugin-http. "
28+
"This compatibility shim will be removed in v0.6.",
29+
FutureWarning,
30+
)
31+
32+
snakemake_storage_plugin_http.StorageProvider.is_valid_query = classmethod(
33+
lambda c, q: StorageQueryValidationResult(
34+
query=q,
35+
valid=False,
36+
reason="Disabled: snakemake-storage-plugin-cached-http handles all HTTP(S) URLs",
37+
)
38+
)
39+
except ImportError:
40+
pass

0 commit comments

Comments
 (0)