#2 Add %dnf_python macro that selects what dnf runs on
Merged 6 years ago by churchyard. Opened 6 years ago by churchyard.
rpms/ churchyard/dnf dnf_python_macro  into  master

file modified
+46 -37
@@ -13,14 +13,22 @@ 

  # Note that --without python2 will fail to build manpages

  # so it's currently unsupported

  # Also double check the results if you build with different combos

+ #

+ # %%dnf_python selects what dnf requires and what /usr/bin/dnf runs on

+ # The build has to be enabled, i.e. you cannot build --without python3

+ # and set dnf_python to python3 at the same time

+ # It should be one of: python2, python3, platform-python (with dash!)

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

+ %global dnf_python python2

  %bcond_without python2

  %bcond_with python3

  %bcond_with platform_python

  %else

+ %global dnf_python python3

+ #global dnf_python platform-python

  %bcond_without python2

  %bcond_without python3

- %bcond_with platform_python

+ %bcond_without platform_python

  %endif

  

  %if %{with python2}
@@ -40,7 +48,7 @@ 

  

  Name:           dnf

  Version:        2.6.3

- Release:        3%{?dist}

+ Release:        4%{?dist}

  Summary:        Package manager forked from Yum, using libsolv as a dependency resolver

  # For a breakdown of the licensing, see PACKAGE-LICENSING

  License:        GPLv2+ and GPLv2 and GPL
@@ -57,15 +65,8 @@ 

  BuildRequires:  %{_bindir}/sphinx-build

  BuildRequires:  systemd

  BuildRequires:  bash-completion

- %if %{with platform_python}

- Requires:       platform-python-%{name} = %{version}-%{release}

- %else

- %if %{with python3}

- Requires:       python3-%{name} = %{version}-%{release}

- %else

- Requires:       python2-%{name} = %{version}-%{release}

- %endif

- %endif

+ 

+ Requires:       %{dnf_python}-%{name} = %{version}-%{release}

  

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

  Requires:       python-dbus
@@ -330,45 +331,46 @@ 

  mkdir -p %{buildroot}%{_var}/cache/dnf/

  touch %{buildroot}%{_localstatedir}/log/%{name}.log

  

+ 

+ 

  %if %{with platform_python}

- %if %{with python3}

- cp %{buildroot}%{_bindir}/dnf-3 %{buildroot}%{_bindir}/dnf

- cp %{buildroot}%{_bindir}/dnf-automatic-3 %{buildroot}%{_bindir}/dnf-automatic

- %else

- mv %{buildroot}%{_bindir}/dnf-3 %{buildroot}%{_bindir}/dnf

- mv %{buildroot}%{_bindir}/dnf-automatic-3 %{buildroot}%{_bindir}/dnf-automatic

+ cp %{buildroot}%{_bindir}/dnf-3 %{buildroot}%{_bindir}/dnf-pp

+ cp %{buildroot}%{_bindir}/dnf-automatic-3 %{buildroot}%{_bindir}/dnf-automatic-pp

+ sed -i 's|#!%{__python3}|#!%{__platform_python}|' %{buildroot}%{_bindir}/dnf{,-automatic}-pp

+ %if %{without python3}

+ rm %{buildroot}%{_bindir}/*-3

  %endif

- sed -i 's|#!%{__python3}|#!%{__platform_python}|' %{buildroot}%{_bindir}/dnf{,-automatic}

- ln -sr  %{buildroot}%{_bindir}/dnf %{buildroot}%{_bindir}/yum

  %endif

  

  %if %{with python3}

- %if %{without platform_python}

- ln -sr %{buildroot}%{_bindir}/dnf-3 %{buildroot}%{_bindir}/dnf

- ln -sr  %{buildroot}%{_bindir}/dnf-3 %{buildroot}%{_bindir}/yum

- mv %{buildroot}%{_bindir}/dnf-automatic-3 %{buildroot}%{_bindir}/dnf-automatic

- %else

  sed -i 's|#!%{__platform_python}|#!%{__python3}|' %{buildroot}%{_bindir}/dnf{,-automatic}-3

  %endif

- %endif

  

- %if %{with python2} && %{without platform_python} && %{without python3}

- ln -sr %{buildroot}%{_bindir}/dnf-2 %{buildroot}%{_bindir}/dnf

- mv %{buildroot}%{_bindir}/dnf-automatic-2 %{buildroot}%{_bindir}/dnf-automatic

+ %if %{with python2}

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

  ln -sr  %{buildroot}%{_bindir}/dnf-2 %{buildroot}%{_bindir}/yum4

  ln -sr  %{buildroot}%{_mandir}/man8/dnf.8.gz %{buildroot}%{_mandir}/man8/yum4.8.gz

  rm -f %{buildroot}%{_mandir}/man8/yum.8.gz

- %else

- ln -sr  %{buildroot}%{_bindir}/dnf-2 %{buildroot}%{_bindir}/yum

  %endif

+ sed -i 's|#!/usr/bin/python|#!%{__python2}|' %{buildroot}%{_bindir}/*-2

  %endif

  

- rm -vf %{buildroot}%{_bindir}/dnf-automatic-*

+ ln -sr  %{buildroot}%{_bindir}/dnf %{buildroot}%{_bindir}/yum

  

- %if %{with python2}

- sed -i 's|#!/usr/bin/python|#!%{__python2}|' %{buildroot}%{_bindir}/dnf-2

+ %if "%{dnf_python}" == "python3"

+ ln -sr  %{buildroot}%{_bindir}/dnf-3 %{buildroot}%{_bindir}/dnf

+ mv -f  %{buildroot}%{_bindir}/dnf-automatic-3 %{buildroot}%{_bindir}/dnf-automatic

+ %else

+ %if "%{dnf_python}" == "python2"

+ ln -sr  %{buildroot}%{_bindir}/dnf-2 %{buildroot}%{_bindir}/dnf

+ mv -f %{buildroot}%{_bindir}/dnf-automatic-2 %{buildroot}%{_bindir}/dnf-automatic

+ %else

+ ln -sr  %{buildroot}%{_bindir}/dnf-pp %{buildroot}%{_bindir}/dnf

+ mv -f  %{buildroot}%{_bindir}/dnf-automatic-pp %{buildroot}%{_bindir}/dnf-automatic

+ %endif

  %endif

+ rm %{buildroot}%{_bindir}/dnf-automatic-*

+ 

  

  %check

  %if %{with python2}
@@ -481,6 +483,7 @@ 

  

  %if %{with platform_python}

  %files -n platform-python-%{name}

+ %{_bindir}/%{name}-pp

  %exclude %{platform_python_sitelib}/%{name}/automatic

  %{platform_python_sitelib}/%{name}/

  %dir %{platpypluginpath}
@@ -497,17 +500,23 @@ 

  %{_unitdir}/%{name}-automatic-download.timer

  %{_unitdir}/%{name}-automatic-install.service

  %{_unitdir}/%{name}-automatic-install.timer

- %if %{with platform_python}

- %{platform_python_sitelib}/%{name}/automatic/

- %else

- %if %{with python3}

+ 

+ 

+ %if "%{dnf_python}" == "python3"

  %{python3_sitelib}/%{name}/automatic/

  %else

+ %if "%{dnf_python}" == "python2"

  %{python2_sitelib}/%{name}/automatic/

+ %else

+ %{platform_python_sitelib}/%{name}/automatic/

  %endif

  %endif

  

  %changelog

+ * Tue Aug 22 2017 Miro Hrončok <mhroncok@redhat.com> - 2.6.3-4

+ - Add %%dnf_python macro that selects what dnf runs on

+ - Enable platform_python once again, but set %%dnf_python to python3

+ 

  * Mon Aug 21 2017 Tomas Orsava <torsava@redhat.com> - 2.6.3-3

  - Rebuilt without platform-python to revert the switch of /usr/bin/dnf to

    platform-python in standard Fedora

%global dnf_python platform-python

$ rpm -qp --requires dnf-2.6.3-4.fc28.noarch.rpm | egrep '(python|dnf)'
platform-python-dnf = 2.6.3-4.fc28

$ rpm -qp --requires dnf-automatic-2.6.3-4.fc28.noarch.rpm | egrep '(python|dnf)'
/usr/libexec/platform-python
config(dnf-automatic) = 2.6.3-4.fc28
dnf = 2.6.3-4.fc28
platform-python(abi) = 3.6

$ rpm -qp --requires python3-dnf-2.6.3-4.fc28.noarch.rpm | egrep '(python|dnf)'
/usr/bin/python3
dnf-conf = 2.6.3-4.fc28
python(abi) = 3.6
python3-gpg
python3-hawkey >= 0.9.3
python3-iniparse
python3-libcomps >= 0.1.8
python3-librepo >= 1.7.19
rpm-python3 >= 4.13.0-0.rc1.29

$ rpm -qp --requires python2-dnf-2.6.3-4.fc28.noarch.rpm | egrep '(python|dnf)'
/usr/bin/python2
dnf-conf = 2.6.3-4.fc28
python(abi) = 2.7
python-iniparse
python-libcomps >= 0.1.8
python-librepo >= 1.7.19
python2-gpg
python2-hawkey >= 0.9.3
rpm-python >= 4.13.0-0.rc1.29

$ rpm -qp --requires platform-python-dnf-2.6.3-4.fc28.noarch.rpm | egrep '(python|dnf)'
/usr/libexec/platform-python
dnf-conf = 2.6.3-4.fc28
platform-python(abi) = 3.6
platform-python-gpg
platform-python-hawkey >= 0.9.3
platform-python-iniparse
platform-python-libcomps >= 0.1.8
platform-python-librepo >= 1.7.19
platform-python-rpm >= 4.13.0-0.rc1.29

$ rpm -qplv dnf-2.6.3-4.fc28.noarch.rpm | grep bin
lrwxrwxrwx    1 root    root                        6 srp 22 14:18 /usr/bin/dnf -> dnf-pp

$ rpm -qplv dnf-automatic-2.6.3-4.fc28.noarch.rpm | grep bin
-rwxr-xr-x    1 root    root                     1291 srp 22 14:18 /usr/bin/dnf-automatic

$ rpm -qplv python2-dnf-2.6.3-4.fc28.noarch.rpm | grep bin
-rwxr-xr-x    1 root    root                     1942 srp 22 14:18 /usr/bin/dnf-2

$ rpm -qplv python3-dnf-2.6.3-4.fc28.noarch.rpm | grep bin
-rwxr-xr-x    1 root    root                     1942 srp 22 14:18 /usr/bin/dnf-3

$ rpm -qplv platform-python-dnf-2.6.3-4.fc28.noarch.rpm | grep bin
-rwxr-xr-x    1 root    root                     1954 srp 22 14:18 /usr/bin/dnf-pp

%global dnf_python python3

$ rpm -qp --requires dnf-2.6.3-4.fc28.noarch.rpm | egrep '(python|dnf)'
python3-dnf = 2.6.3-4.fc28

$ rpm -qp --requires dnf-automatic-2.6.3-4.fc28.noarch.rpm | egrep '(python|dnf)'
/usr/bin/python3
config(dnf-automatic) = 2.6.3-4.fc28
dnf = 2.6.3-4.fc28
python(abi) = 3.6

$ rpm -qp --requires python3-dnf-2.6.3-4.fc28.noarch.rpm | egrep '(python|dnf)'
/usr/bin/python3
dnf-conf = 2.6.3-4.fc28
python(abi) = 3.6
python3-gpg
python3-hawkey >= 0.9.3
python3-iniparse
python3-libcomps >= 0.1.8
python3-librepo >= 1.7.19
rpm-python3 >= 4.13.0-0.rc1.29

$ rpm -qp --requires python2-dnf-2.6.3-4.fc28.noarch.rpm | egrep '(python|dnf)'
/usr/bin/python2
dnf-conf = 2.6.3-4.fc28
python(abi) = 2.7
python-iniparse
python-libcomps >= 0.1.8
python-librepo >= 1.7.19
python2-gpg
python2-hawkey >= 0.9.3
rpm-python >= 4.13.0-0.rc1.29

$ rpm -qp --requires platform-python-dnf-2.6.3-4.fc28.noarch.rpm | egrep '(python|dnf)'
/usr/libexec/platform-python
dnf-conf = 2.6.3-4.fc28
platform-python(abi) = 3.6
platform-python-gpg
platform-python-hawkey >= 0.9.3
platform-python-iniparse
platform-python-libcomps >= 0.1.8
platform-python-librepo >= 1.7.19
platform-python-rpm >= 4.13.0-0.rc1.29

$ rpm -qplv dnf-2.6.3-4.fc28.noarch.rpm | grep bin
lrwxrwxrwx    1 root    root                        5 srp 22 14:33 /usr/bin/dnf -> dnf-3

$ rpm -qplv dnf-automatic-2.6.3-4.fc28.noarch.rpm | grep bin
-rwxr-xr-x    1 root    root                     1279 srp 22 14:33 /usr/bin/dnf-automatic

$ rpm -qplv python2-dnf-2.6.3-4.fc28.noarch.rpm | grep bin
-rwxr-xr-x    1 root    root                     1942 srp 22 14:33 /usr/bin/dnf-2

$ rpm -qplv python3-dnf-2.6.3-4.fc28.noarch.rpm | grep bin
-rwxr-xr-x    1 root    root                     1942 srp 22 14:33 /usr/bin/dnf-3

$ rpm -qplv platform-python-dnf-2.6.3-4.fc28.noarch.rpm | grep bin
-rwxr-xr-x    1 root    root                     1954 srp 22 14:33 /usr/bin/dnf-pp

%global dnf_python python2

$ rpm -qp --requires dnf-2.6.3-4.fc28.noarch.rpm | egrep '(python|dnf)'
python2-dnf = 2.6.3-4.fc28

$ rpm -qp --requires dnf-automatic-2.6.3-4.fc28.noarch.rpm | egrep '(python|dnf)'
/usr/bin/python2
config(dnf-automatic) = 2.6.3-4.fc28
dnf = 2.6.3-4.fc28
python(abi) = 2.7

$ rpm -qp --requires python3-dnf-2.6.3-4.fc28.noarch.rpm | egrep '(python|dnf)'
/usr/bin/python3
dnf-conf = 2.6.3-4.fc28
python(abi) = 3.6
python3-gpg
python3-hawkey >= 0.9.3
python3-iniparse
python3-libcomps >= 0.1.8
python3-librepo >= 1.7.19
rpm-python3 >= 4.13.0-0.rc1.29

$ rpm -qp --requires python2-dnf-2.6.3-4.fc28.noarch.rpm | egrep '(python|dnf)'
/usr/bin/python2
dnf-conf = 2.6.3-4.fc28
python(abi) = 2.7
python-iniparse
python-libcomps >= 0.1.8
python-librepo >= 1.7.19
python2-gpg
python2-hawkey >= 0.9.3
rpm-python >= 4.13.0-0.rc1.29

$ rpm -qp --requires platform-python-dnf-2.6.3-4.fc28.noarch.rpm | egrep '(python|dnf)'
/usr/libexec/platform-python
dnf-conf = 2.6.3-4.fc28
platform-python(abi) = 3.6
platform-python-gpg
platform-python-hawkey >= 0.9.3
platform-python-iniparse
platform-python-libcomps >= 0.1.8
platform-python-librepo >= 1.7.19
platform-python-rpm >= 4.13.0-0.rc1.29

$ rpm -qplv dnf-2.6.3-4.fc28.noarch.rpm | grep bin
lrwxrwxrwx    1 root    root                        5 srp 22 14:29 /usr/bin/dnf -> dnf-2

$ rpm -qplv dnf-automatic-2.6.3-4.fc28.noarch.rpm | grep bin
-rwxr-xr-x    1 root    root                     1279 srp 22 14:29 /usr/bin/dnf-automatic

$ rpm -qplv python2-dnf-2.6.3-4.fc28.noarch.rpm | grep bin
-rwxr-xr-x    1 root    root                     1942 srp 22 14:29 /usr/bin/dnf-2

$ rpm -qplv python3-dnf-2.6.3-4.fc28.noarch.rpm | grep bin
-rwxr-xr-x    1 root    root                     1942 srp 22 14:29 /usr/bin/dnf-3

$ rpm -qplv platform-python-dnf-2.6.3-4.fc28.noarch.rpm | grep bin
-rwxr-xr-x    1 root    root                     1954 srp 22 14:29 /usr/bin/dnf-pp

Since the Modularity team doesn't mind changing the spec rather than setting %bcond, this looks like the best approach.
LGTM

Also, they can change the macro.

Pull-Request has been merged by churchyard

6 years ago

The macro definitely makes sense to me, since a 3-way bcond does not exist. However, from modulemd you can only override bcond's, not macros. That being said, contyk expressly said he was planning it that way, so it matters not.

LGTM!

Another commit was added later that adds if-else condition for module build, so no macro / bcond overrides will be needed on modulemd level.

Metadata