Skip to content

Commit

Permalink
Do not initialize a full repository registry in ToolShed 2.0.
Browse files Browse the repository at this point in the history
It seems like it is only used by repository_grids - which I think are unused by the new tool shed. I don't recall writing any client side grid framework code and my PR description did claim it was mako free.
  • Loading branch information
jmchilton committed Aug 5, 2024
1 parent a3833c0 commit 2d4d8f4
Show file tree
Hide file tree
Showing 5 changed files with 107 additions and 13 deletions.
107 changes: 99 additions & 8 deletions lib/tool_shed/repository_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
or_,
select,
)
from typing_extensions import Protocol

import tool_shed.repository_types.util as rt_util
from tool_shed.util import (
Expand All @@ -18,11 +19,80 @@
Repository,
RepositoryMetadata,
)
from .structured_app import ToolShedApp

log = logging.getLogger(__name__)


class Registry:
class RegistryInterface(Protocol):

# only used in legacy controllers - can drop when drop old tool shed webapp
def add_category_entry(self, category):
...

def add_entry(self, repository):
# used when creating a repository
# Used in legacy add_repository_registry_entry API endpoint - already deemed not worth pulling over to 2.0
# used in legacy undelete_repository admin controller
# used in legacy deprecate controller
...

def edit_category_entry(self, old_name, new_name):
# used in legacy admin controller
...

def is_valid(self, repository) -> bool:
# probably not used outside this class but also not hurting anything
...

def remove_category_entry(self, category):
...

def remove_entry(self, repository):
...


# stop gap to implement the same general interface as repository_registry but do nothing,
# I don't think this stuff is needed - outside potentially old test cases?
class NullRepositoryRegistry(RegistryInterface):

def __init__(self, app: ToolShedApp):
self.app = app

# all of these are only used by repository_grids - which I think the tool shed 2.0
# does not use at all - but they are part of the "public interface" consumed by
# the full registry.
self.certified_level_one_viewable_repositories_and_suites_by_category = {}
self.certified_level_one_viewable_suites_by_category = {}
self.viewable_repositories_and_suites_by_category = {}
self.viewable_suites_by_category = {}
self.viewable_valid_repositories_and_suites_by_category = {}
self.viewable_valid_suites_by_category = {}

def add_category_entry(self, category):
# only used in legacy controllers - can drop when drop old tool shed webapp
pass

def add_entry(self, repository):
# used when creating a repository, and maybe more?
pass

def edit_category_entry(self, old_name, new_name):
pass

def is_valid(self, repository) -> bool:
if repository and not repository.deleted and not repository.deprecated and repository.downloadable_revisions:
return True
return False

def remove_category_entry(self, category):
pass

def remove_entry(self, repository):
pass


class Registry(RegistryInterface):
def __init__(self, app):
log.debug("Loading the repository registry...")
self.app = app
Expand All @@ -32,17 +102,30 @@ def __init__(self, app):
self.certified_level_one_suite_tuples = []
# These category dictionaries contain entries where the key is the category and the value is the integer count
# of viewable repositories within that category.

# only used internally to class and by repository_grids
self.certified_level_one_viewable_repositories_and_suites_by_category = {}
# only used internally to class and by repository_grids
self.certified_level_one_viewable_suites_by_category = {}
self.certified_level_two_repository_and_suite_tuples = []
self.certified_level_two_suite_tuples = []
self.certified_level_two_viewable_repositories_and_suites_by_category = {}
self.certified_level_two_viewable_suites_by_category = {}

# not even used in legacy shed code...
# self.certified_level_two_repository_and_suite_tuples = []
# self.certified_level_two_suite_tuples = []
# self.certified_level_two_viewable_repositories_and_suites_by_category = {}
# self.certified_level_two_viewable_suites_by_category = {}

# only used internally to class
self.repository_and_suite_tuples = []
# only used internally to class
self.suite_tuples = []

# only used internally to class and by repository_grids
self.viewable_repositories_and_suites_by_category = {}
# only used internally to class and by repository_grids
self.viewable_suites_by_category = {}
# only used internally to class and by repository_grids
self.viewable_valid_repositories_and_suites_by_category = {}
# only used internally to class and by repository_grids
self.viewable_valid_suites_by_category = {}
self.load()

Expand Down Expand Up @@ -152,6 +235,7 @@ def edit_category_entry(self, old_name, new_name):
self.certified_level_one_viewable_suites_by_category[new_name] = 0

def get_certified_level_one_clause_list(self):
# only used internally to class
clause_list = []
for repository in get_repositories(self.sa_session):
certified_level_one_tuple = self.get_certified_level_one_tuple(repository)
Expand All @@ -169,6 +253,7 @@ def get_certified_level_one_tuple(self, repository):
"""
Return True if the latest installable changeset_revision of the received repository is level one certified.
"""
# only used internally to class
if repository is None:
return (None, False)
if repository.deleted or repository.deprecated:
Expand All @@ -190,6 +275,7 @@ def get_certified_level_one_tuple(self, repository):
return (None, False)

def is_level_one_certified(self, repository_metadata):
# only used internally to class
if repository_metadata:
repository = repository_metadata.repository
if repository:
Expand All @@ -206,12 +292,13 @@ def is_level_one_certified(self, repository_metadata):
return tuple in self.certified_level_one_repository_and_suite_tuples
return False

def is_valid(self, repository):
def is_valid(self, repository) -> bool:
if repository and not repository.deleted and not repository.deprecated and repository.downloadable_revisions:
return True
return False

def load_certified_level_one_repository_and_suite_tuple(self, repository):
# only used internally to class
# The received repository has been determined to be level one certified.
name = str(repository.name)
owner = str(repository.user.username)
Expand All @@ -226,6 +313,7 @@ def load_certified_level_one_repository_and_suite_tuple(self, repository):
self.certified_level_one_repository_and_suite_tuples.append(certified_level_one_tuple)

def load_repository_and_suite_tuple(self, repository):
# only used internally to class
name = str(repository.name)
owner = str(repository.user.username)
for repository_metadata in repository.metadata_revisions:
Expand All @@ -238,6 +326,7 @@ def load_repository_and_suite_tuple(self, repository):
self.suite_tuples.append(tuple)

def load_repository_and_suite_tuples(self):
# only used internally to class
# Load self.certified_level_one_repository_and_suite_tuples and self.certified_level_one_suite_tuples.
clauses = self.get_certified_level_one_clause_list()
for repository in get_certified_repositories_with_user(self.sa_session, clauses, model.User):
Expand All @@ -247,11 +336,12 @@ def load_repository_and_suite_tuples(self):
self.load_repository_and_suite_tuple(repository)

def load_viewable_repositories_and_suites_by_category(self):
# only used internally to class
# Clear all dictionaries just in case they were previously loaded.
self.certified_level_one_viewable_repositories_and_suites_by_category = {}
self.certified_level_one_viewable_suites_by_category = {}
self.certified_level_two_viewable_repositories_and_suites_by_category = {}
self.certified_level_two_viewable_suites_by_category = {}
# self.certified_level_two_viewable_repositories_and_suites_by_category = {}
# self.certified_level_two_viewable_suites_by_category = {}
self.viewable_repositories_and_suites_by_category = {}
self.viewable_suites_by_category = {}
self.viewable_valid_repositories_and_suites_by_category = {}
Expand Down Expand Up @@ -363,6 +453,7 @@ def remove_entry(self, repository):

@property
def sa_session(self):
# only used internally to class
return self.app.model.session

def unload_certified_level_one_repository_and_suite_tuple(self, repository):
Expand Down
4 changes: 2 additions & 2 deletions lib/tool_shed/structured_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

if TYPE_CHECKING:
from tool_shed.managers.model_cache import ModelCache
from tool_shed.repository_registry import Registry as RepositoryRegistry
from tool_shed.repository_registry import RegistryInterface
from tool_shed.repository_types.registry import Registry as RepositoryTypesRegistry
from tool_shed.util.hgweb_config import HgWebConfigManager
from tool_shed.webapp.model import mapping
Expand All @@ -14,7 +14,7 @@
class ToolShedApp(BasicSharedApp):
repository_types_registry: "RepositoryTypesRegistry"
model: "mapping.ToolShedModelMapping"
repository_registry: "RepositoryRegistry"
repository_registry: "RegistryInterface"
hgweb_config_manager: "HgWebConfigManager"
security_agent: "CommunityRBACAgent"
model_cache: "ModelCache"
5 changes: 4 additions & 1 deletion lib/tool_shed/webapp/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,10 @@ def __init__(self, **kwd) -> None:
self.hgweb_config_manager.hgweb_config_dir = self.config.hgweb_config_dir
self.hgweb_config_manager.hgweb_repo_prefix = self.config.hgweb_repo_prefix
# Initialize the repository registry.
self.repository_registry = tool_shed.repository_registry.Registry(self)
if config.SHED_API_VERSION != "v2":
self.repository_registry = tool_shed.repository_registry.Registry(self)
else:
self.repository_registry = tool_shed.repository_registry.NullRepositoryRegistry(self)
# Configure Sentry client if configured
self.configure_sentry_client()
# used for cachebusting -- refactor this into a *SINGLE* UniverseApplication base.
Expand Down
3 changes: 1 addition & 2 deletions lib/tool_shed/webapp/buildapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@
GalaxyWebTransaction,
)
from galaxy.webapps.util import wrap_if_allowed

SHED_API_VERSION = os.environ.get("TOOL_SHED_API_VERSION", "v1")
from .config import SHED_API_VERSION

log = logging.getLogger(__name__)

Expand Down
1 change: 1 addition & 0 deletions lib/tool_shed/webapp/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
log = logging.getLogger(__name__)

TOOLSHED_APP_NAME = "tool_shed"
SHED_API_VERSION = os.environ.get("TOOL_SHED_API_VERSION", "v1")


class ToolShedAppConfiguration(BaseAppConfiguration, CommonConfigurationMixin):
Expand Down

0 comments on commit 2d4d8f4

Please sign in to comment.