URL: https://github.com/freeipa/freeipa/pull/272
Author: pspacek
 Title: #272: Build: makerpms.sh generates Python 2 & 3 packages at the same 
time
Action: synchronized

To pull the PR as Git branch:
git remote add ghfreeipa https://github.com/freeipa/freeipa
git fetch ghfreeipa pull/272/head:pr272
git checkout pr272
From f7beaa42acb6ebba8ff71326144510e0fc631606 Mon Sep 17 00:00:00 2001
From: Petr Spacek <pspa...@redhat.com>
Date: Thu, 24 Nov 2016 17:35:24 +0100
Subject: [PATCH 1/2] Build: makerpms.sh generates Python 2 & 3 packages at the
 same time

Petr Viktorin recommended me to copy the whole build directory and run
configure twice, with different values for PYTHON variable.

After thinking a bit about that, it seems as cleanest approach.
Building for two versions of Python at the same time should be
temporary state so I decided not to complicate Autotools build system
with conditional spagetti for two versions of Python.

For proper Python2/3 distiction in the two separate builds, I added
find/grep/sed combo which replaces shebangs with system-wide Python
interpreter as necessary. This is workaround for the fact that FreeIPA
does not use setuptools properly. Honza told me that proper use of
setuptools is not trivial so we decided to go with this for now.

https://fedorahosted.org/freeipa/ticket/157
---
 freeipa.spec.in | 148 +++++++++++++++++++++++++++++++++++++-------------------
 1 file changed, 97 insertions(+), 51 deletions(-)

diff --git a/freeipa.spec.in b/freeipa.spec.in
index 6847bed..bf9c788 100644
--- a/freeipa.spec.in
+++ b/freeipa.spec.in
@@ -5,7 +5,7 @@
 %if 0%{?rhel}
 %global with_python3 0
 %else
-%global with_python3 0
+%global with_python3 1
 %endif
 
 # lint is not executed during rpmbuild
@@ -267,6 +267,37 @@ and integration with Active Directory based infrastructures (Trusts).
 If you are installing an IPA server, you need to install this package.
 
 
+%if 0%{?with_python3}
+
+%package -n python3-ipaserver
+Summary: Python libraries used by IPA server
+Group: System Environment/Libraries
+BuildArch: noarch
+%{?python_provide:%python_provide python3-ipaserver}
+Requires: %{name}-server-common = %{version}-%{release}
+Requires: %{name}-common = %{version}-%{release}
+Requires: python3-ipaclient = %{version}-%{release}
+Requires: python3-pyldap >= 2.4.15
+Requires: python3-lxml
+Requires: python3-gssapi >= 1.1.2
+Requires: python3-sssdconfig
+Requires: python3-pyasn1
+Requires: python3-dbus
+Requires: python3-dns >= 1.11.1
+Requires: python3-kdcproxy >= 0.3
+Requires: rpm-libs
+
+%description -n python3-ipaserver
+IPA is an integrated solution to provide centrally managed Identity (users,
+hosts, services), Authentication (SSO, 2FA), and Authorization
+(host access control, SELinux user roles, services). The solution provides
+features for further integration with Linux based clients (SUDO, automount)
+and integration with Active Directory based infrastructures (Trusts).
+If you are installing an IPA server, you need to install this package.
+
+%endif  # with_python3
+
+
 %package server-common
 Summary: Common files used by IPA server
 Group: System Environment/Base
@@ -684,6 +715,11 @@ This package contains tests that verify IPA functionality under Python 3.
 
 %prep
 %setup -n freeipa-%{version} -q
+%if 0%{?with_python3}
+# Workaround: We want to build Python things twice. To be sure we do not mess
+# up something, do two separate builds in separate directories.
+cp -r %{_builddir}/freeipa-%{version} %{_builddir}/freeipa-%{version}-python3
+%endif # with_python3
 
 
 %build
@@ -691,10 +727,33 @@ This package contains tests that verify IPA functionality under Python 3.
 export JAVA_STACK_SIZE="8m"
 # PATH is workaround for https://bugzilla.redhat.com/show_bug.cgi?id=1005235
 export PATH=/usr/bin:/usr/sbin:$PATH
+export PYTHON=%{__python2}
+# Workaround: make sure all shebangs are pointing to Python 2
+# This should be solved properly using setuptools
+# and this hack should be removed.
+find \
+	! -name '*.pyc' -a \
+	! -name '*.pyo' -a \
+	-type f -exec grep -qsm1 '^#!.*\bpython' {} \; \
+	-exec sed -i -e '1 s|^#!.*\bpython[^ ]*|#!%{__python2}|' {} \;
 %configure --with-vendor-suffix=-%{release}
 # -Onone is workaround for https://bugzilla.redhat.com/show_bug.cgi?id=1398405
 %make_build -Onone
 
+%if 0%{?with_python3}
+pushd %{_builddir}/freeipa-%{version}-python3
+export PYTHON=%{__python3}
+# Workaround: make sure all shebangs are pointing to Python 3
+# This should be solved properly using setuptools
+# and this hack should be removed.
+find \
+	! -name '*.pyc' -a \
+	! -name '*.pyo' -a \
+	-type f -exec grep -qsm1 '^#!.*\bpython' {} \; \
+	-exec sed -i -e '1 s|^#!.*\bpython[^ ]*|#!%{__python3}|' {} \;
+%configure --with-vendor-suffix=-%{release}
+popd
+%endif # with_python3
 
 %check
 %if ! %{ONLY_CLIENT}
@@ -713,16 +772,25 @@ make %{?_smp_mflags} client-check VERBOSE=yes LIBDIR=%{_libdir}
 # All files and directories created by spec install should be marked as ghost.
 # (These are typically configuration files created by IPA installer.)
 # All other artifacts should be created by make install.
+#
+# Exception to this rule are test programs which where want to install
+# Python2/3 versions at the same time so we need to rename them. Yuck.
 %make_install
-# remove files which are useful only for make uninstall
-find %{buildroot} -wholename '*/site-packages/*/install_files.txt' -exec rm {} \;
-
 mv %{buildroot}%{_bindir}/ipa-run-tests %{buildroot}%{_bindir}/ipa-run-tests-%{python2_version}
 mv %{buildroot}%{_bindir}/ipa-test-config %{buildroot}%{_bindir}/ipa-test-config-%{python2_version}
 mv %{buildroot}%{_bindir}/ipa-test-task %{buildroot}%{_bindir}/ipa-test-task-%{python2_version}
 
+
 %if 0%{?with_python3}
-(cd ipatests && %{__python3} setup.py install --root %{buildroot})
+pushd %{_builddir}/freeipa-%{version}-python3
+(cd ipaclient && %make_install)
+(cd ipalib && %make_install)
+(cd ipaplatform && %make_install)
+(cd ipapython && %make_install)
+(cd ipaserver && %make_install)
+(cd ipatests && %make_install)
+popd
+
 mv %{buildroot}%{_bindir}/ipa-run-tests %{buildroot}%{_bindir}/ipa-run-tests-%{python3_version}
 mv %{buildroot}%{_bindir}/ipa-test-config %{buildroot}%{_bindir}/ipa-test-config-%{python3_version}
 mv %{buildroot}%{_bindir}/ipa-test-task %{buildroot}%{_bindir}/ipa-test-task-%{python3_version}
@@ -731,6 +799,8 @@ ln -s %{_bindir}/ipa-test-config-%{python3_version} %{buildroot}%{_bindir}/ipa-t
 ln -s %{_bindir}/ipa-test-task-%{python3_version} %{buildroot}%{_bindir}/ipa-test-task-3
 %endif # with_python3
 
+
+# test framework defaults to Python 2
 ln -s %{_bindir}/ipa-run-tests-%{python2_version} %{buildroot}%{_bindir}/ipa-run-tests-2
 ln -s %{_bindir}/ipa-test-config-%{python2_version} %{buildroot}%{_bindir}/ipa-test-config-2
 ln -s %{_bindir}/ipa-test-task-%{python2_version} %{buildroot}%{_bindir}/ipa-test-task-2
@@ -738,17 +808,9 @@ ln -s %{_bindir}/ipa-run-tests-%{python2_version} %{buildroot}%{_bindir}/ipa-run
 ln -s %{_bindir}/ipa-test-config-%{python2_version} %{buildroot}%{_bindir}/ipa-test-config
 ln -s %{_bindir}/ipa-test-task-%{python2_version} %{buildroot}%{_bindir}/ipa-test-task
 
-%if 0%{?with_python3}
-(cd ipalib && make PYTHON=%{__python3} IPA_VERSION_IS_GIT_SNAPSHOT=no %{?_smp_mflags} DESTDIR=%{buildroot} LIBDIR=%{_libdir} install)
-(cd ipapython && make PYTHON=%{__python3} IPA_VERSION_IS_GIT_SNAPSHOT=no %{?_smp_mflags} DESTDIR=%{buildroot} LIBDIR=%{_libdir} install)
-(cd ipaplatform && %{__python3} setup.py install --root %{buildroot})
-(cd ipaclient && %{__python3} setup.py install --root %{buildroot})
-%endif # with_python3
 
-# Switch shebang of /usr/bin/ipa
-# XXX: ipa cli is not stable enough for enabling py3 support, keep it in py2
-# in any case
-sed -i -e'1s/python\(3\|$\)/python2/' %{buildroot}%{_bindir}/ipa
+# remove files which are useful only for make uninstall
+find %{buildroot} -wholename '*/site-packages/*/install_files.txt' -exec rm {} \;
 
 %find_lang %{gettext_domain}
 
@@ -797,15 +859,6 @@ touch %{buildroot}%{_libdir}/krb5/plugins/libkrb5/winbind_krb5_locator.so
 
 %if ! %{ONLY_CLIENT}
 mkdir -p %{buildroot}%{_sysconfdir}/cron.d
-
-(cd %{buildroot}/%{python_sitelib}/ipaserver && find . -type f  | \
-    sed -e 's,\.py.*$,.*,g' | sort -u | \
-    sed -e 's,\./,%%{python_sitelib}/ipaserver/,g' ) >server-python.list
-
-(cd %{buildroot}/%{python_sitelib}/ipatests && find . -type f  | \
-    sed -e 's,\.py.*$,.*,g' | sort -u | \
-    sed -e 's,\./,%%{python_sitelib}/ipatests/,g' ) >tests-python.list
-
 %endif # ONLY_CLIENT
 
 
@@ -1059,20 +1112,24 @@ fi
 %{_mandir}/man1/ipa-winsync-migrate.1*
 
 
-%files -n python2-ipaserver -f server-python.list
+%files -n python2-ipaserver
 %defattr(-,root,root,-)
 %doc README Contributors.txt
 %license COPYING
-%{python_sitelib}/ipaserver-*.egg-info
-%dir %{python_sitelib}/ipaserver
-%dir %{python_sitelib}/ipaserver/dnssec
-%dir %{python_sitelib}/ipaserver/install
-%dir %{python_sitelib}/ipaserver/install/plugins
-%dir %{python_sitelib}/ipaserver/install/server
-%dir %{python_sitelib}/ipaserver/advise
-%dir %{python_sitelib}/ipaserver/advise/plugins
-%dir %{python_sitelib}/ipaserver/plugins
-%dir %{python_sitelib}/ipaserver/secrets
+%{python2_sitelib}/ipaserver
+%{python2_sitelib}/ipaserver-*.egg-info
+
+
+%if 0%{?with_python3}
+
+%files -n python3-ipaserver
+%defattr(-,root,root,-)
+%doc README Contributors.txt
+%license COPYING
+%{python3_sitelib}/ipaserver
+%{python3_sitelib}/ipaserver-*.egg-info
+
+%endif # with_python3
 
 
 %files server-common
@@ -1325,21 +1382,12 @@ fi
 
 %if ! %{ONLY_CLIENT}
 
-%files -n python2-ipatests -f tests-python.list
+%files -n python2-ipatests
 %defattr(-,root,root,-)
 %doc README Contributors.txt
 %license COPYING
-%dir %{python_sitelib}/ipatests
-%dir %{python_sitelib}/ipatests/test_cmdline
-%dir %{python_sitelib}/ipatests/test_install
-%dir %{python_sitelib}/ipatests/test_ipalib
-%dir %{python_sitelib}/ipatests/test_ipapython
-%dir %{python_sitelib}/ipatests/test_ipaserver
-%dir %{python_sitelib}/ipatests/test_ipaserver/test_install
-%dir %{python_sitelib}/ipatests/test_ipaserver/data
-%dir %{python_sitelib}/ipatests/test_pkcs10
-%dir %{python_sitelib}/ipatests/test_webui
-%dir %{python_sitelib}/ipatests/test_xmlrpc
+%{python_sitelib}/ipatests
+%{python_sitelib}/ipatests-*.egg-info
 %{_bindir}/ipa-run-tests
 %{_bindir}/ipa-test-config
 %{_bindir}/ipa-test-task
@@ -1349,7 +1397,6 @@ fi
 %{_bindir}/ipa-run-tests-%{python2_version}
 %{_bindir}/ipa-test-config-%{python2_version}
 %{_bindir}/ipa-test-task-%{python2_version}
-%{python_sitelib}/ipatests-*.egg-info
 %{_mandir}/man1/ipa-run-tests.1*
 %{_mandir}/man1/ipa-test-config.1*
 %{_mandir}/man1/ipa-test-task.1*
@@ -1360,15 +1407,14 @@ fi
 %defattr(-,root,root,-)
 %doc README Contributors.txt
 %license COPYING
-
-%{python3_sitelib}/ipatests/
+%{python3_sitelib}/ipatests
+%{python3_sitelib}/ipatests-*.egg-info
 %{_bindir}/ipa-run-tests-3
 %{_bindir}/ipa-test-config-3
 %{_bindir}/ipa-test-task-3
 %{_bindir}/ipa-run-tests-%{python3_version}
 %{_bindir}/ipa-test-config-%{python3_version}
 %{_bindir}/ipa-test-task-%{python3_version}
-%{python3_sitelib}/ipatests-*.egg-info
 
 %endif # with_python3
 

From de0f80a89a1267a2ad61172b06ce342ad1542968 Mon Sep 17 00:00:00 2001
From: Petr Spacek <pspa...@redhat.com>
Date: Wed, 30 Nov 2016 13:38:07 +0100
Subject: [PATCH 2/2] Build: specify BuildRequires for Python 3 pylint

python3-samba is intentionally ommited because it is not in Fedora repos.
Pylint somehow magically ignores this missing package.
Keep in mind that server will not work until this this solved.

https://fedorahosted.org/freeipa/ticket/157
---
 freeipa.spec.in | 39 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 39 insertions(+)

diff --git a/freeipa.spec.in b/freeipa.spec.in
index bf9c788..8484e01 100644
--- a/freeipa.spec.in
+++ b/freeipa.spec.in
@@ -97,6 +97,7 @@ BuildRequires:  python-lesscpy
 
 #
 # Build dependencies for makeapi/makeaci
+# makeapi/makeaci is using Python 2 only for now
 #
 BuildRequires:  python-ldap
 BuildRequires:  python-nss
@@ -145,6 +146,44 @@ BuildRequires:  python-sssdconfig
 BuildRequires:  python-nose
 BuildRequires:  python-paste
 BuildRequires:  systemd-python
+
+%if 0%{?with_python3}
+# FIXME: this depedency is missing - server will not work
+#BuildRequires:  python3-samba
+BuildRequires:  python3-setuptools
+# 0.6: serialization.load_pem_private_key, load_pem_public_key
+BuildRequires:  python3-cryptography >= 0.6
+BuildRequires:  python3-gssapi
+BuildRequires:  python3-pylint >= 1.0
+# workaround for https://bugzilla.redhat.com/show_bug.cgi?id=1096506
+BuildRequires:  python3-polib
+BuildRequires:  python3-libipa_hbac
+BuildRequires:  python3-memcached
+BuildRequires:  python3-lxml
+# 5.0.0: QRCode.print_ascii
+BuildRequires:  python3-qrcode-core >= 5.0.0
+# 1.13: python-dns URI record support
+BuildRequires:  python3-dns >= 1.13
+BuildRequires:  python3-yubico
+# pki Python package
+# 10.2.1: crypto.NSSCryptoProvider(password_file)
+BuildRequires:  pki-base-python3 >= 10.2.1
+BuildRequires:  python3-pytest-multihost
+BuildRequires:  python3-pytest-sourceorder
+BuildRequires:  python3-jwcrypto
+BuildRequires:  python3-custodia
+BuildRequires:  python3-dbus
+BuildRequires:  python3-dateutil
+BuildRequires:  python3-enum34
+BuildRequires:  python3-netifaces
+BuildRequires:  python3-sss
+BuildRequires:  python3-sss-murmur
+BuildRequires:  python3-sssdconfig
+BuildRequires:  python3-libsss_nss_idmap
+BuildRequires:  python3-nose
+BuildRequires:  python3-paste
+BuildRequires:  python3-systemd
+%endif # with_python3
 %endif # with_lint
 
 #
-- 
Manage your subscription for the Freeipa-devel mailing list:
https://www.redhat.com/mailman/listinfo/freeipa-devel
Contribute to FreeIPA: http://www.freeipa.org/page/Contribute/Code

Reply via email to