-
Notifications
You must be signed in to change notification settings - Fork 1k
File sources for gdrive, gcs, onedata, basespace #12500
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
9bb6ec2
Added google drive file source
nuwang ae8a832
Added unit tests for google drive file source
nuwang 482fb28
Added google drive to conditional requirements
nuwang 71862f5
Use separate env vars for each required param in google drive credent…
nuwang b8bdb68
Added file source for google cloud storage
nuwang d1185fc
Added one data
nuwang cb22970
Added support for illumina basespace filesource
nuwang 15b7b88
Streamline access tokens needed to run gcsfs and gdrive storage tests
nuwang d1f8049
Add support for anonymous gcs file source access
nuwang 5d72ddb
Make gcsfs test optional
nuwang 0924628
Refactor file source tests
nuwang File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The added unit tests are all using the same test structure, can you parameterize them ?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I think they can be. It's something that's generally the case for many file source tests. Maybe a refactoring run that should be done outside of this PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you at least push
_configured_file_sources
into the helper ? That is literally the same in all those tests.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have refactored the tests and helpers. Can you take a look?