22import os
33import re
44import sys
5+ from pathlib import Path
56from subprocess import call
67from uuid import uuid1
78
@@ -172,35 +173,33 @@ def get_step_positions(self, file_name):
172173 positions = []
173174 for step , infos in self .__steps_map .items ():
174175 positions = positions + [{'stepValue' : step , 'span' : i .span }
175- for i in infos if str (i .file_name ). lower () == str ( file_name ). lower ( )]
176+ for i in infos if paths_equal (i .file_name , file_name )]
176177 return positions
177178
178179 def _get_all_hooks (self , file_name ):
179180 all_hooks = []
180181 for hook in self .hooks :
181182 all_hooks = all_hooks + \
182- [h for h in getattr (self , "__{}" .format (hook ))
183- if str (h .file_name ). lower () == str ( file_name ). lower ( )]
183+ [h for h in getattr (self , "__{}" .format (hook ))
184+ if paths_equal (h .file_name , file_name )]
184185 return all_hooks
185186
186187 def get_all_methods_in (self , file_name ):
187188 methods = []
188189 for _ , infos in self .__steps_map .items ():
189- # Using relative paths may lead to different spelling of the C drive (lower or capital C)
190- methods = methods + [i for i in infos if str (i .file_name ).lower () == str (file_name ).lower ()]
190+ methods = methods + [i for i in infos if paths_equal (i .file_name , file_name )]
191191 return methods + self ._get_all_hooks (file_name )
192192
193193 def is_file_cached (self , file_name ):
194194 for _ , infos in self .__steps_map .items ():
195- # Using relative paths may lead to different spelling of the C drive (lower or capital C)
196- if any (str (i .file_name ).lower () == str (file_name ).lower () for i in infos ):
195+ if any (Path (i .file_name ).resolve () == Path (file_name ).resolve () for i in infos ):
197196 return True
198197 return False
199198
200199 def remove_steps (self , file_name ):
201200 new_map = {}
202201 for step , infos in self .__steps_map .items ():
203- filtered_info = [i for i in infos if i .file_name != file_name ]
202+ filtered_info = [i for i in infos if not paths_equal ( i .file_name , file_name ) ]
204203 if len (filtered_info ) > 0 :
205204 new_map [step ] = filtered_info
206205 self .__steps_map = new_map
@@ -211,6 +210,17 @@ def clear(self):
211210 setattr (self , '__{}' .format (hook ), [])
212211
213212
213+ def paths_equal (p1 : str | Path , p2 : str | Path ) -> bool :
214+ """
215+ Compare two paths in a cross-platform safe way.
216+ On Windows: case-insensitive, slash-insensitive.
217+ On Linux/macOS: case-sensitive.
218+ """
219+ p1 = Path (p1 ).resolve ()
220+ p2 = Path (p2 ).resolve ()
221+ return os .path .normcase (str (p1 )) == os .path .normcase (str (p2 ))
222+
223+
214224def _filter_hooks (tags , hooks ):
215225 filtered_hooks = []
216226 for hook in hooks :
0 commit comments