Skip to content

Commit

Permalink
Parameterize plugins with bundle class
Browse files Browse the repository at this point in the history
  • Loading branch information
nadove-ucsc committed Apr 15, 2023
1 parent b6e9b0e commit debe0a8
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 12 deletions.
10 changes: 6 additions & 4 deletions src/azul/plugins/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,10 @@ class ManifestFormat(Enum):

T = TypeVar('T', bound='Plugin')

BUNDLE = TypeVar('BUNDLE', bound=Bundle)

class Plugin(ABC):

class Plugin(ABC, Generic[BUNDLE]):
"""
A base class for Azul plugins. Concrete plugins shouldn't inherit this
class directly but one of the subclasses of this class. This class just
Expand Down Expand Up @@ -207,7 +209,7 @@ def _load(cls, plugin_type_name: str, plugin_package_name: str) -> Type[T]:
return plugin_cls


class MetadataPlugin(Plugin):
class MetadataPlugin(Plugin[BUNDLE]):

@classmethod
def type_name(cls) -> str:
Expand All @@ -226,7 +228,7 @@ def transformer_types(self) -> Iterable[Type[Transformer]]:

@abstractmethod
def transformers(self,
bundle: Bundle,
bundle: BUNDLE,
*,
delete: bool
) -> Iterable[Transformer]:
Expand Down Expand Up @@ -418,7 +420,7 @@ def filter_stage(self) -> 'Type[FilterStage]':
raise NotImplementedError


class RepositoryPlugin(Generic[SOURCE_SPEC, SOURCE_REF, BUNDLE_FQID], Plugin):
class RepositoryPlugin(Plugin[BUNDLE], Generic[BUNDLE, SOURCE_SPEC, SOURCE_REF, BUNDLE_FQID]):

@classmethod
def type_name(cls) -> str:
Expand Down
2 changes: 1 addition & 1 deletion src/azul/plugins/metadata/anvil/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
)


class Plugin(MetadataPlugin, AnvilPlugin):
class Plugin(MetadataPlugin[Bundle], AnvilPlugin):

@property
def exposed_indices(self) -> Mapping[str, Sorting]:
Expand Down
2 changes: 1 addition & 1 deletion src/azul/plugins/metadata/hca/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
)


class Plugin(MetadataPlugin, HCAPlugin):
class Plugin(MetadataPlugin[Bundle], HCAPlugin):

def transformer_types(self) -> Iterable[Type[BaseTransformer]]:
return (
Expand Down
2 changes: 1 addition & 1 deletion src/azul/plugins/repository/canned/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def drs_path(self, manifest_entry: JSON) -> Optional[str]:


@dataclass(frozen=True)
class Plugin(HCAPlugin, RepositoryPlugin[SimpleSourceSpec, CannedSourceRef, CannedBundleFQID]):
class Plugin(HCAPlugin, RepositoryPlugin[CannedBundle, SimpleSourceSpec, CannedSourceRef, CannedBundleFQID]):
_sources: Set[SimpleSourceSpec]

@classmethod
Expand Down
2 changes: 1 addition & 1 deletion src/azul/plugins/repository/dss/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def drs_path(self, manifest_entry: JSON) -> str:
return str(furl(path=(file_uuid,), args={'version': file_version}))


class Plugin(HCAPlugin, RepositoryPlugin[SimpleSourceSpec, DSSSourceRef, DSSBundleFQID]):
class Plugin(HCAPlugin, RepositoryPlugin[DSSBundle, SimpleSourceSpec, DSSSourceRef, DSSBundleFQID]):

@classmethod
def create(cls, catalog: CatalogName) -> RepositoryPlugin:
Expand Down
6 changes: 4 additions & 2 deletions src/azul/plugins/repository/tdr.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from abc import (
ABC,
abstractmethod,
)
from collections.abc import (
Expand Down Expand Up @@ -44,6 +45,7 @@
SourcedBundleFQID,
)
from azul.plugins import (
BUNDLE,
RepositoryFileDownload,
RepositoryPlugin,
)
Expand All @@ -70,7 +72,7 @@ class TDRBundleFQID(SourcedBundleFQID[TDRSourceRef]):
pass


class TDRBundle(Bundle[TDRBundleFQID]):
class TDRBundle(Bundle[TDRBundleFQID], ABC):

def drs_path(self, manifest_entry: JSON) -> Optional[str]:
return manifest_entry.get('drs_path')
Expand All @@ -87,7 +89,7 @@ def _parse_drs_path(self, drs_uri: str) -> str:


@attr.s(kw_only=True, auto_attribs=True, frozen=True)
class TDRPlugin(RepositoryPlugin[SOURCE_SPEC, SOURCE_REF, BUNDLE_FQID]):
class TDRPlugin(RepositoryPlugin[BUNDLE, SOURCE_SPEC, SOURCE_REF, BUNDLE_FQID]):
_sources: Set[TDRSourceSpec]

@classmethod
Expand Down
2 changes: 1 addition & 1 deletion src/azul/plugins/repository/tdr_anvil/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ def _parse_drs_uri(self, file_ref: Optional[str]) -> Optional[str]:
return self._parse_drs_path(file_ref)


class Plugin(AnvilPlugin, TDRPlugin[TDRSourceSpec, TDRSourceRef, AnvilBundleFQID]):
class Plugin(AnvilPlugin, TDRPlugin[TDRAnvilBundle, TDRSourceSpec, TDRSourceRef, AnvilBundleFQID]):

@cached_property
def _version(self):
Expand Down
2 changes: 1 addition & 1 deletion src/azul/plugins/repository/tdr_hca/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ def _parse_drs_uri(self,
return None


class Plugin(HCAPlugin, TDRPlugin[TDRSourceSpec, TDRSourceRef, TDRBundleFQID]):
class Plugin(HCAPlugin, TDRPlugin[TDRHCABundle, TDRSourceSpec, TDRSourceRef, TDRBundleFQID]):

def list_partitions(self,
source: TDRSourceRef
Expand Down

0 comments on commit debe0a8

Please sign in to comment.