[Pydev-code] Another take at symlinks
Brought to you by:
fabioz
|
From: chris v. <chr...@gm...> - 2007-06-25 10:09:32
|
Hello,
I'm currently trying to make a patch which adresses the long-standing
symlink problem on Unix platforms, as I am using Ubuntu Feisty and they
have almost every library symlinked...
I have debugged this a little (using Eclipse 3.2 and the 1.3.5 zipped
src) and I've found out that this is neither a Java problem nor an
Eclipse problem; both of them can in fact handle symlinks just as one
would expect them to (I just mention this because I've seen statements
on this list claiming otherwise). It is actually Pydev's usage of
canonical vs. absolute paths which is causing the problem. pygtk.py is a
good example to show what is happening:
The file pygtk.py is physically located at
/usr/share/python-support/python-gobject/, while the pythonpath points
to /var/lib/python-support/python2.5/. But since
/var/lib/python-support/python2.5/pygtk.py is a symlink to the physical
location, python will accept an "import pygtk" without complaining.
Testing with the aforementioned file, the following behaviour can be seen:
File f = new File("/var/lib/python-support/python2.5/pygtk.py");
f.isFile() returns true
f.getCanonicalPath() returns
"/usr/share/python-support/python-gobject/pygtk.py"
This is in line with the Java Documentation which states that
getCanonicalPath() resolves symlinks. ModulesManager.changePythonPath()
contains the following code (f is pointing to the symlinked location
"/var/lib/.." retrieved by scanning the pythonpath):
String fileAbsolutePath = REF.getFileAbsolutePath(f);
String m = pythonPathHelper.resolveModule(fileAbsolutePath);
REF.getFileAbsolutePath() canonicalizes the path passed to it, so
resolveModule is called with "/usr/share/python-support/...". But
resolveModule() internally matches the passed file against pythonpath,
and since this is different from the real path (because of the resolved
symlink), it is dropped.
My question is now, why this matching is done in the first place? To
determine the package name, one could just walk up the directories and
look for __init.py__, that would be not only faster but also remove the
symlink problem. Are there any special reasons why the canonical path of
a module must be compared against pythonpath?
regards,
chris
|