-
Notifications
You must be signed in to change notification settings - Fork 692
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
### Description Allow used to pass in a reference to a custom defined stager via the CLI. Checks are run on the instance passed in to be a subclass of the UploadStager interface.
- Loading branch information
Showing
5 changed files
with
98 additions
and
4 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
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 +1 @@ | ||
__version__ = "0.14.10-dev7" # pragma: no cover | ||
__version__ = "0.14.10-dev8" # pragma: no cover |
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 |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import importlib | ||
from typing import Any | ||
|
||
|
||
class ImportFromStringError(Exception): | ||
pass | ||
|
||
|
||
def import_from_string(import_str: Any) -> Any: | ||
if not isinstance(import_str, str): | ||
return import_str | ||
|
||
module_str, _, attrs_str = import_str.partition(":") | ||
if not module_str or not attrs_str: | ||
message = 'Import string "{import_str}" must be in format "<module>:<attribute>".' | ||
raise ImportFromStringError(message.format(import_str=import_str)) | ||
|
||
try: | ||
module = importlib.import_module(module_str) | ||
except ModuleNotFoundError as exc: | ||
if exc.name != module_str: | ||
raise exc from None | ||
message = 'Could not import module "{module_str}".' | ||
raise ImportFromStringError(message.format(module_str=module_str)) | ||
|
||
instance = module | ||
try: | ||
for attr_str in attrs_str.split("."): | ||
instance = getattr(instance, attr_str) | ||
except AttributeError: | ||
message = 'Attribute "{attrs_str}" not found in module "{module_str}".' | ||
raise ImportFromStringError(message.format(attrs_str=attrs_str, module_str=module_str)) | ||
|
||
return instance |