[python] Add python2_version_nodots macro

Nick Coghlan ncoghlan at redhat.com
Mon Nov 17 04:17:48 UTC 2014


On 11/14/2014 12:05 AM, Matej Stuchlik wrote:
> commit 6875a63831616c6c8e722632e24faaa1a09cc831
> Author: Matej Stuchlik <mstuchli at redhat.com>
> Date:   Thu Nov 13 15:04:28 2014 +0100
> 
>     Add python2_version_nodots macro
> 
>  macros.python2 |    1 +
>  python.spec    |    5 ++++-
>  2 files changed, 5 insertions(+), 1 deletions(-)
> ---
> diff --git a/macros.python2 b/macros.python2
> index 982b51f..d090296 100644
> --- a/macros.python2
> +++ b/macros.python2
> @@ -2,3 +2,4 @@
>  %python2_sitelib %(%{__python2} -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())")
>  %python2_sitearch %(%{__python2} -c "from distutils.sysconfig import get_python_lib; print(get_python_lib(1))")
>  %python2_version %(%{__python2} -c "import sys; sys.stdout.write(sys.version[:3])")
> +%python2_version_nodots %(%{__python2} -c "import sys; sys.stdout.write(sys.version[:3].replace('.',''))")

I just saw this commit go by on python-owners.

These macros are going to fail when Python 2.7.10 is released next year.
Anything currently depending on the new "no dots" version in particular
may also fail when it moves from 3 digits to 4 (since 2710 sorts
lexically lower than 279).

The version with dots can be fixed by using
"'.'.join(sys.version_info[:3])" instead of ignoring the explicit "Do
not extract version information out of it" guidance for sys.version.

The version without dots can be addressed by including the leading zero:
"{0.major}{0.minor}{0.micro:02d}".format(sys.version_info)

Cheers,
Nick.

-- 
Nick Coghlan
Red Hat Hosted & Shared Services
Software Engineering & Development, Brisbane

HSS Provisioning Architect


More information about the python-devel mailing list