#4 Don't build and ship Python 2 bits on EL > 7 and Fedora > 28
Closed 6 years ago by kevin. Opened 6 years ago by churchyard.
rpms/ churchyard/ansible nopy2  into  master

file modified
+83 -36
@@ -5,9 +5,6 @@ 

  %global __python2 /usr/bin/python2.6

  %endif

  

- %if 0%{?rhel} <= 5

- %endif

- 

  %if 0%{?fedora} || 0%{?rhel} >= 8

  %global with_docs 1

  %else
@@ -20,12 +17,19 @@ 

  %global with_python3 0

  %endif

  

+ %if 0%{?fedora} >= 29 || 0%{?rhel} >= 8

+ %global with_python2 0

+ %global with_docs 0

+ # note that the docs are legacy python only as of 2.4.3.0

+ %else

+ %global with_python2 1

  %{!?python_sitelib: %global python_sitelib %(%{__python2} -c "from distutils.sysconfig import get_python_lib; print get_python_lib()")}

+ %endif

  

  Name: ansible

  Summary: SSH-based configuration management, deployment, and task execution system

  Version: 2.4.3.0

- Release: 2%{?dist}

+ Release: 3%{?dist}

  

  Group: Development/Libraries

  License: GPLv3+
@@ -40,6 +44,15 @@ 

  Url: http://ansible.com

  BuildArch: noarch

  

+ # This is needed to update the old ansible-firewall package that is no 

+ # longer needed. Note that you should also remove ansible-node-firewall manually

+ # Where you still have it installed. 

+ #

+ Provides: ansible-fireball = %{version}-%{release}

+ Obsoletes: ansible-fireball < 1.2.4

+ 

+ 

+ %if 0%{?with_python2}

  %if 0%{?rhel} && 0%{?rhel} <= 5

  # On RHEL6 use the python26 stack

  BuildRequires: python26-devel
@@ -125,22 +138,16 @@ 

  BuildRequires: python-simplejson

  %endif

  

- # 

- # This is needed to update the old ansible-firewall package that is no 

- # longer needed. Note that you should also remove ansible-node-firewall manually

- # Where you still have it installed. 

- #

- Provides: ansible-fireball = %{version}-%{release}

- Obsoletes: ansible-fireball < 1.2.4

  

  %description

- 

  Ansible is a radically simple model-driven configuration management,

  multi-node deployment, and remote task execution system. Ansible works

  over SSH and does not require any software or daemons to be installed

  on remote nodes. Extension modules can be written in any language and

  are transferred to managed machines automatically.

  

+ %endif # python2

+ 

  

  %if 0%{?with_python3}

  # Note, ansible is not intended to be used as a library so avoiding the
@@ -150,8 +157,16 @@ 

  # versions of ansible should behave identically but python3-only bugs may be present.

  # So upstream would like us to ship both py2 and py3 ansible (at least in

  # rawhide) for people to beat on and find bugs.

+ 

+ # However, for future ELs and Fedoras, we want Python 3 only

+ %if 0%{?with_python2}

  %package -n ansible-python3

  Summary: SSH-based configuration management, deployment, and task execution system

+ %else

+ Provides:      ansible-python3 = %{version}-%{release}

+ Obsoletes:     ansible-python3 < %{version}-%{release}

+ %endif

+ 

  BuildRequires: python3-devel

  BuildRequires: python3-setuptools

  
@@ -167,6 +182,7 @@ 

  BuildRequires: python3-pytest

  BuildRequires: python3-pytest-xdist

  BuildRequires: python3-pytest-mock

+ BuildRequires: python3-requests

  BuildRequires: python3-coverage

  BuildRequires: python3-mock

  BuildRequires: python3-boto3
@@ -186,11 +202,13 @@ 

  Requires: sshpass

  # needed for json_query filter

  Requires: python3-jmespath

- %endif

  

  

- %if 0%{?with_python3}

+ %if 0%{?with_python2}

  %description -n ansible-python3

+ %else

+ %description

+ %endif

  

  Ansible is a radically simple model-driven configuration management,

  multi-node deployment, and remote task execution system. Ansible works
@@ -199,7 +217,7 @@ 

  are transferred to managed machines automatically.

  

  This package installs versions of ansible that execute on Python3.

- %endif  # with_python3

+ %endif # python3

  

  %package -n ansible-doc

  Summary: Documentation for Ansible
@@ -227,15 +245,25 @@ 

  %endif # with_python3

  

  %build

+ %if 0%{?with_python2}

  %{__python2} setup.py build

  # Build docs

  # EPEL6/7 don't have a recent enough sphinx to build the docs

  %if %with_docs

    make webdocs

  %endif

+ %endif

  

  %if 0%{?with_python3}

+ pushd %{py3dir}

  %py3_build

+ 

+ %if %with_docs && ! 0%{?with_python2}

+   pathfix.py -i %{__python3} -p docs/bin

+   make webdocs

+ %endif

+ 

+ popd

  %endif # with_python3

  

  
@@ -247,23 +275,32 @@ 

  

  for i in $RPM_BUILD_ROOT/%{_bindir}/ansible* ; do

      if [ $(basename $i) = "ansible-connection" -o $(basename $i) = "ansible" ] ; then

-         mv $i $i-%{python3_version}

+         %if 0%{?with_python2}

+             mv $i $i-%{python3_version}

+         %else

+             # for backwards compatibility

+             ln -s $(basename $i) $i-%{python3_version}

+         %endif

          ln -s %{_bindir}/$(basename $i)-%{python3_version} $i-3

+     %if 0%{?with_python2}

      else

          # The ansible commands are themselves symlinks to /usr/bin/ansible.

          # Need to change them to point to the python3 version

          ln -s %{_bindir}/ansible-3 $i-%{python3_version}

          ln -s %{_bindir}/$(basename $i)-%{python3_version} $i-3

+     %endif

      fi

  done

  %endif # with_python3

  

+ %if 0%{?with_python2}

  %{__python2} setup.py install --root=$RPM_BUILD_ROOT

  for i in $RPM_BUILD_ROOT/%{_bindir}/{ansible,ansible-console,ansible-doc,ansible-galaxy,ansible-playbook,ansible-pull,ansible-vault}  ; do

      mv $i $i-%{python2_version}

      ln -s %{_bindir}/$(basename $i)-%{python2_version} $i

      ln -s %{_bindir}/$(basename $i)-%{python2_version} $i-2

  done

+ %endif

  

  mkdir -p $RPM_BUILD_ROOT/etc/ansible/

  mkdir -p $RPM_BUILD_ROOT/etc/ansible/roles/
@@ -282,50 +319,57 @@ 

  # RHEL <= 6 doesn't have a new enough python-mock to run the tests

  # Currently RHEL <= 7 doesn't have pytest-xdist or a new enough pytest

  # Fedora 25 doesn't have a new enough pytest

- %if 0%{?fedora} >= 26 || 0%{?rhel} >= 8

- if test -z $(which pytest) ; then

-   mkdir tests_bin

-   pushd tests_bin

-   ln -s `which py.test` pytest

-   export PATH=$PATH:$(pwd)

-   popd

- fi

+ %if 0%{?with_python2} && 0%{?fedora} >= 26

+ mkdir tests_bin

+ pushd tests_bin

+ ln -s `which pytest-2` pytest

+ export PATH=$PATH:$(pwd)

+ popd

+ 

  make tests

+ %endif  # New enough Fedora with python2

  

  %if 0%{?with_python3}

  pushd %{py3dir}

- if test -z $(which pytest) ; then

-   mkdir tests_bin

-   pushd tests_bin

-   ln -s `which py.test` pytest

-   export PATH=$PATH:$(pwd)

-   popd

- fi

+ 

+ mkdir tests_bin

+ pushd tests_bin

+ # this is a hack and should be done differently!

+ ln -s `which pytest-3` pytest

+ ln -s %{__python3} python

+ ln -s %{__python3} python2

+ export PATH=$PATH:$(pwd)

+ popd

+ 

  make tests

+ popd

  %endif  # python3

  

- %endif  # New enough Fedora/RHEL

  

  

  %files

  %defattr(-,root,root)

+ %if 0%{?with_python2}

  %{python_sitelib}/ansible*

+ %endif

  %{_bindir}/ansible*

- %if 0%{?with_python3}

+ %if 0%{?with_python3} && 0%{?with_python2}

  %exclude %{_bindir}/ansible*-3*

- %endif  # python3

+ %endif  # python3 and 2

  %config(noreplace) %{_sysconfdir}/ansible/

  %doc README.md PKG-INFO COPYING CHANGELOG.md

  %doc %{_mandir}/man1/ansible*

  

  %if 0%{?with_python3}

+ %if 0%{?with_python2}

  %files -n ansible-python3

  %defattr(-,root,root,-)

- %{python3_sitelib}/ansible*

- %{_bindir}/ansible*-3*

  %config(noreplace) %{_sysconfdir}/ansible/

  %doc README.md PKG-INFO COPYING CHANGELOG.md

  %doc %{_mandir}/man1/ansible*

+ %{_bindir}/ansible*-3*

+ %endif # python2

+ %{python3_sitelib}/ansible*

  %endif  # python3

  

  %files -n ansible-doc
@@ -335,6 +379,9 @@ 

  %endif

  

  %changelog

+ * Fri Mar 16 2018 Miro Hrončok <mhroncok@redhat.com> - 2.4.3.0-3

+ - Don't build and ship Python 2 bits on EL > 7 and Fedora > 28

+ 

  * Wed Feb 07 2018 Fedora Release Engineering <releng@fedoraproject.org> - 2.4.3.0-2

  - Rebuilt for https://fedoraproject.org/wiki/Fedora_28_Mass_Rebuild

  

Note that:

  • I don't think Python 3 tests were run before at all, hacked it
  • Docs don't build on Python 3, should be brought upstream
  • The if-elsing is ugly sometimes, but I assumed this is "one specfile for every Fedora and EL out there" so I went with that

This PR is very raw, I'd appreciate feedback. The resulting RPM is untested.

1 new commit added

  • Provide and Obsolete -python3 if py3 is the main package
6 years ago

Note that this says firewall in comment and fireball in the provide. Not sure which one is good, but I've just moved this as is.

Well, I have been waiting to hear from upstream that we should switch to python3 as primary/only. I don't think they are ready for that change, but we can discuss it.

@toshio can you take a look at this? Should we look at 2.5.0 for python3 primary or keep pushing it out?

So, I think we are ok to Switch to python3 by default in f29(rawhide) and rhel > 7

Can you rebase with that and then I can update to the just released 2.5.0 (or you can in the PR if you want) and we can push the 2.5.0 out with this change.

rebased onto 200dae1

6 years ago

rebased, let's wait for the CI to give us a build to test?

I've created a skeleton/minimal change for f29:

https://fedoraproject.org/wiki/Changes/Ansible_python3_default

I've tested the scratch build and it seems to work fine here, but could we keep the python2 subpackage around (and just not default)? Some people may have some issue where being able to switch back until it's fixed is nice.

I won't be abale to make that change for couple of days. Please either do that or wait for ~Tuesday. (Feel free to remind me then.)

Thanks. I may get time this weekend, will see. Thanks for your efforts in any case...

ok. I did get some time to think/look at this along with the 2.5.0 update.

Upon further consideration, I think I am ok switching f29+ to python3 only.

  • Fedora 29 isn't due out until november, so thats a pretty long runway for Fedora users.
  • I suspect upstream will be focusing more on python3, making python2 fixes less urgent, and at least python3 bugs will get a lot of attention.
  • There are a number of other ways someone could switch back to python2 ansible currently if they really had to (pip install, virtualenv, ansible hacking/env-setup, custom ansible rpm, etc).
  • Also, epel7/rhel7 folks can keep using python2, so at the very least a rhel7/centos7 control host could be used.

The docs don't seem to build with python2 either in f28... will look more at that.

ok. I have pushed my changes based on this, so I am going to close this PR now. ;)

Thanks so much for the work!

The commit I pushed:

  • Uses python3 to build docs on all Fedoras (except on f26, which doesn't have pathfix.py, so I just special cased it for now).
  • f26/f27/f28 all keep the python3 built, but not default and runs tests on both python2 and python3 versions.
  • f29 drops python2 and makes python3 default and runs tests on python3
  • Updates to 2.5.0.

I'll work on filing/submitting the f29 change to let people know it's switching to python3 default.

Thanks again!

Pull-Request has been closed by kevin

6 years ago

Notable problems:

rendering: host_group_vars
../bin/testing_formatter.sh
DEPRECATION WARNING: python2 invoked with /usr/bin/python.
    Use /usr/bin/python3 or /usr/bin/python2
    /usr/bin/python will be removed or switched to Python 3 in the future.
    If you cannot make the switch now, please follow instructions at https://fedoraproject.org/wiki/Changes/Avoid_usr_bin_python_in_RPM_Build#Quick_Opt-Out

You need to pathfix also files in test/runner/test.py (those are invoked from testing_formatter.sh)

And:

loading intersphinx inventory from https://docs.python.org/2/objects.inv...
loading intersphinx inventory from ../python2-2.7.13.inv...

You want to use Python 3 intersphinx.

Also, my change did:

+ mkdir tests_bin
+ pushd tests_bin
+ # this is a hack and should be done differently!
+ ln -s `which pytest-3` pytest
+ ln -s %{__python3} python                    # <--- THIS
+ ln -s %{__python3} python2                   # <--- AND THIS
+ export PATH=$PATH:$(pwd)
+ popd

And I don't see any alternative in your commit. Are you absolutely sure your test run on Python 3?

(asciidoc pulls in python2, so in order to check if it builds without python2, you better disable all things that need asciidoc, don't buildrequire it and try a scratchbuild)

I could have messed up somewhere. ;)

Here's a f29 scratch build with the current spec:
https://koji.fedoraproject.org/koji/taskinfo?taskID=25994655

The tests have:

  • make PYTHON=/usr/bin/python3 tests-py3
    fatal: not a git repository (or any of the parent directories): .git
    fatal: not a git repository (or any of the parent directories): .git
    fatal: not a git repository (or any of the parent directories): .git
    test/runner/ansible-test units -v --python 3.6
    DEPRECATION WARNING: python2 invoked with /usr/bin/python.
    Use /usr/bin/python3 or /usr/bin/python2
    /usr/bin/python will be removed or switched to Python 3 in the future.
    If you cannot make the switch now, please follow instructions at https://fedoraproject.org/wiki/Changes/Avoid_usr_bin_python_in_RPM_Build#Quick_Opt-Out
    Unit test with Python 3.6
    Run command: pytest --boxed -r a --color no --junit-xml test/results/junit/python3.6-units.xml -v test/units/
    ============================= test session starts ==============================
    platform linux -- Python 3.6.4, pytest-3.4.2, py-1.5.3, pluggy-0.6.0 -- /usr/bin/python3.6
    cachedir: .pytest_cache
    rootdir: /builddir/build/BUILD/python3-ansible-2.5.0-1.fc29, inifile:
    plugins: xdist-1.22.2, mock-1.7.1, forked-0.2
    collecting ... collected 3201 items / 72 skipped
    ...
    ================== 3173 passed, 100 skipped in 570.59 seconds ==================

But if you want to look over the build and file a new PR with improvements, please do. ;)
Note that docs take forever to build, so if you are testing set with_docs to 0 in the appropriate places.

Hint: Every time you see

DEPRECATION WARNING: python2 invoked with /usr/bin/python. Use /usr/bin/python3 or /usr/bin/python2 /usr/bin/python will be removed or switched to Python 3 in the future.

In something that should run on Python 3 only, something is very wrong.

Yet here it is probably because stuff in test/runner has wrong shebangs. Additional pathfix call should fix that.