-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12500 from nuwang/papercut_file_sources
File sources for gdrive, gcs, onedata, basespace
- Loading branch information
Showing
20 changed files
with
315 additions
and
81 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
try: | ||
from fs_basespace import BASESPACEFS | ||
except ImportError: | ||
BASESPACEFS = None | ||
|
||
from ._pyfilesystem2 import PyFilesystem2FilesSource | ||
|
||
|
||
class BaseSpaceFilesSource(PyFilesystem2FilesSource): | ||
plugin_type = 'basespace' | ||
required_module = BASESPACEFS | ||
required_package = "fs-basespace" | ||
|
||
def _open_fs(self, user_context): | ||
props = self._serialization_props(user_context) | ||
handle = BASESPACEFS(**props) | ||
return handle | ||
|
||
|
||
__all__ = ('BaseSpaceFilesSource',) |
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,30 @@ | ||
try: | ||
from fs_gcsfs import GCSFS | ||
from google.cloud.storage import Client | ||
from google.oauth2.credentials import Credentials | ||
except ImportError: | ||
GCSFS = None | ||
|
||
from ._pyfilesystem2 import PyFilesystem2FilesSource | ||
|
||
|
||
class GoogleCloudStorageFilesSource(PyFilesystem2FilesSource): | ||
plugin_type = 'googlecloudstorage' | ||
required_module = GCSFS | ||
required_package = "fs-gcsfs" | ||
|
||
def _open_fs(self, user_context): | ||
props = self._serialization_props(user_context) | ||
bucket_name = props.pop('bucket_name', None) | ||
root_path = props.pop('root_path', None) | ||
project = props.pop('project', None) | ||
args = {} | ||
if props.get('anonymous'): | ||
args['client'] = Client.create_anonymous_client() | ||
elif props.get('token'): | ||
args['client'] = Client(project=project, credentials=Credentials(**props)) | ||
handle = GCSFS(bucket_name, root_path=root_path, retry=0, **args) | ||
return handle | ||
|
||
|
||
__all__ = ('GoogleCloudStorageFilesSource',) |
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,22 @@ | ||
try: | ||
from fs.googledrivefs import GoogleDriveFS | ||
from google.oauth2.credentials import Credentials | ||
except ImportError: | ||
GoogleDriveFS = None | ||
|
||
from ._pyfilesystem2 import PyFilesystem2FilesSource | ||
|
||
|
||
class GoogleDriveFilesSource(PyFilesystem2FilesSource): | ||
plugin_type = 'googledrive' | ||
required_module = GoogleDriveFS | ||
required_package = "fs.googledrivefs" | ||
|
||
def _open_fs(self, user_context): | ||
props = self._serialization_props(user_context) | ||
credentials = Credentials(**props) | ||
handle = GoogleDriveFS(credentials) | ||
return handle | ||
|
||
|
||
__all__ = ('GoogleDriveFilesSource',) |
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,20 @@ | ||
try: | ||
from fs.onedatafs import OnedataFS | ||
except ImportError: | ||
OnedataFS = None | ||
|
||
from ._pyfilesystem2 import PyFilesystem2FilesSource | ||
|
||
|
||
class OneDataFilesSource(PyFilesystem2FilesSource): | ||
plugin_type = 'onedata' | ||
required_module = OnedataFS | ||
required_package = "fs-onedatafs" | ||
|
||
def _open_fs(self, user_context): | ||
props = self._serialization_props(user_context) | ||
handle = OnedataFS(**props) | ||
return handle | ||
|
||
|
||
__all__ = ('OneDataFilesSource',) |
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,2 @@ | ||
pytest | ||
fs-gcsfs |
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,7 @@ | ||
- type: basespace | ||
id: test1 | ||
doc: Test access to Illumina BaseSpace | ||
basespace_server: https://api.basespace.illumina.com | ||
client_id: ${user.preferences['basespace|client_id']} | ||
client_secret: ${user.preferences['basespace|client_secret']} | ||
access_token: ${user.preferences['basespace|access_token']} |
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,4 +1,4 @@ | ||
- type: dropbox | ||
id: test1 | ||
doc: Test WebDAV server. | ||
doc: Test access to a dropbox account. | ||
accessToken: ${user.preferences['dropbox|access_token']} |
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,11 @@ | ||
- type: googlecloudstorage | ||
id: test1 | ||
doc: Test access to Google Cloud Storage. | ||
project: ${user.preferences['googlecloudstorage|project']} | ||
bucket_name: 'genomics-public-data' | ||
token_uri: "https://www.googleapis.com/oauth2/v4/token" | ||
client_id: ${user.preferences['googlecloudstorage|client_id']} | ||
client_secret: ${user.preferences['googlecloudstorage|client_secret']} | ||
token: ${user.preferences['googlecloudstorage|access_token']} | ||
refresh_token: ${user.preferences['googlecloudstorage|refresh_token']} | ||
anonymous: true |
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,8 @@ | ||
- type: googledrive | ||
id: test1 | ||
doc: Test access to a Google drive. | ||
token: ${user.preferences['googledrive|access_token']} | ||
refresh_token: ${user.preferences['googledrive|refresh_token']} | ||
token_uri: "https://www.googleapis.com/oauth2/v4/token" | ||
client_id: ${user.preferences['googledrive|client_id']} | ||
client_secret: ${user.preferences['googledrive|client_secret']} |
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,5 @@ | ||
- type: onedata | ||
id: test1 | ||
doc: Test access to a OneData host | ||
provider_host: ${user.preferences['onedata|provider_host']} | ||
access_token: ${user.preferences['onedata|access_token']} |
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,36 @@ | ||
import os | ||
|
||
import pytest | ||
|
||
from ._util import ( | ||
assert_realizes_as, | ||
configured_file_sources, | ||
find, | ||
user_context_fixture, | ||
) | ||
SCRIPT_DIRECTORY = os.path.abspath(os.path.dirname(__file__)) | ||
FILE_SOURCES_CONF = os.path.join(SCRIPT_DIRECTORY, "basespace_file_sources_conf.yml") | ||
|
||
skip_if_no_basespace_access_token = pytest.mark.skipif( | ||
not os.environ.get('GALAXY_TEST_BASESPACE_CLIENT_ID') | ||
or not os.environ.get('GALAXY_TEST_BASESPACE_CLIENT_SECRET') | ||
or not os.environ.get('GALAXY_TEST_BASESPACE_ACCESS_TOKEN') | ||
or not os.environ.get('GALAXY_TEST_BASESPACE_TEST_FILE_PATH'), | ||
reason="GALAXY_TEST_BASESPACE_CLIENT_ID and related vars not set" | ||
) | ||
|
||
|
||
@skip_if_no_basespace_access_token | ||
def test_file_source(): | ||
user_context = user_context_fixture() | ||
file_sources = configured_file_sources(FILE_SOURCES_CONF) | ||
file_source_pair = file_sources.get_file_source_path("gxfiles://test1") | ||
|
||
assert file_source_pair.path == "/" | ||
file_source = file_source_pair.file_source | ||
test_file = os.environ.get('GALAXY_TEST_BASESPACE_TEST_FILE_PATH', "") | ||
res = file_source.list(os.path.dirname(test_file), recursive=False, user_context=user_context) | ||
a_file = find(res, class_="File", name=os.path.basename(test_file)) | ||
assert a_file | ||
|
||
assert_realizes_as(file_sources, a_file['uri'], "a\n", user_context=user_context) |
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,25 @@ | ||
import os | ||
|
||
import pytest | ||
|
||
from ._util import assert_simple_file_realize | ||
|
||
try: | ||
from fs_gcsfs import GCSFS | ||
except ImportError: | ||
GCSFS = None | ||
|
||
SCRIPT_DIRECTORY = os.path.abspath(os.path.dirname(__file__)) | ||
FILE_SOURCES_CONF = os.path.join(SCRIPT_DIRECTORY, "gcsfs_file_sources_conf.yml") | ||
|
||
|
||
skip_if_no_gcsfs_libs = pytest.mark.skipif( | ||
not GCSFS, | ||
reason="Required lib to run gcs file source test: fs_gcsfs is not available" | ||
) | ||
|
||
|
||
@skip_if_no_gcsfs_libs | ||
def test_file_source(): | ||
assert_simple_file_realize(FILE_SOURCES_CONF, recursive=False, filename="README", contents="1000genomes", | ||
contains=True) |
Oops, something went wrong.