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

Another shot at tool shed API fixes #18646

Merged
merged 2 commits into from
Aug 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 5 additions & 0 deletions lib/galaxy/exceptions/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,11 @@ class InconsistentDatabase(MessageException):
err_code = error_codes_by_name["INCONSISTENT_DATABASE"]


class InconsistentApplicationState(MessageException):
status_code = 500
err_code = error_codes_by_name["INCONSISTENT_APPLICATION_STATE"]


class InternalServerError(MessageException):
status_code = 500
err_code = error_codes_by_name["INTERNAL_SERVER_ERROR"]
Expand Down
5 changes: 5 additions & 0 deletions lib/galaxy/exceptions/error_codes.json
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,11 @@
"code": 500006,
"message": "Reference data required for program execution failed to load."
},
{
"name": "INCONSISTENT_APPLICATION_STATE",
"code": 500007,
"message": "Inconsistent application state (likely not dbms related) prevented fulfilling the request."
},
{
"name": "NOT_IMPLEMENTED",
"code": 501001,
Expand Down
11 changes: 10 additions & 1 deletion lib/tool_shed/managers/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

from galaxy import exceptions
from galaxy.exceptions import (
InconsistentApplicationState,
InternalServerError,
ObjectNotFound,
RequestParameterInvalidException,
Expand Down Expand Up @@ -148,9 +149,17 @@ def _shed_tool_source_for(
cloned_ok, error_message = clone_repository(repository_clone_url, work_dir, str(ctx.rev()))
if error_message:
raise InternalServerError("Failed to materialize target repository revision")
repo_files_dir = repository_metadata.repository.repo_path(trans.app)
repo_files_dir = repository_metadata.repository.hg_repository_path(trans.app.config.file_path)
if not repo_files_dir:
raise InconsistentApplicationState(
f"Failed to resolve repository path from hgweb_config_manager for [{trs_tool_id}], inconsistent repository state or application configuration"
)
repo_rel_tool_path = relpath(tool_config, repo_files_dir)
path_to_tool = os.path.join(work_dir, repo_rel_tool_path)
if not os.path.exists(path_to_tool):
raise InconsistentApplicationState(
f"Target tool expected at [{path_to_tool}] and not found, inconsistent repository state or application configuration"
)
tool_source = get_tool_source(path_to_tool)
return tool_source
finally:
Expand Down
7 changes: 1 addition & 6 deletions lib/tool_shed/util/repository_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,12 +231,7 @@ def create_repository(
session = sa_session()
with transaction(session):
session.commit()
dir = os.path.join(app.config.file_path, *util.directory_hash_id(repository.id))
# Define repo name inside hashed directory.
final_repository_path = os.path.join(dir, "repo_%d" % repository.id)
# Create final repository directory.
if not os.path.exists(final_repository_path):
os.makedirs(final_repository_path)
final_repository_path = repository.ensure_hg_repository_path(app.config.file_path)
os.rename(repository_path, final_repository_path)
app.hgweb_config_manager.add_entry(lhs, final_repository_path)
# Update the repository registry.
Expand Down
13 changes: 13 additions & 0 deletions lib/tool_shed/webapp/model/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,19 @@ def repo_path(self, app=None):
os.path.join(hgweb_config_manager.hgweb_repo_prefix, self.user.username, self.name)
)

def hg_repository_path(self, repositories_directory: str) -> str:
if self.id is None:
raise Exception("Attempting to call hg_repository_path before id has been set on repository object")
dir = os.path.join(repositories_directory, *util.directory_hash_id(self.id))
final_repository_path = os.path.join(dir, "repo_%d" % self.id)
return final_repository_path

def ensure_hg_repository_path(self, repositories_directory: str) -> str:
final_repository_path = self.hg_repository_path(repositories_directory)
if not os.path.exists(final_repository_path):
os.makedirs(final_repository_path)
return final_repository_path

def revision(self):
repo = self.hg_repo
tip_ctx = repo[repo.changelog.tip()]
Expand Down
Loading