Skip to content

Commit

Permalink
fix bug for empty requirements
Browse files Browse the repository at this point in the history
an empty set of requirements gives an empty requirement string which
was wrongly parsed to an CondaTarget with empty package name

This triggered a `conda search ''` which took so much memory that other
processes crashed.

The fix is to parse an empty list of CondaTargets for an empty target
string. In addition we check for empty package name during the creation
of the CondaTarget (to make this more easily detectable in the future)
  • Loading branch information
bernt-matthias committed Nov 11, 2024
1 parent 16e7cdf commit c57cca2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
2 changes: 1 addition & 1 deletion lib/galaxy/tool_util/deps/conda_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ class CondaTarget:
def __init__(
self, package: str, version: Optional[str] = None, build: Optional[str] = None, channel: Optional[str] = None
) -> None:
if SHELL_UNSAFE_PATTERN.search(package) is not None:
if SHELL_UNSAFE_PATTERN.search(package) is not None or not package:
raise ValueError(f"Invalid package [{package}] encountered.")
self.capitalized_package = package
self.package = package.lower()
Expand Down
11 changes: 6 additions & 5 deletions lib/galaxy/tool_util/deps/mulled/mulled_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -527,8 +527,8 @@ def add_single_image_arguments(parser):
)


def target_str_to_targets(targets_raw):
def parse_target(target_str):
def target_str_to_targets(targets_raw: str) -> List[CondaTarget]:
def parse_target(target_str: str) -> CondaTarget:
if "=" in target_str:
package_name, version = target_str.split("=", 1)
build = None
Expand All @@ -540,9 +540,10 @@ def parse_target(target_str):
else:
target = build_target(target_str)
return target

targets = [parse_target(_) for _ in targets_raw.split(",")]
return targets
if targets_raw.strip() == "":
return []
else:
return [parse_target(_) for _ in targets_raw.split(",")]


def args_to_mull_targets_kwds(args):
Expand Down

0 comments on commit c57cca2

Please sign in to comment.