This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: "python-config --includes" returns a wrong path (double prefix)
Type: behavior Stage: resolved
Components: Build Versions: Python 3.8, Python 3.7, Python 3.6, Python 3.4, Python 3.5
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: Michael.Dussere, animus, benjamin.peterson, mgorny, rdossin, serhiy.storchaka
Priority: normal Keywords: patch

Created on 2014-08-05 13:28 by Michael.Dussere, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
patch_python_sym_links.txt rdossin, 2015-07-22 10:45 review
Pull Requests
URL Status Linked Edit
PR 3769 merged mgorny, 2017-09-26 15:13
PR 3793 merged benjamin.peterson, 2017-09-28 03:23
Messages (7)
msg224825 - (view) Author: Michael Dussere (Michael.Dussere) Date: 2014-08-05 13:28
Our python is installed on a shared directory that is accessed through a symbolic link. 
$ which python3.4-config
/Produits/publics/x86_64.Linux.RH6/python/3.4.1/bin/python3.4-config

$ ls -al /Produits
lrwxrwxrwx 1 root root 13 Oct 31  2013 /Produits -> /nfs/Produits

With this configuration python-config returns a wrong path (it gives a double /nfs prefix)

$ python3.4-config --includes
-I/nfs/nfs/Produits/publics/x86_64.Linux.RH6/python/3.4.1/include/python3.4m -I/nfs/nfs/Produits/publics/x86_64.Linux.RH6/python/3.4.1/include/python3.4m


The problem is due to a double string replacement in the script

   prefix_build="/Produits/publics/x86_64.Linux.RH6/python/3.4.1"
   prefix_real=$(installed_prefix "$0")

   # Use sed to fix paths from their built-to locations to their installed-to
   # locations.
   prefix=$(echo "$prefix_build" | sed "s#$prefix_build#$prefix_real#")
   exec_prefix_build="${prefix}"
   exec_prefix=$(echo "$exec_prefix_build" | sed "s#$exec_prefix_build#$prefix_real#")
   includedir=$(echo "${prefix}/include" | sed "s#$prefix_build#$prefix_real#")

for $includedir the replacement of $prefix_build by $prefix_real is applyed twice and since the $prefix_real contains $prefix_build it produce a wrong result.

In addition I think it is strange to have lines like the following
prefix=$(echo "$prefix_build" | sed "s#$prefix_build#$prefix_real#")
msg231307 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2014-11-18 07:19
Do you want to provide a patch?
msg247108 - (view) Author: Romain Dossin (rdossin) * Date: 2015-07-22 10:45
I stumbled across the exact same problem and I have made a fix that is working, at least for the usage I have...
msg249003 - (view) Author: Alexey Gorshkov (animus) Date: 2015-08-23 09:41
I don't understand: Why python-config needs to seek "realpath"? Why python-config is trying to be smarter than one who starts ./configure script?

As so, the right thing to this, is remove "smart" parts from python-config. But as for fast hack in to this is replace line 'prefix_real=$(installed_prefix "$0")' with 'prefix_real=$prefix_build'.
msg303045 - (view) Author: Michał Górny (mgorny) * Date: 2017-09-26 15:16
I've submitted a pull request with another fix. I've tried to keep the changes at minimal but I couldn't stand keeping meaningless 'echo $x | sed -e s/$x/$y/' ;-).

I have to point out that the attached patch is wrong since it does readlink on CFLAGS &c.
msg303096 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2017-09-27 05:45
New changeset 14086cfc5eed8c5e78342d79e5db87a135d75fa8 by Benjamin Peterson (Michał Górny) in branch 'master':
closes bpo-22140: Prevent double substitution of prefix in python-config.sh (#3769)
https://github.com/python/cpython/commit/14086cfc5eed8c5e78342d79e5db87a135d75fa8
msg303188 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2017-09-28 03:27
New changeset 68b131d5b674549bb637b366730497714ad11328 by Benjamin Peterson in branch '3.6':
[3.6] closes bpo-22140: Prevent double substitution of prefix in python-config.sh (GH-3769) (#3793)
https://github.com/python/cpython/commit/68b131d5b674549bb637b366730497714ad11328
History
Date User Action Args
2022-04-11 14:58:06adminsetgithub: 66338
2020-11-27 14:00:05iritkatriellinkissue31713 superseder
2017-09-28 03:27:44benjamin.petersonsetmessages: + msg303188
2017-09-28 03:23:50benjamin.petersonsetpull_requests: + pull_request3777
2017-09-27 05:45:08benjamin.petersonsetstatus: open -> closed

nosy: + benjamin.peterson
messages: + msg303096

resolution: fixed
stage: patch review -> resolved
2017-09-26 15:16:52mgornysetmessages: + msg303045
versions: + Python 3.5, Python 3.6, Python 3.7, Python 3.8
2017-09-26 15:13:21mgornysetkeywords: + patch
stage: needs patch -> patch review
pull_requests: + pull_request3754
2017-09-25 17:44:22mgornysetnosy: + mgorny
2015-08-23 09:41:05animussetnosy: + animus
messages: + msg249003
2015-07-22 10:45:56rdossinsetfiles: + patch_python_sym_links.txt
nosy: + rdossin
messages: + msg247108

2014-11-18 07:19:37serhiy.storchakasetnosy: + serhiy.storchaka
messages: + msg231307

components: + Build, - Demos and Tools
stage: needs patch
2014-08-05 13:28:32Michael.Dusserecreate