From 7f98e1d74a9a51c9a3217e5047ace0f93022c629 Mon Sep 17 00:00:00 2001 From: fabianegli Date: Fri, 17 Feb 2023 16:36:41 +0100 Subject: [PATCH 01/12] extract function for package sorting --- lib/galaxy/tool_util/deps/mulled/util.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/lib/galaxy/tool_util/deps/mulled/util.py b/lib/galaxy/tool_util/deps/mulled/util.py index 78b1d7d7b5eb..c584ec4c0bb2 100644 --- a/lib/galaxy/tool_util/deps/mulled/util.py +++ b/lib/galaxy/tool_util/deps/mulled/util.py @@ -239,6 +239,17 @@ def _simple_image_name(targets, image_build=None): return f"{target.package_name}{suffix}" +def sort_build_targets(build_targets): + """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. @@ -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()) @@ -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()) From 43807f86f1543830a839102083c10f5c4c7b7b68 Mon Sep 17 00:00:00 2001 From: fabianegli Date: Wed, 1 Mar 2023 14:40:56 +0100 Subject: [PATCH 02/12] add venv to gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 321dab6ab4a0..60b509584e68 100644 --- a/.gitignore +++ b/.gitignore @@ -7,6 +7,7 @@ scripts/scramble/lib scripts/scramble/archives # Python virtualenv +venv .venv .venv3 From c9bec38366c2728ab7d5f24b75c33b784e8b9c4e Mon Sep 17 00:00:00 2001 From: fabianegli Date: Wed, 1 Mar 2023 15:08:12 +0100 Subject: [PATCH 03/12] rename function to parse a targets string --- lib/galaxy/tool_util/deps/mulled/mulled_build.py | 4 ++-- lib/galaxy/tool_util/deps/mulled/mulled_build_files.py | 4 ++-- lib/galaxy/tool_util/deps/mulled/mulled_hash.py | 4 ++-- test/unit/tool_util/mulled/test_mulled_build.py | 4 ++-- test/unit/tool_util/mulled/test_mulled_build_files.py | 4 ++-- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/lib/galaxy/tool_util/deps/mulled/mulled_build.py b/lib/galaxy/tool_util/deps/mulled/mulled_build.py index bf594c01aceb..dc848e5f9205 100644 --- a/lib/galaxy/tool_util/deps/mulled/mulled_build.py +++ b/lib/galaxy/tool_util/deps/mulled/mulled_build.py @@ -513,7 +513,7 @@ def add_single_image_arguments(parser): ) -def target_str_to_targets(targets_raw): +def parse_targets(targets_raw): def parse_target(target_str): if "=" in target_str: package_name, version = target_str.split("=", 1) @@ -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/", ) 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))) diff --git a/lib/galaxy/tool_util/deps/mulled/mulled_build_files.py b/lib/galaxy/tool_util/deps/mulled/mulled_build_files.py index 9cbfff1c6df4..5ac4bcb3dd2d 100644 --- a/lib/galaxy/tool_util/deps/mulled/mulled_build_files.py +++ b/lib/galaxy/tool_util/deps/mulled/mulled_build_files.py @@ -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"] @@ -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) diff --git a/lib/galaxy/tool_util/deps/mulled/mulled_hash.py b/lib/galaxy/tool_util/deps/mulled/mulled_hash.py index 691e4ab7e749..a5ba3e631708 100644 --- a/lib/galaxy/tool_util/deps/mulled/mulled_hash.py +++ b/lib/galaxy/tool_util/deps/mulled/mulled_hash.py @@ -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, @@ -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)) diff --git a/test/unit/tool_util/mulled/test_mulled_build.py b/test/unit/tool_util/mulled/test_mulled_build.py index ab935ac95a7a..f485970cc083 100644 --- a/test/unit/tool_util/mulled/test_mulled_build.py +++ b/test/unit/tool_util/mulled/test_mulled_build.py @@ -10,7 +10,7 @@ DEFAULT_EXTENDED_BASE_IMAGE, InvolucroContext, mull_targets, - target_str_to_targets, + parse_targets, ) from ..util import external_dependency_management @@ -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) diff --git a/test/unit/tool_util/mulled/test_mulled_build_files.py b/test/unit/tool_util/mulled/test_mulled_build_files.py index dc3f7ffd13a2..666dfe2dce56 100644 --- a/test/unit/tool_util/mulled/test_mulled_build_files.py +++ b/test/unit/tool_util/mulled/test_mulled_build_files.py @@ -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, @@ -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) From d11147e17b89e90b4446c2b3288fb434309e4e4e Mon Sep 17 00:00:00 2001 From: fabianegli Date: Fri, 3 Mar 2023 17:04:33 +0100 Subject: [PATCH 04/12] Revert "rename function to parse a targets string" This reverts commit c9bec38366c2728ab7d5f24b75c33b784e8b9c4e. --- lib/galaxy/tool_util/deps/mulled/mulled_build.py | 4 ++-- lib/galaxy/tool_util/deps/mulled/mulled_build_files.py | 4 ++-- lib/galaxy/tool_util/deps/mulled/mulled_hash.py | 4 ++-- test/unit/tool_util/mulled/test_mulled_build.py | 4 ++-- test/unit/tool_util/mulled/test_mulled_build_files.py | 4 ++-- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/lib/galaxy/tool_util/deps/mulled/mulled_build.py b/lib/galaxy/tool_util/deps/mulled/mulled_build.py index dc848e5f9205..bf594c01aceb 100644 --- a/lib/galaxy/tool_util/deps/mulled/mulled_build.py +++ b/lib/galaxy/tool_util/deps/mulled/mulled_build.py @@ -513,7 +513,7 @@ def add_single_image_arguments(parser): ) -def parse_targets(targets_raw): +def target_str_to_targets(targets_raw): def parse_target(target_str): if "=" in target_str: package_name, version = target_str.split("=", 1) @@ -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/", ) args = parser.parse_args() - targets = parse_targets(args.targets) + targets = target_str_to_targets(args.targets) sys.exit(mull_targets(targets, **args_to_mull_targets_kwds(args))) diff --git a/lib/galaxy/tool_util/deps/mulled/mulled_build_files.py b/lib/galaxy/tool_util/deps/mulled/mulled_build_files.py index 5ac4bcb3dd2d..9cbfff1c6df4 100644 --- a/lib/galaxy/tool_util/deps/mulled/mulled_build_files.py +++ b/lib/galaxy/tool_util/deps/mulled/mulled_build_files.py @@ -23,7 +23,7 @@ args_to_mull_targets_kwds, BuildExistsException, mull_targets, - parse_targets, + target_str_to_targets, ) KNOWN_FIELDS = ["targets", "image_build", "name_override", "base_image"] @@ -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] = parse_targets(line_parts[targets_column]) + line_parts[targets_column] = target_str_to_targets(line_parts[targets_column]) return line_tuple(*line_parts) diff --git a/lib/galaxy/tool_util/deps/mulled/mulled_hash.py b/lib/galaxy/tool_util/deps/mulled/mulled_hash.py index a5ba3e631708..691e4ab7e749 100644 --- a/lib/galaxy/tool_util/deps/mulled/mulled_hash.py +++ b/lib/galaxy/tool_util/deps/mulled/mulled_hash.py @@ -9,7 +9,7 @@ """ from ._cli import arg_parser -from .mulled_build import parse_targets +from .mulled_build import target_str_to_targets from .util import ( v1_image_name, v2_image_name, @@ -24,7 +24,7 @@ def main(argv=None): ) parser.add_argument("--hash", dest="hash", choices=["v1", "v2"], default="v2") args = parser.parse_args() - targets = parse_targets(args.targets) + targets = target_str_to_targets(args.targets) image_name = v2_image_name if args.hash == "v2" else v1_image_name print(image_name(targets)) diff --git a/test/unit/tool_util/mulled/test_mulled_build.py b/test/unit/tool_util/mulled/test_mulled_build.py index f485970cc083..ab935ac95a7a 100644 --- a/test/unit/tool_util/mulled/test_mulled_build.py +++ b/test/unit/tool_util/mulled/test_mulled_build.py @@ -10,7 +10,7 @@ DEFAULT_EXTENDED_BASE_IMAGE, InvolucroContext, mull_targets, - parse_targets, + target_str_to_targets, ) from ..util import external_dependency_management @@ -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 = parse_targets(target_str) + targets = target_str_to_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) diff --git a/test/unit/tool_util/mulled/test_mulled_build_files.py b/test/unit/tool_util/mulled/test_mulled_build_files.py index 666dfe2dce56..dc3f7ffd13a2 100644 --- a/test/unit/tool_util/mulled/test_mulled_build_files.py +++ b/test/unit/tool_util/mulled/test_mulled_build_files.py @@ -3,7 +3,7 @@ import pytest import yaml -from galaxy.tool_util.deps.mulled.mulled_build import parse_targets +from galaxy.tool_util.deps.mulled.mulled_build import target_str_to_targets from galaxy.tool_util.deps.mulled.mulled_build_files import ( FALLBACK_LINE_TUPLE, generate_targets, @@ -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"] = parse_targets(equals["targets"]) + equals["targets"] = target_str_to_targets(equals["targets"]) equals = FALLBACK_LINE_TUPLE(**equals) with tempfile.NamedTemporaryFile(mode="w") as tmpfile: tmpfile.write(content) From 54c2ac471194f1c4b661a3f0688777f2909826dd Mon Sep 17 00:00:00 2001 From: fabianegli Date: Wed, 15 Mar 2023 15:34:12 +0100 Subject: [PATCH 05/12] do not change test setup in test --- test/unit/tool_util/mulled/test_mulled_build_files.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/unit/tool_util/mulled/test_mulled_build_files.py b/test/unit/tool_util/mulled/test_mulled_build_files.py index dc3f7ffd13a2..e4a37b170b3f 100644 --- a/test/unit/tool_util/mulled/test_mulled_build_files.py +++ b/test/unit/tool_util/mulled/test_mulled_build_files.py @@ -56,13 +56,14 @@ """ ) TEST_IDS = [next(iter(k.keys())) for k in TESTCASES] +for idx, (test_id, test_case) in enumerate(zip(TEST_IDS, TESTCASES)): + TESTCASES[idx][test_id]["equals"]["targets"] = target_str_to_targets(test_case[test_id]["equals"]["targets"]) @pytest.mark.parametrize( "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 = FALLBACK_LINE_TUPLE(**equals) with tempfile.NamedTemporaryFile(mode="w") as tmpfile: tmpfile.write(content) From 6a0df75d6ce442db8fc931aad7393d60960bb783 Mon Sep 17 00:00:00 2001 From: fabianegli Date: Wed, 15 Mar 2023 23:03:25 +0100 Subject: [PATCH 06/12] improve legibility - removed unnecessary nesting level from TESTCASES - put parametrization on multiple lines --- test/unit/tool_util/mulled/test_mulled_build_files.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/test/unit/tool_util/mulled/test_mulled_build_files.py b/test/unit/tool_util/mulled/test_mulled_build_files.py index e4a37b170b3f..bfbf1fb8167c 100644 --- a/test/unit/tool_util/mulled/test_mulled_build_files.py +++ b/test/unit/tool_util/mulled/test_mulled_build_files.py @@ -55,13 +55,15 @@ targets: samtools """ ) -TEST_IDS = [next(iter(k.keys())) for k in TESTCASES] -for idx, (test_id, test_case) in enumerate(zip(TEST_IDS, TESTCASES)): - TESTCASES[idx][test_id]["equals"]["targets"] = target_str_to_targets(test_case[test_id]["equals"]["targets"]) +TESTCASES = {k: v for t in TESTCASES for k, v in t.items()} +for test_id, test_case in TESTCASES.items(): + TESTCASES[test_id]["equals"]["targets"] = target_str_to_targets(TESTCASES[test_id]["equals"]["targets"]) @pytest.mark.parametrize( - "content, equals", [(d[k]["content"], d[k]["equals"]) for k, d in zip(TEST_IDS, TESTCASES)], ids=TEST_IDS + "content, equals", + [(test_case["content"], test_case["equals"]) for _, test_case in TESTCASES.items()], + ids=TESTCASES.keys() ) def test_generate_targets(content, equals): equals = FALLBACK_LINE_TUPLE(**equals) From 57cb5b4326a5ac9ce28e8d3d20cc4da579eb0190 Mon Sep 17 00:00:00 2001 From: fabianegli Date: Wed, 15 Mar 2023 23:06:47 +0100 Subject: [PATCH 07/12] extract method generate_targets_from_file --- .../deps/mulled/mulled_build_files.py | 25 +++++++++++-------- .../mulled/test_mulled_build_files.py | 18 +++++++++++++ 2 files changed, 32 insertions(+), 11 deletions(-) diff --git a/lib/galaxy/tool_util/deps/mulled/mulled_build_files.py b/lib/galaxy/tool_util/deps/mulled/mulled_build_files.py index 9cbfff1c6df4..2719f574a55b 100644 --- a/lib/galaxy/tool_util/deps/mulled/mulled_build_files.py +++ b/lib/galaxy/tool_util/deps/mulled/mulled_build_files.py @@ -58,6 +58,19 @@ def main(argv=None): sys.exit(ret) +def generate_targets_from_file(target_source_file): + line_tuple = FALLBACK_LINE_TUPLE + with open(target_source_file) as f: + for line in f.readlines(): + if line: + line = line.strip() + if line.startswith("#"): + # headers can define a different column order + line_tuple = tuple_from_header(line) + else: + yield line_to_targets(line, line_tuple) + + def generate_targets(target_source): """Generate all targets from TSV files in specified file or directory.""" target_source = os.path.abspath(target_source) @@ -69,17 +82,7 @@ def generate_targets(target_source): for target_source_file in target_source_files: # If no headers are defined we use the 4 default fields in the order # that has been used in galaxy-tool-util / galaxy-lib < 20.01 - line_tuple = FALLBACK_LINE_TUPLE - with open(target_source_file) as f: - for line in f.readlines(): - if line: - line = line.strip() - if line.startswith("#"): - # headers can define a different column order - line_tuple = tuple_from_header(line) - else: - yield line_to_targets(line, line_tuple) - + yield from generate_targets_from_file(target_source_file) def tuple_from_header(header): fields = header[1:].split("\t") diff --git a/test/unit/tool_util/mulled/test_mulled_build_files.py b/test/unit/tool_util/mulled/test_mulled_build_files.py index bfbf1fb8167c..88e85ce54164 100644 --- a/test/unit/tool_util/mulled/test_mulled_build_files.py +++ b/test/unit/tool_util/mulled/test_mulled_build_files.py @@ -7,6 +7,7 @@ from galaxy.tool_util.deps.mulled.mulled_build_files import ( FALLBACK_LINE_TUPLE, generate_targets, + generate_targets_from_file, ) TESTCASES = yaml.safe_load( @@ -75,3 +76,20 @@ def test_generate_targets(content, equals): assert generated_target.image_build == equals.image_build assert generated_target.name_override == equals.name_override assert generated_target.base_image == equals.base_image + + +@pytest.mark.parametrize( + "content, equals", + [(test_case["content"], test_case["equals"]) for _, test_case in TESTCASES.items()], + ids=TESTCASES.keys() +) +def test_generate_targets_from_file(content, equals): + equals = FALLBACK_LINE_TUPLE(**equals) + with tempfile.NamedTemporaryFile(mode="w") as tmpfile: + tmpfile.write(content) + tmpfile.flush() + generated_target = next(generate_targets_from_file(tmpfile.name)) + assert generated_target.targets == equals.targets + assert generated_target.image_build == equals.image_build + assert generated_target.name_override == equals.name_override + assert generated_target.base_image == equals.base_image From b143ae44db5e2a11c5f16a00b6463108b14c1509 Mon Sep 17 00:00:00 2001 From: fabianegli Date: Thu, 16 Mar 2023 00:02:53 +0100 Subject: [PATCH 08/12] add function to build string from target --- .../tool_util/deps/mulled/mulled_build_files.py | 9 +++++++++ .../tool_util/mulled/test_mulled_build_files.py | 15 +++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/lib/galaxy/tool_util/deps/mulled/mulled_build_files.py b/lib/galaxy/tool_util/deps/mulled/mulled_build_files.py index 2719f574a55b..dd5ee8d769e3 100644 --- a/lib/galaxy/tool_util/deps/mulled/mulled_build_files.py +++ b/lib/galaxy/tool_util/deps/mulled/mulled_build_files.py @@ -108,6 +108,15 @@ def line_to_targets(line_str, line_tuple): return line_tuple(*line_parts) +def str_from_target(target): + target_str = target.package + if target.version: + target_str += "=" + target.version + if target.build: + target_str += "--" + target.build + return target_str + + __all__ = ("main",) diff --git a/test/unit/tool_util/mulled/test_mulled_build_files.py b/test/unit/tool_util/mulled/test_mulled_build_files.py index 88e85ce54164..a0ca90d412a7 100644 --- a/test/unit/tool_util/mulled/test_mulled_build_files.py +++ b/test/unit/tool_util/mulled/test_mulled_build_files.py @@ -8,7 +8,9 @@ FALLBACK_LINE_TUPLE, generate_targets, generate_targets_from_file, + str_from_target, ) +from galaxy.tool_util.deps.mulled.util import build_target TESTCASES = yaml.safe_load( r""" @@ -93,3 +95,16 @@ def test_generate_targets_from_file(content, equals): assert generated_target.image_build == equals.image_build assert generated_target.name_override == equals.name_override assert generated_target.base_image == equals.base_image + + +def test_str_from_target(): + target_str = "atarget" + assert target_str == str_from_target(build_target(target_str)) + + version = "0.1" + target_str_versioned = f"{target_str}={version}" + assert target_str_versioned == str_from_target(build_target(target_str, version)) + + build = "2" + target_str_version_build = f"{target_str}={version}--{build}" + assert target_str_version_build == str_from_target(build_target(target_str, version, build)) From 1be3d786f15a50641626ec0cd68895892a74419a Mon Sep 17 00:00:00 2001 From: fabianegli Date: Thu, 16 Mar 2023 00:17:36 +0100 Subject: [PATCH 09/12] iterate over keys instead of items --- test/unit/tool_util/mulled/test_mulled_build_files.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/unit/tool_util/mulled/test_mulled_build_files.py b/test/unit/tool_util/mulled/test_mulled_build_files.py index a0ca90d412a7..ecb50a91bacf 100644 --- a/test/unit/tool_util/mulled/test_mulled_build_files.py +++ b/test/unit/tool_util/mulled/test_mulled_build_files.py @@ -59,8 +59,8 @@ """ ) TESTCASES = {k: v for t in TESTCASES for k, v in t.items()} -for test_id, test_case in TESTCASES.items(): - TESTCASES[test_id]["equals"]["targets"] = target_str_to_targets(TESTCASES[test_id]["equals"]["targets"]) +for key in TESTCASES: + TESTCASES[key]["equals"]["targets"] = target_str_to_targets(TESTCASES[key]["equals"]["targets"]) @pytest.mark.parametrize( From 673908f20b03a7f12a60b1336e00e1bb30876075 Mon Sep 17 00:00:00 2001 From: Fabian Egli Date: Thu, 16 Mar 2023 00:27:07 +0100 Subject: [PATCH 10/12] add type annotations to sort_build_targets Co-authored-by: Nicola Soranzo --- lib/galaxy/tool_util/deps/mulled/util.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/galaxy/tool_util/deps/mulled/util.py b/lib/galaxy/tool_util/deps/mulled/util.py index c584ec4c0bb2..f39056cc266d 100644 --- a/lib/galaxy/tool_util/deps/mulled/util.py +++ b/lib/galaxy/tool_util/deps/mulled/util.py @@ -239,7 +239,7 @@ def _simple_image_name(targets, image_build=None): return f"{target.package_name}{suffix}" -def sort_build_targets(build_targets): +def sort_build_targets(build_targets: List[Target]) -> List[Target]: """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')] From b010164dafc04b1d8e18afa4966b1d27204140eb Mon Sep 17 00:00:00 2001 From: fabianegli Date: Thu, 16 Mar 2023 00:35:54 +0100 Subject: [PATCH 11/12] fix whitespace linting issues --- lib/galaxy/tool_util/deps/mulled/mulled_build_files.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/galaxy/tool_util/deps/mulled/mulled_build_files.py b/lib/galaxy/tool_util/deps/mulled/mulled_build_files.py index dd5ee8d769e3..eea028f535c4 100644 --- a/lib/galaxy/tool_util/deps/mulled/mulled_build_files.py +++ b/lib/galaxy/tool_util/deps/mulled/mulled_build_files.py @@ -70,7 +70,7 @@ def generate_targets_from_file(target_source_file): else: yield line_to_targets(line, line_tuple) - + def generate_targets(target_source): """Generate all targets from TSV files in specified file or directory.""" target_source = os.path.abspath(target_source) @@ -84,6 +84,7 @@ def generate_targets(target_source): # that has been used in galaxy-tool-util / galaxy-lib < 20.01 yield from generate_targets_from_file(target_source_file) + def tuple_from_header(header): fields = header[1:].split("\t") for field in fields: From 5ca171f8c0dbb32767515db6fdbb2991a573462f Mon Sep 17 00:00:00 2001 From: fabianegli Date: Thu, 16 Mar 2023 02:23:56 +0100 Subject: [PATCH 12/12] fix formatting --- lib/galaxy/tool_util/deps/mulled/util.py | 2 +- test/unit/tool_util/mulled/test_mulled_build_files.py | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/galaxy/tool_util/deps/mulled/util.py b/lib/galaxy/tool_util/deps/mulled/util.py index f39056cc266d..4d0b0f3cb42e 100644 --- a/lib/galaxy/tool_util/deps/mulled/util.py +++ b/lib/galaxy/tool_util/deps/mulled/util.py @@ -241,7 +241,7 @@ def _simple_image_name(targets, image_build=None): def sort_build_targets(build_targets: List[Target]) -> List[Target]: """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) diff --git a/test/unit/tool_util/mulled/test_mulled_build_files.py b/test/unit/tool_util/mulled/test_mulled_build_files.py index ecb50a91bacf..cf0d23cea218 100644 --- a/test/unit/tool_util/mulled/test_mulled_build_files.py +++ b/test/unit/tool_util/mulled/test_mulled_build_files.py @@ -64,9 +64,9 @@ @pytest.mark.parametrize( - "content, equals", - [(test_case["content"], test_case["equals"]) for _, test_case in TESTCASES.items()], - ids=TESTCASES.keys() + "content, equals", + [(test_case["content"], test_case["equals"]) for _, test_case in TESTCASES.items()], + ids=TESTCASES.keys(), ) def test_generate_targets(content, equals): equals = FALLBACK_LINE_TUPLE(**equals) @@ -82,8 +82,8 @@ def test_generate_targets(content, equals): @pytest.mark.parametrize( "content, equals", - [(test_case["content"], test_case["equals"]) for _, test_case in TESTCASES.items()], - ids=TESTCASES.keys() + [(test_case["content"], test_case["equals"]) for _, test_case in TESTCASES.items()], + ids=TESTCASES.keys(), ) def test_generate_targets_from_file(content, equals): equals = FALLBACK_LINE_TUPLE(**equals)