Skip to content

Commit

Permalink
Merge pull request galaxyproject#18037 from jmchilton/files_typing
Browse files Browse the repository at this point in the history
More typing in galaxy.files.
  • Loading branch information
jmchilton authored Apr 22, 2024
2 parents 4e27e13 + 0f993f6 commit edc2302
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
15 changes: 9 additions & 6 deletions lib/galaxy/files/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from galaxy import exceptions
from galaxy.files.sources import (
BaseFilesSource,
FilesSourceProperties,
PluginKind,
)
from galaxy.util import plugin_config
Expand All @@ -39,6 +40,8 @@ class NoMatchingFileSource(Exception):
class ConfiguredFileSources:
"""Load plugins and resolve Galaxy URIs to FileSource objects."""

_file_sources: List[BaseFilesSource]

def __init__(
self,
file_sources_config: "ConfiguredFileSourcesConfig",
Expand All @@ -48,7 +51,7 @@ def __init__(
):
self._file_sources_config = file_sources_config
self._plugin_classes = self._file_source_plugins_dict()
file_sources = []
file_sources: List[BaseFilesSource] = []
if conf_file is not None:
file_sources = self._load_plugins_from_file(conf_file)
elif conf_dict is not None:
Expand Down Expand Up @@ -79,7 +82,7 @@ def _ensure_loaded(plugin_type):

if stock_file_source_conf_dict:
stock_plugin_source = plugin_config.plugin_source_from_dict(stock_file_source_conf_dict)
# insert at begining instead of append so FTP and library import appear
# insert at beginning instead of append so FTP and library import appear
# at the top of the list (presumably the most common options). Admins can insert
# these explicitly for greater control.
file_sources = self._parse_plugin_source(stock_plugin_source) + file_sources
Expand Down Expand Up @@ -107,7 +110,7 @@ def _parse_plugin_source(self, plugin_source):
dict_to_list_key="id",
)

def find_best_match(self, url: str):
def find_best_match(self, url: str) -> Optional[BaseFilesSource]:
"""Returns the best matching file source for handling a particular url. Each filesource scores its own
ability to match a particular url, and the highest scorer with a score > 0 is selected."""
scores = [FileSourceScore(file_source, file_source.score_url_match(url)) for file_source in self._file_sources]
Expand All @@ -124,7 +127,7 @@ def get_file_source_path(self, uri):
path = file_source.to_relative_path(uri)
return FileSourcePath(file_source, path)

def validate_uri_root(self, uri, user_context):
def validate_uri_root(self, uri: str, user_context: "ProvidesUserFileSourcesUserContext"):
# validate a URI against Galaxy's configuration, environment, and the current
# user. Throw appropriate exception if there is a problem with the files source
# referenced by the URI.
Expand Down Expand Up @@ -171,8 +174,8 @@ def plugins_to_dict(
browsable_only: Optional[bool] = False,
include_kind: Optional[Set[PluginKind]] = None,
exclude_kind: Optional[Set[PluginKind]] = None,
) -> List[Dict[str, Any]]:
rval = []
) -> List[FilesSourceProperties]:
rval: List[FilesSourceProperties] = []
for file_source in self._file_sources:
if not file_source.user_has_access(user_context):
continue
Expand Down
3 changes: 2 additions & 1 deletion lib/galaxy/files/sources/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,13 +267,14 @@ class FilesSource(SingleFileSource, SupportsBrowsing):
implements the `SupportsBrowsing` interface.
"""

plugin_type: ClassVar[str]

@abc.abstractmethod
def get_browsable(self) -> bool:
"""Return true if the filesource implements the SupportsBrowsing interface."""


class BaseFilesSource(FilesSource):
plugin_type: ClassVar[str]
plugin_kind: ClassVar[PluginKind] = PluginKind.rfs # Remote File Source by default, override in subclasses

def get_browsable(self) -> bool:
Expand Down

0 comments on commit edc2302

Please sign in to comment.