88import os
99import threading
1010from copy import deepcopy
11- from typing import TYPE_CHECKING
11+ from typing import (
12+ Any ,
13+ Dict ,
14+ FrozenSet ,
15+ Iterable ,
16+ List ,
17+ Optional ,
18+ Set ,
19+ Tuple ,
20+ TYPE_CHECKING ,
21+ Union ,
22+ )
1223
1324from galaxy .tool_util .deps import conda_util
14- from galaxy .tool_util .deps .conda_util import CondaContext
25+ from galaxy .tool_util .deps .conda_util import (
26+ CondaContext ,
27+ CondaTarget ,
28+ )
1529from galaxy .util import unicodify
1630
1731from planemo .exit_codes import (
@@ -43,7 +57,7 @@ def build_conda_context(ctx: "PlanemoCliContext", **kwds) -> CondaContext:
4357 condarc_override = kwds .get ("condarc" , condarc_override_default )
4458 use_local = kwds .get ("conda_use_local" , False )
4559 shell_exec = shell if use_planemo_shell else None
46- conda_context = conda_util . CondaContext (
60+ conda_context = CondaContext (
4761 conda_prefix = conda_prefix ,
4862 ensure_channels = ensure_channels ,
4963 condarc_override = condarc_override ,
@@ -100,21 +114,23 @@ def collect_conda_targets(ctx, paths, recursive=False, found_tool_callback=None)
100114
101115
102116# Copied and modified from mulled stuff - need to syncronize these concepts.
103- def target_str_to_targets (targets_raw ) :
104- def parse_target (target_str ) :
117+ def target_str_to_targets (targets_raw : str ) -> List [ CondaTarget ] :
118+ def parse_target (target_str : str ) -> CondaTarget :
105119 if "=" in target_str :
106120 package_name , version = target_str .split ("=" , 1 )
107121 else :
108122 package_name = target_str
109123 version = None
110- target = conda_util . CondaTarget (package_name , version )
124+ target = CondaTarget (package_name , version )
111125 return target
112126
113127 targets = [parse_target (_ ) for _ in targets_raw .split ("," )]
114128 return targets
115129
116130
117- def collect_conda_target_lists (ctx , paths , recursive = False , found_tool_callback = None ):
131+ def collect_conda_target_lists (
132+ ctx : "PlanemoCliContext" , paths : Iterable [str ], recursive : bool = False , found_tool_callback = None
133+ ) -> List [FrozenSet [CondaTarget ]]:
118134 """Load CondaTarget lists from supplied artifact sources.
119135
120136 If a tool contains more than one requirement, the requirements will all
@@ -126,26 +142,28 @@ def collect_conda_target_lists(ctx, paths, recursive=False, found_tool_callback=
126142 return conda_target_lists
127143
128144
129- def collect_conda_target_lists_and_tool_paths (ctx , paths , recursive = False , found_tool_callback = None ):
145+ def collect_conda_target_lists_and_tool_paths (
146+ ctx : "PlanemoCliContext" , paths : Iterable [str ], recursive : bool = False , found_tool_callback = None
147+ ) -> Tuple [List [FrozenSet [CondaTarget ]], List [List [str ]]]:
130148 """Load CondaTarget lists from supplied artifact sources.
131149
132150 If a tool contains more than one requirement, the requirements will all
133151 appear together as one list element of the output list.
134152 """
135- conda_target_lists = set ()
153+ conda_target_sets : Set [ FrozenSet [ CondaTarget ]] = set ()
136154 tool_paths = collections .defaultdict (list )
137155 for tool_path , tool_source in yield_tool_sources_on_paths (ctx , paths , recursive = recursive , yield_load_errors = False ):
138156 try :
139157 if found_tool_callback :
140158 found_tool_callback (tool_path )
141159 targets = frozenset (tool_source_conda_targets (tool_source ))
142- conda_target_lists .add (targets )
160+ conda_target_sets .add (targets )
143161 tool_paths [targets ].append (tool_path )
144162 except Exception as e :
145163 ctx .log (f"Error while collecting list of conda targets for '{ tool_path } ': { unicodify (e )} " )
146164
147165 # Turn them into lists so the order matches before returning...
148- conda_target_lists = list (conda_target_lists )
166+ conda_target_lists = list (conda_target_sets )
149167 conda_target_tool_paths = [tool_paths [c ] for c in conda_target_lists ]
150168
151169 return conda_target_lists , conda_target_tool_paths
@@ -160,7 +178,9 @@ def tool_source_conda_targets(tool_source):
160178best_practice_search_first = threading .local ()
161179
162180
163- def best_practice_search (conda_target , conda_context = None , platform = None ):
181+ def best_practice_search (
182+ conda_target : CondaTarget , conda_context : Optional [CondaContext ] = None , platform : Optional [str ] = None
183+ ) -> Union [Tuple [None , None ], Tuple [Dict [str , Any ], bool ]]:
164184 # Call it in offline mode after the first time.
165185 try :
166186 best_practice_search_first .previously_called
@@ -175,7 +195,7 @@ def best_practice_search(conda_target, conda_context=None, platform=None):
175195 conda_context = deepcopy (conda_context )
176196 conda_context .ensure_channels = BEST_PRACTICE_CHANNELS
177197 else :
178- conda_context = conda_util . CondaContext (ensure_channels = BEST_PRACTICE_CHANNELS )
198+ conda_context = CondaContext (ensure_channels = BEST_PRACTICE_CHANNELS )
179199 return conda_util .best_search_result (
180200 conda_target ,
181201 conda_context = conda_context ,
0 commit comments