Bug 209204 - Changing default Python version unduly difficult
Summary: Changing default Python version unduly difficult
Status: Closed DUPLICATE of bug 209551
Alias: None
Product: Ports & Packages
Classification: Unclassified
Component: Ports Framework (show other bugs)
Version: Latest
Hardware: Any Any
: --- Affects Only Me
Assignee: David Naylor
URL:
Keywords: needs-qa
Depends on:
Blocks:
 
Reported: 2016-05-02 16:15 UTC by Mikhail Teterin
Modified: 2016-06-19 07:32 UTC (History)
6 users (show)

See Also:


Attachments
Depreciate PYTHON_VERSION, use PYTHON_DEFAULT instead (1.86 KB, patch)
2016-06-18 18:59 UTC, David Naylor
no flags Details | Diff
propose patch (1.68 KB, patch)
2016-06-19 07:28 UTC, Iblis Lin
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Mikhail Teterin freebsd_committer freebsd_triage 2016-05-02 16:15:34 UTC
Although I still have python-2.7 installed and used by some of the ports, I'd like the newly-built ones to be based on python-3.5.

To this end I set the following flags:

DEFAULT_VERSIONS=ruby=2.0 tcl=8.6 gcc=4.9 db=6.1 python=3.5 perl=5.22 ghostscript9:agpl
PYTHON3_DEFAULT=3.5
PYTHON_DEFAULT=3

(even though only the very first one should be needed, right?)

Despite all this, devel/py-sip, for example, still insists on using 2.7:
PKGNAME=py27-sip-4.17,1
PYTHON_VER=2.7

The only way to force it, apparently, is to edit each port's Makefile and change USES=python to USES=python:3 

This should not be necessary, should it?
Comment 1 Mathieu Arnold freebsd_committer freebsd_triage 2016-05-02 17:06:33 UTC
Replace:

PYTHON3_DEFAULT=3.5
PYTHON_DEFAULT=3

by

DEFAULT_VERSIONS= python=3.5 python3=3.5

Now, there are ports that will insist on python 2.7, because they don't work with 3.  I don't see any reason for this to happen with devel/py-sip though.

Without builds logs, on the other hand, I don't see any way to help you.

Best is to open a PR with that port with a poudriere log, to see what happens.
Comment 2 Mikhail Teterin freebsd_committer freebsd_triage 2016-05-02 17:35:28 UTC
(In reply to Mathieu Arnold from comment #1)
> DEFAULT_VERSIONS= python=3.5 python3=3.5

Does not help. For example:

% make -C /usr/ports/textproc/py-pygments -V DEFAULT_VERSIONS
ruby=2.0 tcl=8.6 gcc=4.9 db=6.1 python=3.5 python3=3.5 perl=5.22 ghostscript9:agpl

and yet:

% make -C /usr/ports/textproc/py-pygments -V USES -V PYTHON_VER -V PKGNAME
python
2.7
py27-pygments-2.1.3

> I don't see any reason for this to happen with devel/py-sip though.

Nor for py-pygments, right?

> Without builds logs, on the other hand, I don't see any way to help you.

Why do you need build logs? The problem is right there with the incorrect names of PYTHON_VER and PKGNAME -- these can be seen without any builds even attempted, right?
Comment 3 David Naylor freebsd_committer freebsd_triage 2016-05-04 06:43:39 UTC
The build logs would allow us to have a better understanding of what the problem is.  In this particular case I suspect a warning message in the build logs would give a clue as to the solution.  

Also, I am able to reproduce the problem on my system:
# cd /usr/ports/textproc/py-pygments
# make -V PYTHON_VER
2.7
# make -V PYTHON_VER DEFAULT_VERSIONS=python=3.5
2.7
# make -V WARNING
"Your requested default python version 3.5 is different from the installed default python interpreter version 2.7"

The above warning is what should appear in your build logs.  If not we can address that.  

The issue is you have already installed lang/python (i.e. the default) as version 2.7.  This means your system is "hard-coded" to use python-2.7 as the default until you uninstall all ports that depend on lang/python, inclusive, and rebuild them all with the new default.  

The effect of "default" is stronger than what the word implies, it is more akin to choosing i386 and amd64 at install time.  Once you have chosen it, that's it.  Until you undo and redo.  In other words, the choice of default is persistent and cannot be changed, only undone.  

I hope this clarifies the issue.
Comment 4 Iblis Lin 2016-05-06 17:55:19 UTC
Hi,

Here is the code block in Mk/Uses/python.Mk.
From line 276-289
https://svnweb.freebsd.org/ports/head/Mk/Uses/python.mk?view=markup&pathrev=414168#l276

It shows that the python interpreter pointed by `/usr/local/bin/python`
will be chosen. It overrides the config of `DEFAULT_VERSIONS`.

And, in our case, we install python2 first, implies `/usr/local/bin/python` 
point to py2.
Comment 5 Mikhail Teterin freebsd_committer freebsd_triage 2016-05-06 18:00:17 UTC
(In reply to David Naylor from comment #3)
> This means your system is "hard-coded" to use python-2.7 as the default
> until you uninstall all ports that depend on lang/python

This is, what I refer to as "unduly difficult". Seems like a gratuitous requirement. If I can edit the port's Makefile and change

-USES=python
+USES=python:3

to build the package prefixed with p35- instead of p27-, I should be able to have the same effect by simply setting my preference with DEFAULT_VERSIONS.

(In reply to Iblis Lin from comment #4)
> the python interpreter pointed by `/usr/local/bin/python`
> will be chosen. It overrides the config of `DEFAULT_VERSIONS`.

Thanks, Iblis. Should not be hard to fix, Python-folks?
Comment 6 David Naylor freebsd_committer freebsd_triage 2016-05-08 16:44:51 UTC
Oops, apologies.  The correct approach to what you want to achieve is:

# Variables, which can be set by a user:
#
# PYTHON_VERSION        - The chosen Python interpreter including the version,
#                         e.g. python2.7, python3.3, etc. This allows the user
#                         to override the currently chosen default version and
#                         to install the port for a specific Python version.
#                         It must not be set by a port.

For example:
# cd /usr/ports/textproc/py-pygments
# make -V PYTHON_VER
2.7
# make -V PYTHON_VER PYTHON_VERSION=python3.5
3.5

i.e. if you want to install ports for python versions other than the default (as already set in your system, per PEP 394) then use PYTHON_VERSION, this can be set in /etc/make.conf to effectively change the default.
Comment 7 Mikhail Teterin freebsd_committer freebsd_triage 2016-05-08 18:10:29 UTC
(In reply to David Naylor from comment #6)
> PYTHON_VERSION        - The chosen Python interpreter including the version,

Oh... So, do we rename this PR into something like "PYTHON_VERSION ignores DEFAULT_VERSIONS"?

Because I, for one, think it was a great idea to centralize these settings into one list...

The current approach -- as this very ticket's comments attest -- too confusing even for members of portmgr@ and python@ . Ordinary users have no hope :-)
Comment 8 David Naylor freebsd_committer freebsd_triage 2016-06-18 18:59:26 UTC
Created attachment 171555 [details]
Depreciate PYTHON_VERSION, use PYTHON_DEFAULT instead

Per your suggestion that PYTHON_VERSION is now un-intuitive in the current Ports Framework (a la DEFAULT_VERSIONS) the attached patch depreciates PYTHON_VERSION and uses PYTHON_DEFAULT instead:

# make -V PYTHON_VER
2.7
# make -V PYTHON_VER DEFAULT_VERSIONS=python=3.5
3.5
Comment 9 David Naylor freebsd_committer freebsd_triage 2016-06-18 19:00:50 UTC
Reopen: patch to change confusing behavior.
Comment 10 Iblis Lin 2016-06-19 04:29:58 UTC
Hi! please check out the comment in bug 209551, also.
(I have no idea how to add `sea also` link...
Comment 11 David Naylor freebsd_committer freebsd_triage 2016-06-19 07:17:36 UTC

*** This bug has been marked as a duplicate of bug 209551 ***
Comment 12 Kubilay Kocak freebsd_committer freebsd_triage 2016-06-19 07:26:56 UTC
Assign to committer that resolved
Comment 13 Iblis Lin 2016-06-19 07:28:28 UTC
Created attachment 171563 [details]
propose patch

Please give this patch a try, It follows the rule i proposed in bug 209551, comment 1.

Here describe the testing flow:

1. prepare a new jail

2. check the current priority of `${LOCALBASE}/bin/python`
   
   $ pkg install python  # should create a symlink `/usr/local/bin/python`
   $ cd /usr/ports/databases/py-sqlite3
   $ make -V PYTHON_VERSION DEFAULT_VERSIONS=python=3.5
   python2.7  # the symlink win now

3. apply this patch

4. check that DEFAULT_VERSIONS got higher priority

   $ cd /usr/ports/databases/py-sqlite3
   $ make -V PYTHON_VERSION
   python2.7
   $ make -V PYTHON_VERSION DEFAULT_VERSIONS=python=3.5
   python3.5

5. one more check for priority of symlink `/usr/local/bin/python`
   $ pkg delete python
   $ pkg install python3  # we will get python3.4 installed
   $ cd /usr/local/bin
   $ ln -s python3 python
   $ ls -l python
   lrwxr-xr-x  1 root  wheel  7 Jun 19 14:16 python@ -> python3
   
   $ cd /usr/ports/databases/py-sqlite3
   $ make -V PYTHON_VERSION DEFAULT_VERSIONS=python=3.5
   python3.5
   $ make -V PYTHON_VERSION
   python3.4  # ya! symlink auto-detect correct!
Comment 14 Iblis Lin 2016-06-19 07:32:08 UTC
hmm, i will post my comment to the new issue page.
(When i was writing it, i do not notice it has been closed