Skip to content
Permalink
Browse files
More type fixes.
  • Loading branch information
jmchilton committed Dec 31, 2020
1 parent 1fd4bce commit 53b503ba214ae8ef3fb17c1c79327586aae2d12b
@@ -3,4 +3,4 @@
"""

from pkgutil import extend_path
__path__ = extend_path(__path__, __name__)
__path__ = extend_path(__path__, __name__) # type: ignore
@@ -20,7 +20,7 @@ def _match_by_user(item, user):

class AnnotatableManagerMixin:
#: class of AnnotationAssociation (e.g. HistoryAnnotationAssociation)
annotation_assoc = None
annotation_assoc: type

def annotation(self, item):
"""
@@ -894,9 +894,7 @@ class ModelFilterParser(HasAModelManager):
# (as the model informs how the filter params are parsed)
# I have no great idea where this 'belongs', so it's here for now

#: model class
model_class = None
subcontainer_model_class = None
model_class: type
parsed_filter = parsed_filter

def __init__(self, app, **kwargs):
@@ -20,9 +20,6 @@ class CloudAuthzManager(sharable.SharableModelManager):
model_class = model.CloudAuthz
foreign_key_name = 'cloudauthz'

def __init__(self, app, *args, **kwargs):
super().__init__(app, *args, **kwargs)


class CloudAuthzsSerializer(base.ModelSerializer):
"""
@@ -31,8 +31,8 @@ class ContainerManagerMixin:
# TODO: terminology is getting a bit convoluted and silly at this point: rename three public below?
# TODO: this should be an open mapping (not just 2)
#: the classes that can be contained
contained_class = None
subcontainer_class = None
contained_class: type
subcontainer_class: type
#: how any contents lists produced are ordered - (string) attribute name to sort on or tuple of attribute names
default_order_by: Optional[str] = None

@@ -4,6 +4,7 @@
import glob
import logging
import os
from typing import Type

from galaxy import (
exceptions,
@@ -232,7 +233,7 @@ class DatasetAssociationManager(base.ModelManager,
"""
# DA's were meant to be proxies - but were never fully implemented as them
# Instead, a dataset association HAS a dataset but contains metadata specific to a library (lda) or user (hda)
model_class = model.DatasetInstance
model_class: Type[model.DatasetInstance] = model.DatasetInstance

# NOTE: model_manager_class should be set in HDA/LDA subclasses

@@ -473,7 +473,6 @@ class HistoryContentsFilters(base.ModelFilterParser,
tools.ToolFilterMixin):
# surprisingly (but ominously), this works for both content classes in the union that's filtered
model_class = model.HistoryDatasetAssociation
subcontainer_model_class = model.HistoryDatasetCollectionAssociation

def _parse_orm_filter(self, attr, op, val):

@@ -2,18 +2,19 @@
Mixins for Ratable model managers and serializers.
"""
import logging
from typing import Type

from sqlalchemy.sql.expression import func

from galaxy.model import ItemRatingAssociation
from . import base

log = logging.getLogger(__name__)


class RatableManagerMixin:

#: class of RatingAssociation (e.g. HistoryRatingAssociation)
rating_assoc = None
rating_assoc: Type[ItemRatingAssociation]

def rating(self, item, user, as_int=True):
"""Returns the integer rating given to this item by the user.
@@ -21,7 +21,7 @@ class RBACPermission:
(Libraries, Datasets).
"""

permissions_class = None
permissions_class: type
permission_failed_error_class = RBACPermissionFailedException

def __init__(self, app):
@@ -11,7 +11,7 @@
"""
import logging
import re
from typing import Optional
from typing import Optional, Type

from sqlalchemy import true

@@ -24,6 +24,7 @@
taggable,
users
)
from galaxy.model import UserShareAssociation

log = logging.getLogger(__name__)

@@ -34,7 +35,7 @@ class SharableModelManager(base.ModelManager, secured.OwnableManagerMixin, secur
# base.DeleteableModelMixin? (all four are deletable)

#: the model used for UserShareAssociations with this model
user_share_model = None
user_share_model: Type[UserShareAssociation]

#: the single character abbreviation used in username_and_slug: e.g. 'h' for histories: u/user/h/slug
SINGLE_CHAR_ABBR: Optional[str] = None
@@ -5,6 +5,7 @@
# from galaxy import exceptions as galaxy_exceptions

import logging
from typing import Type

from sqlalchemy import sql

@@ -45,8 +46,7 @@ def _tags_from_strings(item, tag_handler, new_tags_list, user=None):


class TaggableManagerMixin:
#: class of TagAssociation (e.g. HistoryTagAssociation)
tag_assoc = None
tag_assoc: Type[model.ItemTagAssociation]

# TODO: most of this can be done by delegating to the GalaxyTagHandler?
def get_tags(self, item):
@@ -18,7 +18,7 @@
from collections import defaultdict
from datetime import datetime, timedelta
from string import Template
from typing import TYPE_CHECKING
from typing import Optional, TYPE_CHECKING
from uuid import UUID, uuid4

from boltons.iterutils import remap
@@ -2183,7 +2183,11 @@ def __collection_contents_iter(self, **kwds):
return self.__filter_contents(HistoryDatasetCollectionAssociation, **kwds)


class HistoryUserShareAssociation(RepresentById):
class UserShareAssociation(RepresentById):
user: Optional[User]


class HistoryUserShareAssociation(UserShareAssociation):
def __init__(self):
self.history = None
self.user = None
@@ -4867,6 +4871,7 @@ class Workflow(Dictifiable, RepresentById):
input_step_types = ['data_input', 'data_collection_input', 'parameter_input']

def __init__(self, uuid=None):
self.id = None
self.user = None
self.name = None
self.has_cycles = None
@@ -5256,7 +5261,7 @@ def copy(self, copied_step):
return copied_output


class StoredWorkflowUserShareAssociation(RepresentById):
class StoredWorkflowUserShareAssociation(UserShareAssociation):

def __init__(self):
self.stored_workflow = None
@@ -6187,7 +6192,7 @@ def to_dict(self, view='element'):
return rval


class PageUserShareAssociation(RepresentById):
class PageUserShareAssociation(UserShareAssociation):
def __init__(self):
self.page = None
self.user = None
@@ -6251,7 +6256,7 @@ def copy(self, visualization=None):
)


class VisualizationUserShareAssociation(RepresentById):
class VisualizationUserShareAssociation(UserShareAssociation):
def __init__(self):
self.visualization = None
self.user = None
@@ -1885,7 +1885,7 @@ def simple_mapping(model, **kwds):
# Set up proxy so that
# History.users_shared_with
# returns a list of users that history is shared with.
model.History.users_shared_with_dot_users = association_proxy('users_shared_with', 'user')
model.History.users_shared_with_dot_users = association_proxy('users_shared_with', 'user') # type: ignore

mapper(model.HistoryUserShareAssociation, model.HistoryUserShareAssociation.table, properties=dict(
user=relation(model.User, backref='histories_shared_by_others'),
@@ -1934,7 +1934,7 @@ def simple_mapping(model, **kwds):

# Set up proxy so that this syntax is possible:
# <user_obj>.preferences[pref_name] = pref_value
model.User.preferences = association_proxy('_preferences', 'value', creator=model.UserPreference)
model.User.preferences = association_proxy('_preferences', 'value', creator=model.UserPreference) # type: ignore

mapper(model.Group, model.Group.table, properties=dict(
users=relation(model.UserGroupAssociation)
@@ -2502,7 +2502,7 @@ def simple_mapping(model, **kwds):
# Set up proxy so that
# StoredWorkflow.users_shared_with
# returns a list of users that workflow is shared with.
model.StoredWorkflow.users_shared_with_dot_users = association_proxy('users_shared_with', 'user')
model.StoredWorkflow.users_shared_with_dot_users = association_proxy('users_shared_with', 'user') # type: ignore

mapper(model.StoredWorkflowUserShareAssociation, model.StoredWorkflowUserShareAssociation.table, properties=dict(
user=relation(model.User,
@@ -2661,7 +2661,7 @@ def simple_mapping(model, **kwds):
# Set up proxy so that
# Page.users_shared_with
# returns a list of users that page is shared with.
model.Page.users_shared_with_dot_users = association_proxy('users_shared_with', 'user')
model.Page.users_shared_with_dot_users = association_proxy('users_shared_with', 'user') # type: ignore

mapper(model.PageUserShareAssociation, model.PageUserShareAssociation.table,
properties=dict(user=relation(model.User, backref='pages_shared_by_others'),
@@ -2781,14 +2781,14 @@ def rating_mapping(rating_class, **kwds):
external_output_metadata=relation(model.JobExternalOutputMetadata, lazy=True),
tasks=relation(model.Task)
))
model.Job.any_output_dataset_deleted = column_property(
model.Job.any_output_dataset_deleted = column_property( # type: ignore
exists([model.HistoryDatasetAssociation],
and_(model.Job.table.c.id == model.JobToOutputDatasetAssociation.table.c.job_id,
model.HistoryDatasetAssociation.table.c.id == model.JobToOutputDatasetAssociation.table.c.dataset_id,
model.HistoryDatasetAssociation.table.c.deleted == true())
)
)
model.Job.any_output_dataset_collection_instances_deleted = column_property(
model.Job.any_output_dataset_collection_instances_deleted = column_property( # type: ignore
exists([model.HistoryDatasetCollectionAssociation.table.c.id],
and_(model.Job.table.c.id == model.JobToOutputDatasetCollectionAssociation.table.c.job_id,
model.HistoryDatasetCollectionAssociation.table.c.id == model.JobToOutputDatasetCollectionAssociation.table.c.dataset_collection_id,
@@ -2861,7 +2861,7 @@ def _workflow_invocation_update(self):
session.execute(stmt)


model.WorkflowInvocation.update = _workflow_invocation_update
model.WorkflowInvocation.update = _workflow_invocation_update # type: ignore


def init(file_path, url, engine_options=None, create_tables=False, map_install_models=False,
@@ -560,7 +560,7 @@ def is_installed(self):
return self.status == self.installation_status.INSTALLED


class ToolVersion(Dictifiable):
class ToolVersion(Dictifiable, _HasTable):
dict_element_visible_keys = ['id', 'tool_shed_repository']

def __init__(self, id=None, create_time=None, tool_id=None, tool_shed_repository=None):
@@ -5,6 +5,6 @@
except ImportError:
# when installed as a library, galaxy-web-apps may not be available - this
# is fine - we shouldn't be using this entry point anyway.
app_factory = None
app_factory = None # type: ignore

__all__ = ('app_factory', )
@@ -574,10 +574,10 @@ class Grid:
Specifies the content and format of a grid (data table).
"""
title = ""
model_class = None
model_class: Optional[type] = None
show_item_checkboxes = False
use_hide_message = True
global_actions: List[Dict] = []
global_actions: List[GridAction] = []
columns: List[GridColumn] = []
operations: List[GridOperation] = []
standard_filters: List[GridColumnFilter] = []
@@ -591,7 +591,7 @@ class Grid:
cur_filter_pref_name = ".filter"
cur_sort_key_pref_name = ".sort_key"
legend = None
info_text = None
info_text: Optional[str] = None

def __init__(self):
# Determine if any multiple row operations are defined
@@ -539,7 +539,7 @@ class Grid:
Specifies the content and format of a grid (data table).
"""
title = ""
model_class = None
model_class: Optional[type] = None
show_item_checkboxes = False
template = "legacy/grid_base.mako"
async_template = "legacy/grid_base_async.mako"
@@ -7,7 +7,8 @@
import logging
import os
import random
from collections import namedtuple
from enum import Enum
from typing import Set, Tuple

from sqlalchemy.orm import object_session

@@ -19,12 +20,18 @@

log = logging.getLogger(__name__)

_handler_assignment_methods = (
'MEM_SELF', 'DB_SELF', 'DB_PREASSIGN', 'DB_TRANSACTION_ISOLATION', 'DB_SKIP_LOCKED', 'UWSGI_MULE_MESSAGE'
)
HANDLER_ASSIGNMENT_METHODS = namedtuple('JOB_HANDLER_ASSIGNMENT_METHODS', _handler_assignment_methods)(
*[x.lower().replace('_', '-') for x in _handler_assignment_methods]
)

class HANDLER_ASSIGNMENT_METHODS(str, Enum):
MEM_SELF = 'mem-self'
DB_SELF = 'db-self'
DB_PREASSIGN = 'db-preassign'
DB_TRANSACTION_ISOLATION = 'db-transaction-isolation'
DB_SKIP_LOCKED = 'db-skip-locked'
UWSGI_MULE_MESSAGE = 'uwsgi-mule-message'

@classmethod
def has_value(cls, value):
return value in cls._value2member_map_


class HandlerAssignmentSkip(Exception):
@@ -34,8 +41,8 @@ class HandlerAssignmentSkip(Exception):

class ConfiguresHandlers:
DEFAULT_HANDLER_TAG = '_default_'
DEFAULT_BASE_HANDLER_POOLS = ()
UNSUPPORTED_HANDLER_ASSIGNMENT_METHODS = ()
DEFAULT_BASE_HANDLER_POOLS: Tuple[str, ...] = ()
UNSUPPORTED_HANDLER_ASSIGNMENT_METHODS: Set[str] = set()

def add_handler(self, handler_id, tags):
if handler_id not in self.handlers:
@@ -112,9 +119,9 @@ def _init_handler_assignment_methods(self, handling_config_dict=None):
if handling_config_dict:
for method in handling_config_dict.get("assign", []):
method = method.lower()
assert method in HANDLER_ASSIGNMENT_METHODS, \
assert HANDLER_ASSIGNMENT_METHODS.has_value(method), \
"Invalid job handler assignment method '{}', must be one of: {}".format(
method, ', '.join(HANDLER_ASSIGNMENT_METHODS))
method, ', '.join([h.value for h in HANDLER_ASSIGNMENT_METHODS]))
try:
self.handler_assignment_methods.append(method)
except AttributeError:
@@ -2,6 +2,7 @@
This module *does not* contain API routes. It exclusively contains dependencies to be used in FastAPI routes
"""
from typing import (
cast,
Optional,
)

@@ -28,7 +29,7 @@


def get_app() -> UniverseApplication:
return galaxy_app.app
return cast(UniverseApplication, galaxy_app.app)


def get_job_manager(app: UniverseApplication = Depends(get_app)) -> JobManager:
@@ -80,7 +80,7 @@ def show(self, id: EncodedDatabaseIdField, trans: SessionRequestContext = Depend
"""
id = trans.app.security.decode_id(id)
job = self.job_manager.get_accessible_job(trans, id)
return view_show_job(trans, job, full)
return view_show_job(trans, job, bool(full))


class JobController(BaseAPIController, UsesVisualizationMixin):
Loading

0 comments on commit 53b503b

Please sign in to comment.