Unverified Commit 8f0e11b9 authored by Nicola Soranzo's avatar Nicola Soranzo
Browse files

Use ``best_search_result()`` function instead of parsing anaconda.org web pages

Fix the following mulled unit test:

```
FAILED test/unit/tool_util/mulled/test_get_tests.py::test_hashed_test_search - AssertionError: assert ['samtools --help'] == ['bamtools --help', 'samtools --help']
  At index 0 diff: 'samtools --help' != 'bamtools --help'
  Right contains one more item: 'samtools --help'
  Full diff:
  - ['bamtools --help', 'samtools --help']
  + ['samtools --help']
```

that started not finding bamtools-2.4.0 inside
https://anaconda.org/bioconda/bamtools/files any more.

Also:
- Add type annotation to `CondaInDockerContext` and fix ensuing issues.
parent 302acfbc
Loading
Loading
Loading
Loading
+6 −4
Original line number Diff line number Diff line
@@ -101,7 +101,7 @@ class CondaContext(installable.InstallableContext):
    def __init__(
        self,
        conda_prefix: Optional[str] = None,
        conda_exec: Optional[str] = None,
        conda_exec: Optional[Union[str, List[str]]] = None,
        shell_exec: Optional[Callable[..., int]] = None,
        debug: bool = False,
        ensure_channels: Union[str, List[str]] = "",
@@ -204,11 +204,12 @@ class CondaContext(installable.InstallableContext):

    def is_conda_installed(self) -> bool:
        """
        Check if conda_exec exists
        Check if conda_info() works
        """
        if os.path.exists(self.conda_exec):
        try:
            self.conda_info()
            return True
        else:
        except Exception:
            return False

    def can_install_conda(self) -> bool:
@@ -218,6 +219,7 @@ class CondaContext(installable.InstallableContext):
        If conda_exec equals conda_prefix/bin/conda, we can install conda if either conda_prefix
        does not exist or is empty.
        """
        assert isinstance(self.conda_exec, str), "conda_exec is not a str"
        conda_exec = os.path.abspath(self.conda_exec)
        conda_prefix_plus_exec = os.path.abspath(os.path.join(self.conda_prefix, "bin/conda"))
        if conda_exec == conda_prefix_plus_exec:
+1 −1
Original line number Diff line number Diff line
@@ -42,13 +42,13 @@ from ..container_classes import (
)
from ..docker_util import build_docker_images_command
from ..mulled.mulled_build import (
    DEFAULT_CHANNELS,
    ensure_installed,
    InvolucroContext,
    mull_targets,
)
from ..mulled.mulled_build_tool import requirements_to_mulled_targets
from ..mulled.util import (
    DEFAULT_CHANNELS,
    default_mulled_conda_channels_from_env,
    mulled_tags_for,
    split_tag,
+1 −1
Original line number Diff line number Diff line
@@ -12,7 +12,7 @@ from galaxy.tool_util.deps.requirements import (
    ToolRequirements,
)
from galaxy.util import bunch
from .mulled.mulled_build import DEFAULT_CHANNELS
from .mulled.util import DEFAULT_CHANNELS


class AppInfo:
+1 −1
Original line number Diff line number Diff line
@@ -34,7 +34,7 @@ class InstallableContext(metaclass=abc.ABCMeta):
        """Return parent path of the location the installable will be created within."""


def ensure_installed(installable_context, install_func, auto_init):
def ensure_installed(installable_context: InstallableContext, install_func, auto_init):
    """Make sure target is installed - handle multiple processes potentially attempting installation."""
    parent_path = installable_context.parent_path
    desc = installable_context.installable_description
+17 −13
Original line number Diff line number Diff line
@@ -25,12 +25,17 @@ except ImportError:
    Template = None  # type: ignore[assignment,misc]
    UndefinedError = Exception  # type: ignore[assignment,misc]

from galaxy.tool_util.deps.conda_util import (
    best_search_result,
    CondaTarget,
)
from galaxy.util import (
    check_github_api_response_rate_limit,
    unicodify,
)
from galaxy.util.commands import argv_to_str
from .util import (
    CondaInDockerContext,
    get_files_from_conda_package,
    MULLED_SOCKET_TIMEOUT,
    split_container_name,
@@ -291,20 +296,19 @@ def hashed_test_search(
    targets = concatenated_targets.split(",")
    packages = [target.split("=") for target in targets]

    conda_context = CondaInDockerContext(ensure_channels=[anaconda_channel])
    containers = []
    for package in packages:
        r = requests.get(f"https://anaconda.org/bioconda/{package[0]}/files", timeout=MULLED_SOCKET_TIMEOUT)
        r.raise_for_status()
        p = "-".join(package)
        for line in r.text.split("\n"):
    for package_name, package_version in packages:
        conda_target = CondaTarget(package_name, package_version)
        # include only linux-64 builds since that is hardcoded in get_anaconda_url and the only target for container builds
            if p in line and "linux-64" in line:
                build = line.split(p)[1].split(".tar.bz2")[0]
                if build == "":
                    containers.append(f"{package[0]}:{package[1]}")
        hit, exact = best_search_result(conda_target, conda_context, platform="linux-64")
        if not hit or not exact:
            raise Exception(f"Could not find {conda_target}")
        build = hit["build"]
        if build:
            containers.append(f"{package_name}:{package_version}--{build}")
        else:
                    containers.append(f"{package[0]}:{package[1]}-{build}")
                break
            containers.append(f"{package_name}:{package_version}")

    for container in containers:
        tests = main_test_search(container, recipes_path, deep, anaconda_channel, github_repo)
Loading