From 65607764cdb184cf483e82fccaf2a8eaf80efbe9 Mon Sep 17 00:00:00 2001 From: Jeff Tratner Date: Thu, 6 Jan 2022 22:32:37 -0800 Subject: [PATCH 1/5] Guard dxpy imports so dnanexus can actually be optional dxpy pulls in a wide array of (often legacy) packages, skipping the import means we only need to pull it in as necessary which hopefully makes library more useful to others. --- stor/utils.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/stor/utils.py b/stor/utils.py index 01a6f073..d6a3bb46 100644 --- a/stor/utils.py +++ b/stor/utils.py @@ -8,9 +8,6 @@ from subprocess import check_call import tempfile -from dxpy.bindings import verify_string_dxid -from dxpy.exceptions import DXError - from stor import exceptions logger = logging.getLogger(__name__) @@ -257,6 +254,9 @@ def is_valid_dxid(dxid, expected_classes): Returns bool: Whether given dxid is a valid path of one of expected_classes """ + from dxpy.bindings import verify_string_dxid + from dxpy.exceptions import DXError + try: return verify_string_dxid(dxid, expected_classes) is None except DXError: From f83718f8dd3de4d7fac85a9c3763495e46082d77 Mon Sep 17 00:00:00 2001 From: Jeff Tratner Date: Thu, 6 Jan 2022 22:40:57 -0800 Subject: [PATCH 2/5] Guard more imports --- docs/release_notes.rst | 5 +++++ pyproject.toml | 2 +- stor/obs.py | 19 +++++++++++++++---- 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/docs/release_notes.rst b/docs/release_notes.rst index 987cda8f..19e8ab65 100644 --- a/docs/release_notes.rst +++ b/docs/release_notes.rst @@ -1,6 +1,11 @@ Release Notes ============= +v4.0.3 +------ +* Guard dxpy imports in utils so you can use stor without dxpy installed. + + v4.0.2 ------ * fix DeprecationWarning (#140) diff --git a/pyproject.toml b/pyproject.toml index 6a22f0ca..f57e22cc 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "stor" -version = "4.0.2" +version = "4.0.3" description = "Cross-compatible API for accessing Posix and OBS storage systems" authors = ["Counsyl Inc. "] license = "MIT" diff --git a/stor/obs.py b/stor/obs.py index a071f4d8..b9622d38 100644 --- a/stor/obs.py +++ b/stor/obs.py @@ -3,10 +3,6 @@ import posixpath import sys -import dxpy -from swiftclient.service import SwiftError -from swiftclient.service import SwiftUploadObject - from stor.base import Path from stor.posix import PosixPath from stor import utils @@ -28,6 +24,17 @@ def wrapper(self, *args, **kwargs): return wrapper +try: + from swiftclient.service import SwiftUploadObject +except ImportError: + class SwiftUploadObject(object): + """Give 90% of the utility of SwiftUploadObject class without swiftclient!""" + def __init__(self, source, object_name=None, options=None): + self.source = source + self.object_name = object_name + self.options = options + + class OBSUploadObject(SwiftUploadObject): """ An upload object similar to swiftclient's SwiftUploadObject that allows the user @@ -41,6 +48,8 @@ def __init__(self, source, object_name, options=None): source (str): A path that specifies a source file. dest (str): A path that specifies a destination file name (full key) """ + from swiftclient.service import SwiftError + try: super(OBSUploadObject, self).__init__(source, object_name=object_name, options=options) except SwiftError as exc: @@ -452,6 +461,8 @@ def close(self): self.closed = True def _wait_on_close(self): + import dxpy + if isinstance(self._path, stor.dx.DXPath): wait_on_close = stor.settings.get()['dx']['wait_on_close'] if wait_on_close: From 2a31c3059a2228afa495e6e250e823ec7c74d540 Mon Sep 17 00:00:00 2001 From: Jeff Tratner Date: Thu, 6 Jan 2022 22:46:14 -0800 Subject: [PATCH 3/5] Hardcode drives so imports work --- stor/utils.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/stor/utils.py b/stor/utils.py index d6a3bb46..2ef4de8f 100644 --- a/stor/utils.py +++ b/stor/utils.py @@ -187,8 +187,7 @@ def is_swift_path(p): Returns: bool: True if p is a Swift path, False otherwise. """ - from stor.swift import SwiftPath - return p.startswith(SwiftPath.drive) + return p.startswith('swift://') def is_filesystem_path(p): @@ -214,8 +213,7 @@ def is_s3_path(p): Returns bool: True if p is a S3 path, False otherwise. """ - from stor.s3 import S3Path - return p.startswith(S3Path.drive) + return p.startswith('s3://') def is_obs_path(p): @@ -241,8 +239,7 @@ def is_dx_path(p): Returns bool: True if p is a DX path, False otherwise. """ - from stor.dx import DXPath - return p.startswith(DXPath.drive) + return p.startswith('dx://') def is_valid_dxid(dxid, expected_classes): From 932d85a6007923eec618c38291e1d2d87c298769 Mon Sep 17 00:00:00 2001 From: Jeff Tratner Date: Thu, 6 Jan 2022 22:48:24 -0800 Subject: [PATCH 4/5] Skip covering importerror hack --- stor/obs.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stor/obs.py b/stor/obs.py index b9622d38..7c30f6a8 100644 --- a/stor/obs.py +++ b/stor/obs.py @@ -26,7 +26,7 @@ def wrapper(self, *args, **kwargs): try: from swiftclient.service import SwiftUploadObject -except ImportError: +except ImportError: # pragma: no cover class SwiftUploadObject(object): """Give 90% of the utility of SwiftUploadObject class without swiftclient!""" def __init__(self, source, object_name=None, options=None): From fc342a121c8d4c1a4a580dcde92f310091beac59 Mon Sep 17 00:00:00 2001 From: Jeff Tratner Date: Tue, 23 Apr 2024 13:21:32 -0700 Subject: [PATCH 5/5] Update release_notes.rst --- docs/release_notes.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/release_notes.rst b/docs/release_notes.rst index 96f21fb7..8ad90cb5 100644 --- a/docs/release_notes.rst +++ b/docs/release_notes.rst @@ -3,7 +3,7 @@ Release Notes v4.2.0 ------ -* Guard dxpy imports in utils so you can use stor without either dxpy or swift installed. +* Guard dxpy imports in utils so you can use stor without either dxpy or swift installed. (#143) v4.1.0 ------