Skip to contentSkip to conversation

python: fix interpreter directive for python scripts

PATCH Superseded Jonathan Liu 4 participants 7 messages Aug 11, 2012 – Aug 12, 2012

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 python: fix interpreter directive for python scripts

---
 package/python/python.mk | 7 +++++++
 1 file changed, 7 insertions(+)
package/python/python.mk +7 -0
index fae4e5c..783b7b8 100644
@@ -165,6 +165,13 @@ endef
 
 PYTHON_POST_INSTALL_TARGET_HOOKS += PYTHON_REMOVE_USELESS_FILES
 
+# Fix Python interpreter directive
+define PYTHON_FIX_INTERPRETER
+        sed -i '1s|#!.*python.*|#!/usr/bin/env python|' $(TARGET_DIR)/usr/bin/{easy_install,easy_install-2.7,idle,smtpd.py}
+endef
+
+PYTHON_POST_INSTALL_TARGET_HOOKS += PYTHON_FIX_INTERPRETER
+
 PYTHON_AUTORECONF = YES
 
 $(eval $(autotools-package))
Signature · 1 line
1.7.11.3
#1 lore raw

PATCH 1/1 python: fix interpreter directive for python scripts

Le Sat, 11 Aug 2012 16:10:27 +1000,
Jonathan Liu <[email protected]> a ?crit :

package/python/python.mk endef · line 173

Quoted 6 lines
package/python/python.mk +6 -0
+# Fix Python interpreter directive
+define PYTHON_FIX_INTERPRETER
+        sed -i '1s|#!.*python.*|#!/usr/bin/env python|' $(TARGET_DIR)/usr/bin/{easy_install,easy_install-2.7,idle,smtpd.py}
+endef
+
+PYTHON_POST_INSTALL_TARGET_HOOKS += PYTHON_FIX_INTERPRETER

I agree the paths in those scripts is incorrect, *but*:

* Should these scripts have been installed in the first place? I don't think there are useful for the typical usage of the Python interpreter, so maybe we want to get rid of them.

* Instead of fixing this patch manually in every Python script installed, can we investigate on how to fix the root of the problem? I'm the one who has reworked the patches that get Python to cross-compile, and I know this stuff is really painful, but I think it's worth at least trying to understand a bit if there could be a way of handling things. From what I remember the problem is that the host-python uses its host sysconfig parameters even when building things for the target, simply because the whole Python things has absolutely zero understanding of the fact that we could be using Python on one machine to build stuff that will run on a different machine.

Thoughts?

Thomas

Signature · 4 lines
Thomas Petazzoni, Free Electrons
Kernel, drivers, real-time and embedded Linux
development, consulting, training and support.
http://free-electrons.com
#2 lore raw

PATCH 1/1 python: fix interpreter directive for python scripts

Quoted 11 lines · Thomas Petazzoni

Le Sat, 11 Aug 2012 16:10:27 +1000,
Jonathan Liu<[email protected]> a ?crit :

package/python/python.mk endef · line 173

Quoted 6 lines
package/python/python.mk +6 -0
+# Fix Python interpreter directive
+define PYTHON_FIX_INTERPRETER
+        sed -i '1s|#!.*python.*|#!/usr/bin/env python|' $(TARGET_DIR)/usr/bin/{easy_install,easy_install-2.7,idle,smtpd.py}
+endef
+
+PYTHON_POST_INSTALL_TARGET_HOOKS += PYTHON_FIX_INTERPRETER

I agree the paths in those scripts is incorrect, *but*:

Quoted 3 lines

* Should these scripts have been installed in the first place? I don't think there are useful for the typical usage of the Python interpreter, so maybe we want to get rid of them.

Perhaps we could add a config option later on to not install idle and smtpd.py.

Quoted 12 lines

* Instead of fixing this patch manually in every Python script installed, can we investigate on how to fix the root of the problem? I'm the one who has reworked the patches that get Python to cross-compile, and I know this stuff is really painful, but I think it's worth at least trying to understand a bit if there could be a way of handling things. From what I remember the problem is that the host-python uses its host sysconfig parameters even when building things for the target, simply because the whole Python things has absolutely zero understanding of the fact that we could be using Python on one machine to build stuff that will run on a different machine.

easy_install and easy_install-2.7 shouldn't be in there apparently. It's part of setuptools package.
I've submitted a V2 patch so it only fixes idle and smtpd.py in python package. The V2 patch is independant of this setuptools interpreter directive issue.

I will see if I can look into fixing the interpreter for the setuptools package.

Regards,
Jonathan

#3 lore raw

PATCH 1/1 python: fix interpreter directive for python scripts

In reply to Thomas Petazzoni
Quoted 15 lines · Thomas Petazzoni

Le Sat, 11 Aug 2012 16:10:27 +1000,
Jonathan Liu<[email protected]> a ?crit :

package/python/python.mk endef · line 173

Quoted 6 lines
package/python/python.mk +6 -0
+# Fix Python interpreter directive
+define PYTHON_FIX_INTERPRETER
+        sed -i '1s|#!.*python.*|#!/usr/bin/env python|' $(TARGET_DIR)/usr/bin/{easy_install,easy_install-2.7,idle,smtpd.py}
+endef
+
+PYTHON_POST_INSTALL_TARGET_HOOKS += PYTHON_FIX_INTERPRETER

I agree the paths in those scripts is incorrect, *but*:

* Should these scripts have been installed in the first place? I don't think there are useful for the typical usage of the Python interpreter, so maybe we want to get rid of them.

Quoted 11 lines

* Instead of fixing this patch manually in every Python script installed, can we investigate on how to fix the root of the problem? I'm the one who has reworked the patches that get Python to cross-compile, and I know this stuff is really painful, but I think it's worth at least trying to understand a bit if there could be a way of handling things. From what I remember the problem is that the host-python uses its host sysconfig parameters even when building things for the target, simply because the whole Python things has absolutely zero understanding of the fact that we could be using Python on one machine to build stuff that will run on a different machine.

I've submitted patch for Python to use fixed path for sys.executable to resolve this.

Regards,
Jonathan

#4 lore raw

PATCH 1/1 python: fix interpreter directive for python scripts

I've just ran into this kind of problem. It can be solved per package by adding "-e /usr/bin/python" to the setup build command.

Avishay

2012/8/12 Jonathan Liu <[email protected]>

Quoted 35 lines · Thomas Petazzoni
Quoted 18 lines

Le Sat, 11 Aug 2012 16:10:27 +1000,
Jonathan Liu<[email protected]> a ?crit :

+# Fix Python interpreter directive

package/python/python.mk endef

Quoted 7 lines
(quoted diff) +2 -0
+define PYTHON_FIX_INTERPRETER
+        sed -i '1s|#!.*python.*|#!/usr/bin/**env python|'

$(TARGET_DIR)/usr/bin/{easy_**install,easy_install-2.7,idle,**smtpd.py}

package/python/python.mk +3 -0
+endef
+
+PYTHON_POST_INSTALL_TARGET_**HOOKS += PYTHON_FIX_INTERPRETER

I agree the paths in those scripts is incorrect, *but*:

* Should these scripts have been installed in the first place? I don't think there are useful for the typical usage of the Python interpreter, so maybe we want to get rid of them.

Quoted 12 lines

* Instead of fixing this patch manually in every Python script installed, can we investigate on how to fix the root of the problem? I'm the one who has reworked the patches that get Python to cross-compile, and I know this stuff is really painful, but I think it's worth at least trying to understand a bit if there could be a way of handling things. From what I remember the problem is that the host-python uses its host sysconfig parameters even when building things for the target, simply because the whole Python things has absolutely zero understanding of the fact that we could be using Python on one machine to build stuff that will run on a different machine.

I've submitted patch for Python to use fixed path for sys.executable to resolve this.

Quoted 7 lines

Regards,
Jonathan
______________________________**_________________
buildroot mailing list
buildroot at busybox.net
http://lists.busybox.net/**mailman/listinfo/buildroot<http://lists.busybox.net/mailman/listinfo/buildroot>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.busybox.net/pipermail/buildroot/attachments/20120812/0dfffc8a/attachment-0001.html>

#5 lore raw

PATCH 1/1 python: fix interpreter directive for python scripts

Jonathan, Avishay, Thomas, All,

Quoted 2 lines · On Sunday 12 August 2012 15:19:17 Avishay Orpaz wrote:

I've just ran into this kind of problem. It can be solved per package by adding "-e /usr/bin/python" to the setup build command.

Or introduce a new package infrastrucutre, like for autotools-based and cmake-based packages. For example, we could add a "pysetup" (or whatver) infrastructure:

  $(eval $(pysetup-package))

Which would automatically call ./setup in the package directory, passing the proper arguments, instead of reimplementing that in every python packages?

Regards,
Yann E. MORIN.

Signature · 6 lines
.-----------------.--------------------.------------------.--------------------.
|  Yann E. MORIN  | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: |
| +33 662 376 056 | Software  Designer | \ / CAMPAIGN     |  ___               |
| +33 223 225 172 `------------.-------:  X  AGAINST      |  \e/  There is no  |
| http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL    |   v   conspiracy.  |
'------------------------------^-------^------------------^--------------------'
#6 lore raw

PATCH 1/1 python: fix interpreter directive for python scripts

Le Sun, 12 Aug 2012 16:50:03 +0200,
"Yann E. MORIN" <[email protected]> a ?crit :

Quoted 8 lines

Or introduce a new package infrastrucutre, like for autotools-based and cmake-based packages. For example, we could add a "pysetup" (or whatver) infrastructure:

  $(eval $(pysetup-package))

Which would automatically call ./setup in the package directory, passing the proper arguments, instead of reimplementing that in every python packages?

Right. We start to have more and more Python-based packages, and it seems like those using the Python setuptools could benefit from having a common infrastructure.

Best regards,

Thomas

Signature · 4 lines
Thomas Petazzoni, Free Electrons
Kernel, drivers, real-time and embedded Linux
development, consulting, training and support.
http://free-electrons.com