Re: [PATCH] Scripts in contrib/ and relative paths
Michael Haggerty <[email protected]> Fri, 26 Mar 2010 12:41:27 +0100
| Newsgroups | gmane.comp.version-control.subversion.cvs2svn.devel |
|---|---|
| Message-ID | <[email protected]> |
Jon Foster wrote: > I came across this minor bug: > >> ~/cvs2svn-trunk/contrib$ ./destroy_repository.py >> Traceback (most recent call last): >> File "./destroy_repository.py", line 113, in <module> >> from cvs2svn_lib.key_generator import KeyGenerator >> ImportError: No module named cvs2svn_lib.key_generator > > It works if I specify the absolute path: > >> ~/cvs2svn-trunk/contrib$ `pwd`/destroy_repository.py >> [...usage message, as expected...] > > The problem is that destroy_repository.py automatically finds the > cvs2svn libraries by taking the script path, then chopping off the > last directory component. But because I didn't specify the full > path, there wasn't a "last directory component" to chop off. The > fix is just to insert a call to abspath() in the appropriate place. Good catch. I've seen this problem in other Python code lately but forgot to look for it in the cvs2svn project. > After fixing that, there's a similar-but-different bug when using > pychecker: > >> ~/cvs2svn-trunk/contrib$ pychecker destroy_repository.py >> Processing destroy_repository... >> ImportError: No module named cvs2svn_lib.key_generator > > In this case, the problem is that sys.argv[0] points to pychecker, > not destroy_repository.py. This can be fixed by using __file__ > instead, which is a special Python variable that gives the path > to the current source file. > > Patch attached, that fixes all the occurances of this code. I see that in your patch you added the abspath() but didn't switch to using __file__ instead of sys.argv[0]. Is there a reason for that? Michael ------------------------------------------------------ http://cvs2svn.tigris.org/ds/viewMessage.do?dsForumId=1667&dsMessageId=2465390 To unsubscribe from this discussion, e-mail: [[email protected]].