-
Notifications
You must be signed in to change notification settings - Fork 13
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
10 changed files
with
411 additions
and
346 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
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,65 +1,18 @@ | ||
# cgatcore/remote/__init__.py | ||
|
||
import os | ||
import sys | ||
from abc import abstractmethod | ||
|
||
|
||
class AbstractRemoteObject(): | ||
'''This is an abstract class that all RemoteObjects will | ||
inherit from. This is an abstract class to rigidly define | ||
the abstract methods of this RemoteObject class''' | ||
|
||
def __init__(self, *args, **kwargs): | ||
self.args = args | ||
self.kwargs = kwargs | ||
|
||
@abstractmethod | ||
def exists(self): | ||
pass | ||
|
||
@abstractmethod | ||
def download(self): | ||
pass | ||
|
||
@abstractmethod | ||
def upload(self): | ||
pass | ||
|
||
@abstractmethod | ||
def delete_file(self): | ||
pass | ||
|
||
|
||
# Import S3-specific functionality | ||
try: | ||
from .file_handler import ( | ||
s3_transform, | ||
s3_merge, | ||
s3_split, | ||
s3_originate, | ||
s3_follows, | ||
S3Mapper, | ||
s3_aware | ||
) | ||
except ImportError as e: | ||
import warnings | ||
|
||
warnings.warn(f"Failed to import S3 functionality from file_handler: {str(e)}. S3 features will be unavailable.") | ||
|
||
# If the file_handler module is not available, create dummy functions | ||
def dummy_decorator(*args, **kwargs): | ||
def decorator(func): | ||
return func | ||
|
||
return decorator | ||
|
||
s3_transform = s3_merge = s3_split = s3_originate = s3_follows = dummy_decorator | ||
s3_aware = lambda func: func | ||
|
||
class S3Mapper: | ||
def __init__(self): | ||
pass | ||
from .abstract import AbstractRemoteObject | ||
from .file_handler import S3Pipeline, S3Mapper, s3_path_to_local, suffix | ||
|
||
# Create an instance of S3Mapper | ||
s3_mapper = S3Mapper() | ||
|
||
# Conditional import for testing | ||
if os.getenv("PYTEST_CURRENT_TEST"): | ||
from tests.mocks import MockS3RemoteObject | ||
from unittest.mock import patch | ||
with patch("cgatcore.remote.aws.S3RemoteObject", new=MockS3RemoteObject): | ||
s3_mapper = S3Mapper() # Use MockS3RemoteObject during tests | ||
|
||
__all__ = ['S3Pipeline', 'S3Mapper', 's3_path_to_local', 'suffix'] |
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,29 @@ | ||
# cgatcore/remote/abstract.py | ||
|
||
from abc import ABC, abstractmethod | ||
|
||
|
||
class AbstractRemoteObject(ABC): | ||
'''This is an abstract class that all RemoteObjects will | ||
inherit from. This is an abstract class to rigidly define | ||
the abstract methods of this RemoteObject class''' | ||
|
||
def __init__(self, *args, **kwargs): | ||
self.args = args | ||
self.kwargs = kwargs | ||
|
||
@abstractmethod | ||
def exists(self): | ||
pass | ||
|
||
@abstractmethod | ||
def download(self): | ||
pass | ||
|
||
@abstractmethod | ||
def upload(self): | ||
pass | ||
|
||
@abstractmethod | ||
def delete_file(self): | ||
pass |
Oops, something went wrong.