Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
28 changed files
with
591 additions
and
419 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ select = | |
|
||
exclude = | ||
.git, | ||
.venv, | ||
__pycache__, | ||
build, | ||
dist, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,17 @@ | ||
""" | ||
Exception classes for internal use. | ||
""" | ||
from textwrap import dedent | ||
|
||
|
||
class NextstrainCliError(Exception): | ||
"""Exception base class for all custom :mod:`nextstrain.cli` exceptions.""" | ||
pass | ||
|
||
class UserError(NextstrainCliError): | ||
def __init__(self, message, *args, **kwargs): | ||
super().__init__("Error: " + message, *args, **kwargs) | ||
def __init__(self, message): | ||
# Remove leading newlines, trailing whitespace, and then indentation | ||
# to better support nicely-formatted """multi-line strings""". | ||
formatted_message = dedent(message.lstrip("\n").rstrip()) | ||
|
||
super().__init__("Error: " + formatted_message) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
""" | ||
Remote destinations and sources for Nextstrain datasets and narratives. | ||
""" | ||
|
||
from pathlib import Path | ||
from typing import cast, Dict, Iterable, List, Tuple, TYPE_CHECKING | ||
from urllib.parse import urlparse, ParseResult | ||
from ..errors import UserError | ||
from ..types import RemoteModule | ||
from . import s3 as __s3 | ||
|
||
|
||
# While PEP-0544 allows for modules to serve as implementations of Protocols¹, | ||
# Mypy doesn't currently support it². Pyright does³, however, so we tell Mypy | ||
# to "trust us", but let Pyright actually check our work. Mypy considers the | ||
# MYPY variable to always be True when evaluating the code, regardless of the | ||
# assignment below. | ||
# | ||
# This bit of type checking chicanery is not ideal, but the benefit of having | ||
# our module interfaces actually checked by Pyright is worth it. In the | ||
# future, we should maybe ditch Mypy in favor of Pyright alone, but I didn't | ||
# want to put in the due diligence for a full switchover right now. | ||
# | ||
# -trs, 12 August 2021 | ||
# | ||
# ¹ https://www.python.org/dev/peps/pep-0544/#modules-as-implementations-of-protocols | ||
# ² https://github.com/python/mypy/issues/5018 | ||
# ³ https://github.com/microsoft/pyright/issues/1341 | ||
# | ||
MYPY = False | ||
if TYPE_CHECKING and MYPY: | ||
s3 = cast(RemoteModule, __s3) | ||
else: | ||
s3 = __s3 | ||
|
||
|
||
SUPPORTED_SCHEMES: Dict[str, RemoteModule] = { | ||
"s3": s3, | ||
} | ||
|
||
|
||
def parse_remote_path(path: str) -> Tuple[RemoteModule, ParseResult]: | ||
url = urlparse(path) | ||
|
||
if url.scheme not in SUPPORTED_SCHEMES: | ||
raise UserError(f""" | ||
Unsupported remote scheme {url.scheme}:// | ||
Supported schemes are: {", ".join(SUPPORTED_SCHEMES)} | ||
""") | ||
|
||
remote = SUPPORTED_SCHEMES[url.scheme] | ||
|
||
return remote, url |
Oops, something went wrong.