1818from  functools  import  wraps 
1919from  .mparser  import  Token , ArrayNode , ArgumentNode , ArithmeticNode , AssignmentNode , BaseNode , StringNode , BooleanNode , ElementaryNode , IdNode , FunctionNode , PlusAssignmentNode 
2020from  .mintro  import  IntrospectionEncoder 
21+ from  .utils .universal  import  pathname_sort_key 
2122import  json , os , re , sys , codecs 
2223import  typing  as  T 
2324from  pathlib  import  Path 
@@ -951,15 +952,6 @@ def rel_source(src: str) -> str:
951952
952953        # Sort files 
953954        for  i  in  to_sort_nodes :
954-             def  convert (text : str ) ->  T .Union [int , str ]:
955-                 return  int (text ) if  text .isdigit () else  text .lower ()
956- 
957-             def  alphanum_key (key : str ) ->  T .List [T .Union [int , str ]]:
958-                 return  [convert (c ) for  c  in  re .split ('([0-9]+)' , key )]
959- 
960-             def  path_sorter (key : str ) ->  T .List [T .Tuple [bool , T .List [T .Union [int , str ]]]]:
961-                 return  [(key .count ('/' ) <=  idx , alphanum_key (x )) for  idx , x  in  enumerate (key .split ('/' ))]
962- 
963955            if  isinstance (i , FunctionNode ) and  i .func_name .value  in  BUILD_TARGET_FUNCTIONS :
964956                src_args  =  i .args .arguments [1 :]
965957                target_name  =  [i .args .arguments [0 ]]
@@ -968,7 +960,7 @@ def path_sorter(key: str) -> T.List[T.Tuple[bool, T.List[T.Union[int, str]]]]:
968960                target_name  =  []
969961            unknown : T .List [BaseNode ] =  [x  for  x  in  src_args  if  not  isinstance (x , StringNode )]
970962            sources : T .List [StringNode ] =  [x  for  x  in  src_args  if  isinstance (x , StringNode )]
971-             sources  =  sorted (sources , key = lambda  x : path_sorter (x .value ))
963+             sources  =  sorted (sources , key = lambda  x : pathname_sort_key (x .value ))
972964            i .args .arguments  =  target_name  +  unknown  +  T .cast (T .List [BaseNode ], sources )
973965
974966    def  process (self , cmd : T .Dict [str , T .Any ]) ->  None :
0 commit comments