Skip to content
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

Improve type hints in manager classes #18129

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
b70a23b
Make most base managers generic and parameterize concrete item managers
mvdbeek May 11, 2024
76b7288
Split UserManager into shared base manager and galaxy-specific user m…
mvdbeek May 11, 2024
d116ea9
Add ToolShed specific user manager
mvdbeek May 11, 2024
d4b2cc5
Fix bugs and type hints reveealed by improved type hints
mvdbeek May 11, 2024
6d046f5
Drop unnecessary type ignores
mvdbeek May 11, 2024
d32b6dd
Make ApiKeyManager generic for galaxy or ts models
mvdbeek May 12, 2024
f82bdd7
Fix and adjust model type optionality
mvdbeek May 12, 2024
ce73553
Cannot use union in lagom
mvdbeek May 12, 2024
fed8b1a
Fix type annotation for api_keys.key
mvdbeek May 13, 2024
668deb2
Fix nullability of TS api key
mvdbeek May 13, 2024
3076954
Fixup setup_users in celery rate limit integration test
mvdbeek May 13, 2024
9866f4e
Fix unit tests
mvdbeek May 13, 2024
1aedb85
Add more type hints in manager signatures
mvdbeek May 23, 2024
da79c31
Fix up history pruner unit test
mvdbeek May 23, 2024
a1760cc
Ensure dataset on disk befoe access
mvdbeek May 11, 2024
2523f47
Tighten up use of DatasetProtocol and DatasetHasHidProtocol
mvdbeek May 23, 2024
5b856b5
Make AccessibleManagerMixin generic
mvdbeek May 23, 2024
1c61242
Specialize generated query in ModelManager
mvdbeek May 23, 2024
67024f0
Add type parameters to DatasetManager
mvdbeek May 23, 2024
f388f05
Add type annotation to HDAManager copy signature
mvdbeek May 23, 2024
e8d0e09
Eliminate unnecessary type ignores
mvdbeek May 23, 2024
35b1e12
Add type hint for dataset_manager_by_type
mvdbeek May 23, 2024
b5e1ddc
Undo DatasetSourceType change
mvdbeek May 23, 2024
f5ed1f1
Turn DatasetSourceType into literal
mvdbeek May 23, 2024
57f0085
Do proper type narrowing in delete_batch
mvdbeek May 23, 2024
796fcd1
Ensure dataset should be on disk before opening dataset
mvdbeek May 23, 2024
26b6c74
Remove unnecessary by_id implementation
mvdbeek May 23, 2024
0eced90
Add API test to ensure that a proper error is returned if the dataset…
mvdbeek May 23, 2024
70aa9d7
Restore nullability of column definition
mvdbeek May 23, 2024
2e0fe2a
Fix nullable typo
mvdbeek May 23, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 17 additions & 19 deletions client/src/api/schema/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4019,14 +4019,10 @@ export interface components {
/**
* Source
* @description The source of this dataset, either `hda` or `ldda` depending of its origin.
* @enum {string}
*/
src: components["schemas"]["DatasetSourceType"];
src: "hda" | "ldda";
};
/**
* DatasetSourceType
* @enum {string}
*/
DatasetSourceType: "hda" | "ldda";
/**
* DatasetState
* @enum {string}
Expand Down Expand Up @@ -4645,8 +4641,9 @@ export interface components {
/**
* Source
* @description The source of this dataset, either `hda` or `ldda` depending of its origin.
* @enum {string}
*/
src: components["schemas"]["DatasetSourceType"];
src: "hda" | "ldda";
};
/** EncodedHdcaSourceId */
EncodedHdcaSourceId: {
Expand Down Expand Up @@ -5605,7 +5602,7 @@ export interface components {
* HDA or LDDA
* @description Whether this dataset belongs to a history (HDA) or a library (LDDA).
*/
hda_ldda?: components["schemas"]["DatasetSourceType"] | null;
hda_ldda?: components["schemas"]["DataItemSourceType"] | null;
/**
* HID
* @description The index position of this item in the History.
Expand Down Expand Up @@ -5851,7 +5848,7 @@ export interface components {
* @description Whether this dataset belongs to a history (HDA) or a library (LDDA).
* @default hda
*/
hda_ldda?: components["schemas"]["DatasetSourceType"];
hda_ldda?: components["schemas"]["DataItemSourceType"];
/**
* HID
* @description The index position of this item in the History.
Expand Down Expand Up @@ -6000,7 +5997,7 @@ export interface components {
* @description Whether this dataset belongs to a history (HDA) or a library (LDDA).
* @default hda
*/
hda_ldda?: components["schemas"]["DatasetSourceType"];
hda_ldda?: components["schemas"]["DataItemSourceType"];
/**
* History ID
* @example 0123456789ABCDEF
Expand Down Expand Up @@ -9370,8 +9367,9 @@ export interface components {
/**
* Source
* @description The source of the content. Can be other history element to be copied or library elements.
* @enum {string}
*/
source: components["schemas"]["DatasetSourceType"];
source: "hda" | "ldda";
};
/** MessageNotificationContent */
MessageNotificationContent: {
Expand Down Expand Up @@ -13847,7 +13845,7 @@ export interface operations {
/** @description View to be passed to the serializer */
/** @description Comma-separated list of keys to be passed to the serializer */
query?: {
hda_ldda?: components["schemas"]["DatasetSourceType"];
hda_ldda?: "hda" | "ldda";
data_type?: components["schemas"]["RequestDataType"] | null;
view?: string | null;
keys?: string | null;
Expand Down Expand Up @@ -14148,7 +14146,7 @@ export interface operations {
parameters: {
/** @description Whether this dataset belongs to a history (HDA) or a library (LDDA). */
query?: {
hda_ldda?: components["schemas"]["DatasetSourceType"];
hda_ldda?: "hda" | "ldda";
};
/** @description The user ID that will be used to effectively make this API call. Only admins and designated users can make API calls on behalf of other users. */
header?: {
Expand Down Expand Up @@ -14184,7 +14182,7 @@ export interface operations {
parameters: {
/** @description Whether this dataset belongs to a history (HDA) or a library (LDDA). */
query?: {
hda_ldda?: components["schemas"]["DatasetSourceType"];
hda_ldda?: "hda" | "ldda";
};
/** @description The user ID that will be used to effectively make this API call. Only admins and designated users can make API calls on behalf of other users. */
header?: {
Expand Down Expand Up @@ -14218,7 +14216,7 @@ export interface operations {
parameters: {
/** @description Whether this dataset belongs to a history (HDA) or a library (LDDA). */
query?: {
hda_ldda?: components["schemas"]["DatasetSourceType"];
hda_ldda?: "hda" | "ldda";
};
/** @description The user ID that will be used to effectively make this API call. Only admins and designated users can make API calls on behalf of other users. */
header?: {
Expand Down Expand Up @@ -14287,7 +14285,7 @@ export interface operations {
parameters: {
/** @description Whether this dataset belongs to a history (HDA) or a library (LDDA). */
query?: {
hda_ldda?: components["schemas"]["DatasetSourceType"];
hda_ldda?: "hda" | "ldda";
};
/** @description The user ID that will be used to effectively make this API call. Only admins and designated users can make API calls on behalf of other users. */
header?: {
Expand Down Expand Up @@ -14353,7 +14351,7 @@ export interface operations {
parameters: {
/** @description Whether this dataset belongs to a history (HDA) or a library (LDDA). */
query?: {
hda_ldda?: components["schemas"]["DatasetSourceType"];
hda_ldda?: "hda" | "ldda";
};
/** @description The user ID that will be used to effectively make this API call. Only admins and designated users can make API calls on behalf of other users. */
header?: {
Expand Down Expand Up @@ -19697,7 +19695,7 @@ export interface operations {
* @description Whether this dataset belongs to a history (HDA) or a library (LDDA).
*/
query?: {
hda_ldda?: components["schemas"]["DatasetSourceType"] | null;
hda_ldda?: ("hda" | "ldda") | null;
};
/** @description The user ID that will be used to effectively make this API call. Only admins and designated users can make API calls on behalf of other users. */
header?: {
Expand Down Expand Up @@ -19798,7 +19796,7 @@ export interface operations {
* @description Whether this dataset belongs to a history (HDA) or a library (LDDA).
*/
query?: {
hda_ldda?: components["schemas"]["DatasetSourceType"] | null;
hda_ldda?: ("hda" | "ldda") | null;
};
/** @description The user ID that will be used to effectively make this API call. Only admins and designated users can make API calls on behalf of other users. */
header?: {
Expand Down
4 changes: 2 additions & 2 deletions lib/galaxy/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
from galaxy.files.templates import ConfiguredFileSourceTemplates
from galaxy.job_metrics import JobMetrics
from galaxy.jobs.manager import JobManager
from galaxy.managers.api_keys import ApiKeyManager
from galaxy.managers.api_keys import GalaxyApiKeyManager
from galaxy.managers.citations import CitationsManager
from galaxy.managers.collections import DatasetCollectionManager
from galaxy.managers.dbkeys import GenomeBuilds
Expand Down Expand Up @@ -722,7 +722,7 @@ def __init__(self, **kwargs) -> None:
self.test_data_resolver = self._register_singleton(
TestDataResolver, TestDataResolver(file_dirs=self.config.tool_test_data_directories)
)
self.api_keys_manager = self._register_singleton(ApiKeyManager)
self.api_keys_manager = self._register_singleton(GalaxyApiKeyManager)

# Tool Data Tables
self._configure_tool_data_tables(from_shed_config=False)
Expand Down
2 changes: 1 addition & 1 deletion lib/galaxy/celery/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ def set_metadata(
try:
if overwrite:
hda_manager.overwrite_metadata(dataset_instance)
dataset_instance.datatype.set_meta(dataset_instance) # type:ignore [arg-type]
dataset_instance.datatype.set_meta(dataset_instance)
dataset_instance.set_peek()
# Reset SETTING_METADATA state so the dataset instance getter picks the dataset state
dataset_instance.set_metadata_success_state()
Expand Down
5 changes: 2 additions & 3 deletions lib/galaxy/datatypes/binary.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@
MetadataParameter,
)
from galaxy.datatypes.protocols import (
DatasetHasHidProtocol,
DatasetProtocol,
HasExtraFilesAndMetadata,
HasFileName,
Expand Down Expand Up @@ -692,7 +691,7 @@ def get_chunk(self, trans, dataset: HasFileName, offset: int = 0, ck_size: Optio
def display_data(
self,
trans,
dataset: DatasetHasHidProtocol,
dataset: DatasetProtocol,
preview: bool = False,
filename: Optional[str] = None,
to_ext: Optional[str] = None,
Expand Down Expand Up @@ -2094,7 +2093,7 @@ def display_peek(self, dataset: DatasetProtocol) -> str:
def display_data(
self,
trans,
dataset: DatasetHasHidProtocol,
dataset: DatasetProtocol,
preview: bool = False,
filename: Optional[str] = None,
to_ext: Optional[str] = None,
Expand Down
7 changes: 2 additions & 5 deletions lib/galaxy/datatypes/blast.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,7 @@
Optional,
)

from galaxy.datatypes.protocols import (
DatasetHasHidProtocol,
DatasetProtocol,
)
from galaxy.datatypes.protocols import DatasetProtocol
from galaxy.datatypes.sniff import (
build_sniff_from_prefix,
FilePrefix,
Expand Down Expand Up @@ -210,7 +207,7 @@ def display_peek(self, dataset: DatasetProtocol) -> str:
def display_data(
self,
trans,
dataset: DatasetHasHidProtocol,
dataset: DatasetProtocol,
preview: bool = False,
filename: Optional[str] = None,
to_ext: Optional[str] = None,
Expand Down
8 changes: 4 additions & 4 deletions lib/galaxy/datatypes/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ def __archive_extra_files_path(self, extra_files_path: str) -> Generator[Tuple[s
yield fpath, rpath

def _serve_raw(
self, dataset: DatasetHasHidProtocol, to_ext: Optional[str], headers: Headers, **kwd
self, dataset: DatasetProtocol, to_ext: Optional[str], headers: Headers, **kwd
) -> Tuple[IO, Headers]:
headers["Content-Length"] = str(os.stat(dataset.get_file_name()).st_size)
headers["content-type"] = (
Expand Down Expand Up @@ -516,7 +516,7 @@ def _serve_file_contents(self, trans, data, headers, preview, file_size, max_pee
def display_data(
self,
trans,
dataset: DatasetHasHidProtocol,
dataset: DatasetProtocol,
preview: bool = False,
filename: Optional[str] = None,
to_ext: Optional[str] = None,
Expand Down Expand Up @@ -648,7 +648,7 @@ def _yield_user_file_content(self, trans, from_dataset: HasCreatingJob, filename

def _download_filename(
self,
dataset: DatasetHasHidProtocol,
dataset: Union[DatasetProtocol, DatasetHasHidProtocol],
to_ext: Optional[str] = None,
hdca: Optional[DatasetHasHidProtocol] = None,
element_identifier: Optional[str] = None,
Expand All @@ -665,7 +665,7 @@ def escape(raw_identifier):
template_values = {
"name": escape(dataset.name),
"ext": to_ext,
"hid": dataset.hid,
"hid": getattr(dataset, "hid", "-library"),
}

if not filename_pattern:
Expand Down
3 changes: 1 addition & 2 deletions lib/galaxy/datatypes/isa.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
from galaxy import util
from galaxy.datatypes.data import Data
from galaxy.datatypes.protocols import (
DatasetHasHidProtocol,
DatasetProtocol,
HasExtraFilesAndMetadata,
HasExtraFilesPath,
Expand Down Expand Up @@ -266,7 +265,7 @@ def groom_dataset_content(self, file_name: str) -> None:
def display_data(
self,
trans,
dataset: DatasetHasHidProtocol,
dataset: DatasetProtocol,
preview: bool = False,
filename: Optional[str] = None,
to_ext: Optional[str] = None,
Expand Down
10 changes: 8 additions & 2 deletions lib/galaxy/datatypes/protocols.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,16 @@
Location of protocols used in datatypes
"""

from typing import Any
from typing import (
Any,
TYPE_CHECKING,
)

from typing_extensions import Protocol

if TYPE_CHECKING:
from sqlalchemy.orm.base import Mapped


class HasClearAssociatedFiles(Protocol):
def clear_associated_files(self, metadata_safe: bool = False, purge: bool = False) -> None: ...
Expand Down Expand Up @@ -35,7 +41,7 @@ class HasHid(Protocol):


class HasId(Protocol):
id: int
id: "Mapped[int]"


class HasInfo(Protocol):
Expand Down
3 changes: 1 addition & 2 deletions lib/galaxy/datatypes/sequence.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
MetadataElement,
)
from galaxy.datatypes.protocols import (
DatasetHasHidProtocol,
DatasetProtocol,
HasMetadata,
)
Expand Down Expand Up @@ -766,7 +765,7 @@ def sniff_prefix(self, file_prefix: FilePrefix) -> bool:
def display_data(
self,
trans,
dataset: DatasetHasHidProtocol,
dataset: DatasetProtocol,
preview: bool = False,
filename: Optional[str] = None,
to_ext: Optional[str] = None,
Expand Down
3 changes: 1 addition & 2 deletions lib/galaxy/datatypes/spaln.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
from galaxy.datatypes.data import Data
from galaxy.datatypes.metadata import MetadataElement
from galaxy.datatypes.protocols import (
DatasetHasHidProtocol,
DatasetProtocol,
HasExtraFilesAndMetadata,
)
Expand Down Expand Up @@ -117,7 +116,7 @@ def display_peek(self, dataset: DatasetProtocol) -> str:
def display_data(
self,
trans,
dataset: DatasetHasHidProtocol,
dataset: DatasetProtocol,
preview: bool = False,
filename: Optional[str] = None,
to_ext: Optional[str] = None,
Expand Down
3 changes: 1 addition & 2 deletions lib/galaxy/datatypes/tabular.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@
MetadataParameter,
)
from galaxy.datatypes.protocols import (
DatasetHasHidProtocol,
DatasetProtocol,
HasFileName,
HasMetadata,
Expand Down Expand Up @@ -168,7 +167,7 @@ def _read_chunk(self, trans, dataset: HasFileName, offset: int, ck_size: Optiona
def display_data(
self,
trans,
dataset: DatasetHasHidProtocol,
dataset: DatasetProtocol,
preview: bool = False,
filename: Optional[str] = None,
to_ext: Optional[str] = None,
Expand Down
5 changes: 2 additions & 3 deletions lib/galaxy/datatypes/text.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
MetadataParameter,
)
from galaxy.datatypes.protocols import (
DatasetHasHidProtocol,
DatasetProtocol,
HasCreatingJob,
HasExtraFilesAndMetadata,
Expand Down Expand Up @@ -208,7 +207,7 @@ def sniff_prefix(self, file_prefix: FilePrefix) -> bool:
def display_data(
self,
trans,
dataset: DatasetHasHidProtocol,
dataset: DatasetProtocol,
preview: bool = False,
filename: Optional[str] = None,
to_ext: Optional[str] = None,
Expand All @@ -224,7 +223,7 @@ def display_data(
def _display_data_trusted(
self,
trans,
dataset: DatasetHasHidProtocol,
dataset: DatasetProtocol,
preview: bool = False,
filename: Optional[str] = None,
to_ext: Optional[str] = None,
Expand Down
Loading
Loading