classification
Title: Remove trailing slash from --prefix
Type: behavior Stage: patch review
Components: Build, Installation Versions: Python 3.0, Python 2.6
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: collinwinter, georg.brandl, loewis, sonderblade
Priority: normal Keywords: patch

Created on 2007-03-07 22:30 by sonderblade, last changed 2009-03-31 21:46 by georg.brandl. This issue is now closed.

Files
File name Uploaded Description Edit
fix-prefix-with-trailing-slash-problem.patch sonderblade, 2007-03-07 22:30 Ensure that $prefix does not have a trailing backslash
fix-prefix-with-trailing-slash-problem-2.patch sonderblade, 2007-03-20 22:06 Same patch, take 2
fix-prefix-with-trailing-slash-problem-3.patch sonderblade, 2007-03-27 23:40 take 3
Messages (14)
msg52101 - (view) Author: Björn Lindqvist (sonderblade) Date: 2007-03-07 22:30
Two tests in test_inspect.py failed for me with the following traceback:

======================================================================
FAIL: test_stack (__main__.TestInterpreterStack)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "test/test_inspect.py", line 92, in test_stack
    (modfile, 16, 'eggs', ['    st = inspect.stack()\n'], 0))
AssertionError: ('/tmp/install//lib/python2.6/test/inspect_fodder.py', 16, 'eggs', ['    st = inspect.stack()\n'], 0) != ('/tmp/install/lib/python2.6/test/inspect_fodder.py', 16, 'eggs', ['    st = inspect.stack()\n'], 0)

This happened because I configured Python with "./configure --prefix=/tmp/install/" and autoconf automagically created paths such as ${prefix}/lib so it got a double slash. 

Double slashes are completely harmless on Unix and test_inspect.py is probably wrong in comparing two paths like that. Nevertheless, they are ugly and I think it is worthwhile to eliminate them. So here is patch that does that by adding a "hack" to configure.in.
msg52102 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2007-03-08 08:08
Does this work if the prefix is "/"?
msg52103 - (view) Author: Björn Lindqvist (sonderblade) Date: 2007-03-08 20:15
It does. Autoconf sees that prefix is the empty string "", but as the variable is defined it does not replace it with the default /usr/local. So it should be safe. Although it would be nice if someone else could test it too.
msg52104 - (view) Author: Collin Winter (collinwinter) * (Python committer) Date: 2007-03-12 17:37
I think I'd rather fix the tests, using something like os.path.normpath().
msg52105 - (view) Author: Björn Lindqvist (sonderblade) Date: 2007-03-13 23:05
Yes, that could be fixed too. But all tracebacks originating from the standard library also get the double slash:

>>> import fnmatch
>>> fnmatch.filter(1, 2)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/bjourne/install//lib/python2.6/fnmatch.py", line 46, in filter
    res = translate(pat)
  File "/home/bjourne/install//lib/python2.6/fnmatch.py", line 78, in translate
    i, n = 0, len(pat)
TypeError: object of type 'int' has no len()

IMHO, that is ugly enough that it ought to be fixed.
msg52106 - (view) Author: Collin Winter (collinwinter) * (Python committer) Date: 2007-03-16 02:49
Sounds good to me. How about you, Georg?
msg52107 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2007-03-16 08:26
I'd still specialcase prefix == "/". Currently, with your patch it ends up as
sys.prefix == "", which is bad if someone does

x = os.path.join(sys.prefix, "lib", ...)

I think who configures with --prefix=/ can live with the double slashes.
msg52108 - (view) Author: Björn Lindqvist (sonderblade) Date: 2007-03-16 12:27
Ok, I'll add a specialcase for that which should be trivial. Also, the manual for sys.prefix is a little vague and probably needs an update. 
msg52109 - (view) Author: Björn Lindqvist (sonderblade) Date: 2007-03-20 22:06
File Added: fix-prefix-with-trailing-slash-problem-2.patch
msg52110 - (view) Author: Björn Lindqvist (sonderblade) Date: 2007-03-20 22:08
New patch fixes your concern Georg.
msg52111 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2007-03-21 08:56
Okay, thanks.
Martin, you know how to do the configure magic properly, do you want to commit this?
msg52112 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2007-03-21 14:20
I think the problem with this patch is that % substitution is not widely available in /bin/sh. For example, on Solaris 9, /bin/sh gives 'bad substitution'. Even /usr/xpg4/bin/sh rejects it. So I think this should be redone using, say, sed.
msg52113 - (view) Author: Björn Lindqvist (sonderblade) Date: 2007-03-27 23:40
Here is patch with sed instead. I hope this should be safe because all variants of UNIX should have sed I think.
File Added: fix-prefix-with-trailing-slash-problem-3.patch
msg84925 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2009-03-31 21:46
Changed a bit (seems that backslash before the $ in the regex isn't
necessary) and checked in in r70903.
History
Date User Action Args
2009-03-31 21:46:04georg.brandlsetstatus: open -> closed
resolution: fixed
messages: + msg84925
2009-03-30 22:09:15ajaksu2setstage: patch review
type: behavior
components: + Installation
versions: + Python 2.6, Python 3.0
2007-03-07 22:30:39sonderbladecreate