Graham Dumpleton
graham.dumpleton at gmail.com
Mon May 14 20:24:10 EDT 2007
On 15/05/07, Simon Holness <simon.holness at gmail.com> wrote: > normcase() could also be used just to produce the label used to key > the module within the cache, rather than performing the lookup / file > operations on a case-munged path. Thus file-system interraction (e.g. > using a case-sensitive file system where normcase doesn't expect it). > > e.g. label = self._module_label(os.path.normcase(file)) This is the change I was thinking of rather than change the full path name itself. That way any error messages at the time will be what the user used. The only thing which would show as different would be the __file__ attribute in the module may use different case to what you might originally have used when two different places use versions of path which differ by case. > This use of normcase() would only "break" things if you were loading > modules from two paths which differed only by case (after a normpath() > operation, I think?) on an OS which is (normally) case insensitive, > which is a fairly pathological and ill-advised thing to be doing. All equivalence checks in the cache are done by the label and not the path, so I don't see any cases where doing this would be a problem. > Having just looked at the code, all the os.path stuff is specific to > operating system - posix / NT / mac. I would assume that these > behaviours are also embedded pretty deeply elsewhere in python. > > I'm just a little wary about having import_path silently deviate from > its stated behaviour ("distinguishing modules by location"). One can still get unexpected behaviour if there are symlinks. One could also apply os.path.realpath() to eliminate symlink issues on platforms which support them, but this would slow things down further. Also would break code where code assumes it can use os.path.dirname(__file__) to determine a bas directory as the real file can be in a totally different location. Thus why I don't try and load just one module instance where multiple symlinks point to one physical file. > I was > watching imports carefully so spotted it, but I would imagine most > people would struggle to understand why "~/mymodule" and > "c:\mypath\mymodule" was causing the module to be loaded twice even > though it's in the same location. What are you expecting '~/' to resolve to? In the mod_python module importer '~/' is resolved to be the directory the handler was designated for. It should replace the '~/' with the actual value and if that happened to be 'c:/mypath', the final path should be the same and there should only be one module loaded, not two. Thus if you are seeing two modules may be a bug. Graham
|