Page MenuHomeFreeBSD

shebangfix python_CMD improvement
ClosedPublic

Authored by antoine on Jun 30 2015, 2:14 PM.

Details

Summary

the python shebangfix currently replaces the shebang with
${LOCALBASE}/bin/python which I feel is not a great solution considering
the "python" command doesn't exist unless the lang/python metaport is installed. Neither are installed
automatically via USES=python.

PYTHON_CMD expands to ${LOCALBASE}/bin/pythonX.Y which seems far more
appropriate and reliable here. I recently fought this issue in
www/varnish4 and had to override python_CMD in shebangfix to include the
python version number. This seemed cleaner than adding a new
BUILD_DEPENDS on the python metaport.

edit: @mat pointed out I meant lang/python metaport not lang/python{2,3}

Diff Detail

Repository
rP FreeBSD ports repository
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.

Event Timeline

feld retitled this revision from to shebangfix python_CMD improvement.Jun 30 2015, 2:14 PM
feld updated this object.
feld edited the test plan for this revision. (Show Details)
feld added reviewers: koobs, bapt.
feld updated this revision to Diff 6582.
mat added a subscriber: mat.Jun 30 2015, 2:24 PM

What happens if the port does not USES=python shebangfix, say, does USES=shebangfix or USES=shebangfix python

koobs added a subscriber: Python.
feld updated this object.Jun 30 2015, 2:26 PM
feld removed reviewers: antoine, mva.
feld removed a subscriber: Python.
feld added a comment.Jun 30 2015, 2:29 PM

That's a great point @mat: $PYTHON_CMD would not exist if you did USES=shebangfix without USES=python

But in what scenario would you possibly be doing a shebangfix on a python file and not at least have USES=python:build ?

(I really don't know, but that seems to be the danger here?)

mat added a comment.Jun 30 2015, 2:35 PM
In D2955#57720, @feld wrote:

That's a great point @mat: $PYTHON_CMD would not exist if you did USES=shebangfix without USES=python
But in what scenario would you possibly be doing a shebangfix on a python file and not at least have USES=python:build ?
(I really don't know, but that seems to be the danger here?)

Well, one would need to go through all the ports using shebangfix to see if they also fix a python thing.

Or, you could write python_CMD?= ${PYTHON_CMD:U${LOCALBASE}/bin/python}

But to work, this needs bmake, and so, 8.4 needs to be dead, (so, a month from now) and 9.3 users need to be taught to run bmake instead of make

swills added a subscriber: swills.Jul 2 2015, 7:32 PM

I hate to say this, but it seems to me that "${LOCALBASE}/bin/python" is correct, so the issue is rather that USES=python doesn't pull in lang/python, which would be intuitive. Can someone more knowledgeable about python explain why it doesn't?

${LOCALBASE}/bin/python is incorrect for more than 70% of ports depending on python (all those installing or depending modules or extensions in ${PYTHON_SITELIBDIR} aka ${PYTHONBASE}/lib/python${_PYTHON_VERSION}/site-packages)

swills added a comment.Jul 2 2015, 7:59 PM

${LOCALBASE}/bin/python is incorrect for more than 70% of ports depending on python (all those installing or depending modules or extensions in ${PYTHON_SITELIBDIR} aka ${PYTHONBASE}/lib/python${_PYTHON_VERSION}/site-packages)

Are you saying running ${LOCALBASE}/bin/python won't allow you to import things from ${PYTHONBASE}/lib/python${_PYTHON_VERSION}/site-packages ?

I'm saying if python is a symlink to python2 that symlinks to python2.7 and your modules is installed for python 3.4, then there will be a problem using python to import your module

swills added a comment.Jul 2 2015, 8:22 PM

I'm saying if python is a symlink to python2 that symlinks to python2.7 and your modules is installed for python 3.4, then there will be a problem using python to import your module

I see. Does checking if PYTHON_VERSION is not PYTHON_DEFAULT and only then use PYTHON_CMD make sense?

In D2955#58405, @swills wrote:

I see. Does checking if PYTHON_VERSION is not PYTHON_DEFAULT and only then use PYTHON_CMD make sense?

I don't think so (using PYTHON_CMD makes the same package usable by people having different defaults).

I just found this document by python team that describes which shebang should be used:
https://wiki.freebsd.org/Python/PortsPolicy#Framework_Compliance

In D2955#58405, @swills wrote:

I see. Does checking if PYTHON_VERSION is not PYTHON_DEFAULT and only then use PYTHON_CMD make sense?

I don't think so (using PYTHON_CMD makes the same package usable by people having different defaults).
I just found this document by python team that describes which shebang should be used:
https://wiki.freebsd.org/Python/PortsPolicy#Framework_Compliance

That answers that then, thanks. Python is a strange place.

koobs edited edge metadata.Jul 3 2015, 3:42 AM

For reference, the primary specification document which Python aims to comply with is:

PEP-394 -- The "python" Command on Unix-Like Systems

koobs added a subscriber: mva.

Open this up to more Python eyes to get this finished. Specifically I'd like to see @mva and/or @antoine accept this if noone else chimes in.

I plan to have an improved version of patch from bug 201077 ready and tested in around 10 days (when I'm back from holidays)

koobs added a comment.Jul 27 2015, 5:41 AM

I plan to have an improved version of patch from bug 201077 ready and tested in around 10 days (when I'm back from holidays)

Yay :)

antoine commandeered this revision.
antoine edited edge metadata.Jul 29 2015, 5:50 AM
antoine updated this revision to Diff 7452.

Updated patch.
This version should work with both
USES=python shebangfix -> default python_CMD is ${PYTHON_CMD}
USES=shebangfix python -> default python_CMD is ${PYTHON_CMD}
USES=shebangfix -> default python_CMD is ${LOCALBASE}/bin/python

mat added a reviewer: mat.Jul 29 2015, 8:52 AM
mat accepted this revision.

Macro shipit:

This revision is now accepted and ready to land.Jul 29 2015, 8:52 AM
mat awarded a token.Jul 29 2015, 8:52 AM
This revision was automatically updated to reflect the committed changes.