All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] python: make python2 and python3 alternatives to python
@ 2017-04-13  8:33 Dmitry Rozhkov
  2017-04-13 10:15 ` Alexander Kanavin
  0 siblings, 1 reply; 6+ messages in thread
From: Dmitry Rozhkov @ 2017-04-13  8:33 UTC (permalink / raw)
  To: openembedded-core

If only python3 is installed on an image nothing provides
/usr/bin/python even though many scripts compatible with
both python2 and python3 just state `#!/usr/bin/env python`
in their shebang line.

Make python and python3 recipes provide alternatives for
/usr/bin/python and /usr/bin/python-config. By default
python2 has higher priority over python3.

Signed-off-by: Dmitry Rozhkov <dmitry.rozhkov@linux.intel.com>
---
 meta/recipes-devtools/python/python3_3.5.2.bb | 9 +++++++++
 meta/recipes-devtools/python/python_2.7.13.bb | 7 +++++++
 2 files changed, 16 insertions(+)

diff --git a/meta/recipes-devtools/python/python3_3.5.2.bb b/meta/recipes-devtools/python/python3_3.5.2.bb
index 2ff7c9e..310d43f 100644
--- a/meta/recipes-devtools/python/python3_3.5.2.bb
+++ b/meta/recipes-devtools/python/python3_3.5.2.bb
@@ -221,4 +221,13 @@ FILES_${PN}-misc = "${libdir}/python${PYTHON_MAJMIN}"
 PACKAGES += "${PN}-man"
 FILES_${PN}-man = "${datadir}/man"
 
+inherit update-alternatives
+
+ALTERNATIVE_PRIORITY = "80"
+ALTERNATIVE_${PN}-core = "python python_config"
+ALTERNATIVE_LINK_NAME[python] = "${bindir}/python"
+ALTERNATIVE_LINK_NAME[python_config] = "${bindir}/python-config"
+ALTERNATIVE_TARGET[python] = "${bindir}/python3"
+ALTERNATIVE_TARGET[python_config] = "${bindir}/python3-config"
+
 BBCLASSEXTEND = "nativesdk"
diff --git a/meta/recipes-devtools/python/python_2.7.13.bb b/meta/recipes-devtools/python/python_2.7.13.bb
index 4ef9952..0cf7498 100644
--- a/meta/recipes-devtools/python/python_2.7.13.bb
+++ b/meta/recipes-devtools/python/python_2.7.13.bb
@@ -168,4 +168,11 @@ do_install_ptest() {
 PACKAGES += "${PN}-man"
 FILES_${PN}-man = "${datadir}/man"
 
+inherit update-alternatives
+
+ALTERNATIVE_PRIORITY = "100"
+ALTERNATIVE_${PN}-core = "python python_config"
+ALTERNATIVE_LINK_NAME[python] = "${bindir}/python"
+ALTERNATIVE_LINK_NAME[python_config] = "${bindir}/python-config"
+
 BBCLASSEXTEND = "nativesdk"
-- 
2.9.3



^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] python: make python2 and python3 alternatives to python
  2017-04-13  8:33 [PATCH] python: make python2 and python3 alternatives to python Dmitry Rozhkov
@ 2017-04-13 10:15 ` Alexander Kanavin
  2017-04-13 10:18   ` Alexander Kanavin
  2017-04-13 14:47   ` Burton, Ross
  0 siblings, 2 replies; 6+ messages in thread
From: Alexander Kanavin @ 2017-04-13 10:15 UTC (permalink / raw)
  To: openembedded-core

On 04/13/2017 11:33 AM, Dmitry Rozhkov wrote:
> If only python3 is installed on an image nothing provides
> /usr/bin/python even though many scripts compatible with
> both python2 and python3 just state `#!/usr/bin/env python`
> in their shebang line.
>
> Make python and python3 recipes provide alternatives for
> /usr/bin/python and /usr/bin/python-config. By default
> python2 has higher priority over python3.

This runs against upstream recommendation and common distro practice. 
And it will break scripts that have not been ported to Python 3. Please 
fix the scripts instead to refer to python 3 whenever possible.

Alex



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] python: make python2 and python3 alternatives to python
  2017-04-13 10:15 ` Alexander Kanavin
@ 2017-04-13 10:18   ` Alexander Kanavin
  2017-04-13 14:47   ` Burton, Ross
  1 sibling, 0 replies; 6+ messages in thread
From: Alexander Kanavin @ 2017-04-13 10:18 UTC (permalink / raw)
  To: openembedded-core

On 04/13/2017 01:15 PM, Alexander Kanavin wrote:
> On 04/13/2017 11:33 AM, Dmitry Rozhkov wrote:
>> If only python3 is installed on an image nothing provides
>> /usr/bin/python even though many scripts compatible with
>> both python2 and python3 just state `#!/usr/bin/env python`
>> in their shebang line.
>>
>> Make python and python3 recipes provide alternatives for
>> /usr/bin/python and /usr/bin/python-config. By default
>> python2 has higher priority over python3.
>
> This runs against upstream recommendation and common distro practice.
> And it will break scripts that have not been ported to Python 3. Please
> fix the scripts instead to refer to python 3 whenever possible.

Also, if there are scripts on the image that refer to 'python', yet 
python 2.7 is not installed into the image, that's a missing RDEPENDS in 
the scripts recipe.

Alex



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] python: make python2 and python3 alternatives to python
  2017-04-13 10:15 ` Alexander Kanavin
  2017-04-13 10:18   ` Alexander Kanavin
@ 2017-04-13 14:47   ` Burton, Ross
  2017-04-18  8:44     ` Dmitry Rozhkov
  1 sibling, 1 reply; 6+ messages in thread
From: Burton, Ross @ 2017-04-13 14:47 UTC (permalink / raw)
  To: Alexander Kanavin; +Cc: OE-core

[-- Attachment #1: Type: text/plain, Size: 414 bytes --]

On 13 April 2017 at 11:15, Alexander Kanavin <
alexander.kanavin@linux.intel.com> wrote:

> This runs against upstream recommendation and common distro practice. And
> it will break scripts that have not been ported to Python 3. Please fix the
> scripts instead to refer to python 3 whenever possible.
>

Agreed.  If a script uses /usr/bin/python and gets py3, 99% of the time
you'll get errors.

Ross

[-- Attachment #2: Type: text/html, Size: 830 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] python: make python2 and python3 alternatives to python
  2017-04-13 14:47   ` Burton, Ross
@ 2017-04-18  8:44     ` Dmitry Rozhkov
  2017-04-18  9:33       ` Burton, Ross
  0 siblings, 1 reply; 6+ messages in thread
From: Dmitry Rozhkov @ 2017-04-18  8:44 UTC (permalink / raw)
  To: Burton, Ross, Alexander Kanavin; +Cc: OE-core

On Thu, 2017-04-13 at 15:47 +0100, Burton, Ross wrote:
> 
> On 13 April 2017 at 11:15, Alexander Kanavin <alexander.kanavin@linux
> .intel.com> wrote:
> > This runs against upstream recommendation and common distro
> > practice. And it will break scripts that have not been ported to
> > Python 3. Please fix the scripts instead to refer to python 3
> > whenever possible.
> > 
> 
> Agreed.  If a script uses /usr/bin/python and gets py3, 99% of the
> time you'll get errors.

I've just checked PEP-349. It recommends that

"- The more general python command should be installed whenever any
version of Python 2 is installed and should invoke the same version of
Python as the python2 command (however, note that some distributions
have already chosen to have python implement the python3 command; see
the Rationale and Migration Notes below)."

The proposed patch doesn't violate this recommendation, because
"whenever" Python 2 is installed the python command still invokes
python2.

Also, there are other recommendations like

"- In order to tolerate differences across platforms, all new code that
needs to invoke the Python interpreter should not specify python , but
rather should specify either python2 or python3 (or the more specific
python2.x and python3.x versions; see the Migration Notes ). This
distinction should be made in shebangs, when invoking from a shell
script, when invoking via the system() call, or when invoking in any
other context.
- One exception to this is scripts that are deliberately written to be
source compatible with both Python 2.x and 3.x. Such scripts may
continue to use python on their shebang line without affecting their
portability."

If I understood correctly OE-core is not a distribution, but a tool to
create "a custom one". I would rather allow people to create
distributions where python3 is the default like in Arch Linux.

BR,
Dmitry


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] python: make python2 and python3 alternatives to python
  2017-04-18  8:44     ` Dmitry Rozhkov
@ 2017-04-18  9:33       ` Burton, Ross
  0 siblings, 0 replies; 6+ messages in thread
From: Burton, Ross @ 2017-04-18  9:33 UTC (permalink / raw)
  To: Dmitry Rozhkov; +Cc: OE-core

[-- Attachment #1: Type: text/plain, Size: 1257 bytes --]

On 18 April 2017 at 09:44, Dmitry Rozhkov <dmitry.rozhkov@linux.intel.com>
wrote:

> I've just checked PEP-349. It recommends that
>
> "- The more general python command should be installed whenever any
> version of Python 2 is installed and should invoke the same version of
> Python as the python2 command (however, note that some distributions
> have already chosen to have python implement the python3 command; see
> the Rationale and Migration Notes below)."
>
> The proposed patch doesn't violate this recommendation, because
> "whenever" Python 2 is installed the python command still invokes
> python2.
>

Only out of the box: you can install py2 and py3 and set the alternatives
so that python is python3.

If I understood correctly OE-core is not a distribution, but a tool to
> create "a custom one". I would rather allow people to create
> distributions where python3 is the default like in Arch Linux.


Personally I feel the PEP is an attempt to limit the damage caused by Arch
ignoring the Python maintainers, and I'd prefer not to spread the
impression that 'python' could be Python 3.  Unless you code incredibly
carefully it's not simple to have a script that doesn't care if it runs
under Py2 or Py3.

Ross

[-- Attachment #2: Type: text/html, Size: 2256 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2017-04-18  9:33 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-04-13  8:33 [PATCH] python: make python2 and python3 alternatives to python Dmitry Rozhkov
2017-04-13 10:15 ` Alexander Kanavin
2017-04-13 10:18   ` Alexander Kanavin
2017-04-13 14:47   ` Burton, Ross
2017-04-18  8:44     ` Dmitry Rozhkov
2017-04-18  9:33       ` Burton, Ross

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.