Page MenuHomeFreeBSD

shebangfix python_CMD improvement
ClosedPublic

Authored by antoine on Jun 30 2015, 2:14 PM.
Tags
None
Referenced Files
F79467524: D2955.diff
Mon, Mar 18, 5:48 PM
Unknown Object (File)
Sat, Mar 16, 1:46 AM
Unknown Object (File)
Sat, Mar 16, 1:46 AM
Unknown Object (File)
Sat, Feb 24, 5:44 PM
Unknown Object (File)
Fri, Feb 23, 7:23 AM
Unknown Object (File)
Feb 2 2024, 4:19 PM
Unknown Object (File)
Jan 20 2024, 6:13 AM
Unknown Object (File)
Jan 4 2024, 11:51 AM
Tokens
"The World Burns" token, awarded by mat.

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
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

feld retitled this revision from to shebangfix python_CMD improvement.
feld updated this object.
feld edited the test plan for this revision. (Show Details)
feld added reviewers: koobs, bapt.

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

feld removed reviewers: antoine, mva.
feld removed a subscriber: Python.

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?)

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

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)

${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

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.

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)

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 added a reviewer: feld.
antoine edited edge metadata.

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

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