Re: [gentoo-dev] [PATCH 1/3] python-utils-r1.eclass: Allow -2/-3 as impl-patterns for py2/py3

2017-05-16 Thread Michał Górny
On śro, 2017-05-10 at 20:53 +0200, Michał Górny wrote:
> Allow two special values in the implementation patterns for
> _python_impl_matches(): -2 to indicate all Python 2-compatible
> implementations, and -3 to indicate all Python 3-compatible
> implementations. Both of those values are implemented using
> the python_is_python3 function.
> 
> This is mostly meant to make it easier and more fool-proof to write
> dependencies on backports to Python 2 which in most cases apply to PyPy2
> as well.
> ---
>  eclass/python-utils-r1.eclass | 14 +++---
>  1 file changed, 11 insertions(+), 3 deletions(-)
> 
> diff --git a/eclass/python-utils-r1.eclass b/eclass/python-utils-r1.eclass
> index 7efec083e35e..703246933acc 100644
> --- a/eclass/python-utils-r1.eclass
> +++ b/eclass/python-utils-r1.eclass
> @@ -156,8 +156,10 @@ _python_set_impls() {
>  # Check whether the specified  matches at least one
>  # of the patterns following it. Return 0 if it does, 1 otherwise.
>  #
> -#  should be in PYTHON_COMPAT form. The patterns are fnmatch-style
> -# patterns.
> +#  should be in PYTHON_COMPAT form. The patterns can be either:
> +# a) fnmatch-style patterns, e.g. 'python2*', 'pypy'...
> +# b) '-2' to indicate all Python 2 variants (= !python_is_python3)
> +# c) '-3' to indicate all Python 3 variants (= python_is_python3)
>  _python_impl_matches() {
>   [[ ${#} -ge 2 ]] || die "${FUNCNAME}: takes at least 2 parameters"
>  
> @@ -165,7 +167,13 @@ _python_impl_matches() {
>   shift
>  
>   for pattern; do
> - if [[ ${impl} == ${pattern} ]]; then
> + if [[ ${pattern} == -2 ]]; then
> + ! python_is_python3 "${impl}"
> + return
> + elif [[ ${pattern} == -3 ]]; then
> + python_is_python3 "${impl}"
> + return
> + elif [[ ${impl} == ${pattern} ]]; then
>   return 0
>   fi
>   done

Committed.

-- 
Best regards,
Michał Górny


signature.asc
Description: This is a digitally signed message part


Re: [gentoo-dev] [PATCH 1/3] python-utils-r1.eclass: Allow -2/-3 as impl-patterns for py2/py3

2017-05-10 Thread Michał Górny
On śro, 2017-05-10 at 14:15 -0700, Patrick McLean wrote:
> On Wed, 10 May 2017 20:53:31 +0200
> Michał Górny  wrote:
> 
> > Allow two special values in the implementation patterns for
> > _python_impl_matches(): -2 to indicate all Python 2-compatible
> > implementations, and -3 to indicate all Python 3-compatible
> > implementations. Both of those values are implemented using
> > the python_is_python3 function.
> 
> Seems mostly reasonable, though the syntax is somewhat confusing at
> first glance. There are many places where we use "-value" to negate, so
> this looks like it means "not python 2" rather than "all python 2".
> Perhaps something like '+2' would make it easier to read.

Well, it was supposed to correspond to option parameters, so that it
doesn't collide with regular template matching. But '+' works for me
too, same as anything. Or '@2'. Or '${py2}' ;-P.

> 
> > This is mostly meant to make it easier and more fool-proof to write
> > dependencies on backports to Python 2 which in most cases apply to
> > PyPy2 as well.
> 
> 

-- 
Best regards,
Michał Górny


signature.asc
Description: This is a digitally signed message part


Re: [gentoo-dev] [PATCH 1/3] python-utils-r1.eclass: Allow -2/-3 as impl-patterns for py2/py3

2017-05-10 Thread Patrick McLean
On Wed, 10 May 2017 20:53:31 +0200
Michał Górny  wrote:

> Allow two special values in the implementation patterns for
> _python_impl_matches(): -2 to indicate all Python 2-compatible
> implementations, and -3 to indicate all Python 3-compatible
> implementations. Both of those values are implemented using
> the python_is_python3 function.

Seems mostly reasonable, though the syntax is somewhat confusing at
first glance. There are many places where we use "-value" to negate, so
this looks like it means "not python 2" rather than "all python 2".
Perhaps something like '+2' would make it easier to read.

> This is mostly meant to make it easier and more fool-proof to write
> dependencies on backports to Python 2 which in most cases apply to
> PyPy2 as well.



[gentoo-dev] [PATCH 1/3] python-utils-r1.eclass: Allow -2/-3 as impl-patterns for py2/py3

2017-05-10 Thread Michał Górny
Allow two special values in the implementation patterns for
_python_impl_matches(): -2 to indicate all Python 2-compatible
implementations, and -3 to indicate all Python 3-compatible
implementations. Both of those values are implemented using
the python_is_python3 function.

This is mostly meant to make it easier and more fool-proof to write
dependencies on backports to Python 2 which in most cases apply to PyPy2
as well.
---
 eclass/python-utils-r1.eclass | 14 +++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/eclass/python-utils-r1.eclass b/eclass/python-utils-r1.eclass
index 7efec083e35e..703246933acc 100644
--- a/eclass/python-utils-r1.eclass
+++ b/eclass/python-utils-r1.eclass
@@ -156,8 +156,10 @@ _python_set_impls() {
 # Check whether the specified  matches at least one
 # of the patterns following it. Return 0 if it does, 1 otherwise.
 #
-#  should be in PYTHON_COMPAT form. The patterns are fnmatch-style
-# patterns.
+#  should be in PYTHON_COMPAT form. The patterns can be either:
+# a) fnmatch-style patterns, e.g. 'python2*', 'pypy'...
+# b) '-2' to indicate all Python 2 variants (= !python_is_python3)
+# c) '-3' to indicate all Python 3 variants (= python_is_python3)
 _python_impl_matches() {
[[ ${#} -ge 2 ]] || die "${FUNCNAME}: takes at least 2 parameters"
 
@@ -165,7 +167,13 @@ _python_impl_matches() {
shift
 
for pattern; do
-   if [[ ${impl} == ${pattern} ]]; then
+   if [[ ${pattern} == -2 ]]; then
+   ! python_is_python3 "${impl}"
+   return
+   elif [[ ${pattern} == -3 ]]; then
+   python_is_python3 "${impl}"
+   return
+   elif [[ ${impl} == ${pattern} ]]; then
return 0
fi
done
-- 
2.13.0