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

[WIP] hash.tsv new format plus linting and auto-adding hashes #15640

Closed
wants to merge 13 commits into from
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ scripts/scramble/lib
scripts/scramble/archives

# Python virtualenv
venv
.venv
.venv3

Expand Down
4 changes: 2 additions & 2 deletions lib/galaxy/tool_util/deps/mulled/mulled_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,7 @@ def add_single_image_arguments(parser):
)


def target_str_to_targets(targets_raw):
def parse_targets(targets_raw):
fabianegli marked this conversation as resolved.
Show resolved Hide resolved
def parse_target(target_str):
if "=" in target_str:
package_name, version = target_str.split("=", 1)
Expand Down Expand Up @@ -596,7 +596,7 @@ def main(argv=None):
"The source:dest docker syntax is respected. If relative file paths are given, files will be mounted in /source/<relative_file_path>",
)
args = parser.parse_args()
targets = target_str_to_targets(args.targets)
targets = parse_targets(args.targets)
sys.exit(mull_targets(targets, **args_to_mull_targets_kwds(args)))


Expand Down
4 changes: 2 additions & 2 deletions lib/galaxy/tool_util/deps/mulled/mulled_build_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
args_to_mull_targets_kwds,
BuildExistsException,
mull_targets,
target_str_to_targets,
parse_targets,
)

KNOWN_FIELDS = ["targets", "image_build", "name_override", "base_image"]
Expand Down Expand Up @@ -101,7 +101,7 @@ def line_to_targets(line_str, line_tuple):
len(line_parts) <= n_fields
), f"Too many fields in line [{line_str}], expect at most {n_fields} - targets, image build number, and name override."
line_parts += [None] * (n_fields - len(line_parts))
line_parts[targets_column] = target_str_to_targets(line_parts[targets_column])
line_parts[targets_column] = parse_targets(line_parts[targets_column])
return line_tuple(*line_parts)


Expand Down
4 changes: 2 additions & 2 deletions lib/galaxy/tool_util/deps/mulled/mulled_hash.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"""

from ._cli import arg_parser
from .mulled_build import target_str_to_targets
from .mulled_build import parse_targets
from .util import (
v1_image_name,
v2_image_name,
Expand All @@ -24,7 +24,7 @@ def main(argv=None):
)
parser.add_argument("--hash", dest="hash", choices=["v1", "v2"], default="v2")
args = parser.parse_args()
targets = target_str_to_targets(args.targets)
targets = parse_targets(args.targets)
image_name = v2_image_name if args.hash == "v2" else v1_image_name
print(image_name(targets))

Expand Down
15 changes: 13 additions & 2 deletions lib/galaxy/tool_util/deps/mulled/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,17 @@ def _simple_image_name(targets, image_build=None):
return f"{target.package_name}{suffix}"


def sort_build_targets(build_targets):
fabianegli marked this conversation as resolved.
Show resolved Hide resolved
"""Sort build targets by package name.

>>> ordered_targets = [Target(package_name='bioblend=1.0.0', version=None, build=None, package='bioblend=1.0.0'), Target(package_name='galaxyxml=0.4.14', version=None, build=None, package='galaxyxml=0.4.14')]
>>> unordered_targets = reversed(ordered_targets)
>>> assert ordered_targets == sort_build_targets(ordered_targets)
>>> assert ordered_targets == sort_build_targets(unordered_targets)
"""
return sorted(build_targets, key=lambda t: t.package_name)


def v1_image_name(targets, image_build=None, name_override=None):
"""Generate mulled hash version 1 container identifier for supplied arguments.

Expand Down Expand Up @@ -270,7 +281,7 @@ def v1_image_name(targets, image_build=None, name_override=None):
if len(targets) == 1:
return _simple_image_name(targets, image_build=image_build)
else:
targets_order = sorted(targets, key=lambda t: t.package_name)
targets_order = sort_build_targets(targets)
requirements_buffer = "\n".join(map(conda_build_target_str, targets_order))
m = hashlib.sha1()
m.update(requirements_buffer.encode())
Expand Down Expand Up @@ -318,7 +329,7 @@ def v2_image_name(targets, image_build=None, name_override=None):
if len(targets) == 1:
return _simple_image_name(targets, image_build=image_build)
else:
targets_order = sorted(targets, key=lambda t: t.package_name)
targets_order = sort_build_targets(targets)
package_name_buffer = "\n".join(map(lambda t: t.package_name, targets_order))
package_hash = hashlib.sha1()
package_hash.update(package_name_buffer.encode())
Expand Down
4 changes: 2 additions & 2 deletions test/unit/tool_util/mulled/test_mulled_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
DEFAULT_EXTENDED_BASE_IMAGE,
InvolucroContext,
mull_targets,
target_str_to_targets,
parse_targets,
)
from ..util import external_dependency_management

Expand Down Expand Up @@ -49,6 +49,6 @@ def test_mulled_build_files_cli(use_mamba, tmpdir):

def test_target_str_to_targets():
target_str = "samtools=1.3.1--4,bedtools=2.22"
targets = target_str_to_targets(target_str)
targets = parse_targets(target_str)
assert (targets[0].package, targets[0].version, targets[0].build) == ("samtools", "1.3.1", "4")
assert (targets[1].package, targets[1].version, targets[1].build) == ("bedtools", "2.22", None)
4 changes: 2 additions & 2 deletions test/unit/tool_util/mulled/test_mulled_build_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import pytest
import yaml

from galaxy.tool_util.deps.mulled.mulled_build import target_str_to_targets
from galaxy.tool_util.deps.mulled.mulled_build import parse_targets
from galaxy.tool_util.deps.mulled.mulled_build_files import (
FALLBACK_LINE_TUPLE,
generate_targets,
Expand Down Expand Up @@ -62,7 +62,7 @@
"content, equals", [(d[k]["content"], d[k]["equals"]) for k, d in zip(TEST_IDS, TESTCASES)], ids=TEST_IDS
)
def test_generate_targets(content, equals):
equals["targets"] = target_str_to_targets(equals["targets"])
equals["targets"] = parse_targets(equals["targets"])
equals = FALLBACK_LINE_TUPLE(**equals)
with tempfile.NamedTemporaryFile(mode="w") as tmpfile:
tmpfile.write(content)
Expand Down