88from datetime import datetime
99from functools import partial
1010from itertools import chain
11- from pathlib import Path
1211from urllib .parse import urlencode
1312
1413from pkgcheck import const as pkgcheck_const
@@ -282,7 +281,7 @@ def mk_fake_pkg(self, pkg: package, keywords: set[str]):
282281 data = {attr : str (getattr (pkg , attr .lower ())) for attr in pkg .eapi .dep_keys },
283282 )
284283
285- def find_best_match (self , restrict , pkgset : list [package ]) -> package :
284+ def find_best_match (self , restrict , pkgset : list [package ], prefer_semi_stable = True ) -> package :
286285 restrict = boolean .AndRestriction (
287286 * restrict ,
288287 packages .PackageRestriction ("properties" , values .ContainmentMatch ("live" , negate = True )),
@@ -295,18 +294,18 @@ def find_best_match(self, restrict, pkgset: list[package]) -> package:
295294 if intersect := tuple (filter (restrict .match , all_pkgs )):
296295 return max (intersect )
297296 matches = sorted (filter (restrict .match , pkgset ), reverse = True )
298- for match in matches :
299- if not all (keyword .startswith ("~" ) for keyword in match .keywords ):
300- return match
297+ if prefer_semi_stable :
298+ for match in matches :
299+ if not all (keyword .startswith ("~" ) for keyword in match .keywords ):
300+ return match
301301 return matches [0 ]
302302
303303 def extend_targets_stable_groups (self , groups ):
304304 stabilization_groups = self .options .repo .stabilization_groups
305- search_repo = self .options .search_repo
306305 for group in groups :
307306 for pkg in stabilization_groups [group ]:
308307 try :
309- yield None , self . find_best_match ([ pkg ], search_repo . match ( pkg )). versioned_atom
308+ yield None , pkg
310309 except (ValueError , IndexError ):
311310 self .err .write (f"Unable to find match for { pkg .unversioned_atom } " )
312311
@@ -339,9 +338,18 @@ def _find_dependencies(self, pkg: package, keywords: set[str]):
339338 results [match ].add (keyword )
340339 yield from results .items ()
341340
342- def build_full_graph (self , targets : list [package ]):
343- self .targets = tuple (targets )
344- check_nodes = [(pkg , set ()) for pkg in targets ]
341+ def load_targets (self , targets : list [tuple [str , str ]]):
342+ result = []
343+ search_repo = self .options .search_repo
344+ for _ , target in targets :
345+ try :
346+ result .append (self .find_best_match ([target ], search_repo .match (target ), False ))
347+ except ValueError :
348+ raise ValueError (f"Restriction { target } has no match in repository" )
349+ self .targets = tuple (result )
350+
351+ def build_full_graph (self ):
352+ check_nodes = [(pkg , set ()) for pkg in self .targets ]
345353
346354 vertices : dict [package , GraphNode ] = {}
347355 edges = []
@@ -373,7 +381,7 @@ def build_full_graph(self, targets: list[package]):
373381 for src , dst in edges :
374382 vertices [src ].edges .add (vertices [dst ])
375383 self .starting_nodes = {
376- vertices [starting_node ] for starting_node in targets if starting_node in vertices
384+ vertices [starting_node ] for starting_node in self . targets if starting_node in vertices
377385 }
378386
379387 def output_dot (self , dot_file ):
@@ -538,14 +546,6 @@ def _load_from_stdin(out: Formatter, err: Formatter):
538546 raise arghparse .ArgumentError (None , "reading from stdin is only valid when piping data in" )
539547
540548
541- def _parse_targets (search_repo , targets ):
542- for _ , target in targets :
543- try :
544- yield max (search_repo .itermatch (target ))
545- except ValueError :
546- raise ValueError (f"Restriction { target } has no match in repository" )
547-
548-
549549@bugs .bind_main_func
550550def main (options , out : Formatter , err : Formatter ):
551551 search_repo = options .search_repo
@@ -554,8 +554,8 @@ def main(options, out: Formatter, err: Formatter):
554554 options .targets .extend (d .extend_targets_stable_groups (options .sets or ()))
555555 if not options .targets :
556556 options .targets = list (_load_from_stdin (out , err ))
557- targets = list ( _parse_targets ( search_repo , options .targets ) )
558- d .build_full_graph (targets )
557+ d . load_targets ( options .targets )
558+ d .build_full_graph ()
559559 d .merge_stabilization_groups ()
560560 d .merge_cycles ()
561561 d .merge_new_keywords_children ()
0 commit comments