From 55fa35a37f18410b36f3ff5d4becf0c3679c747c Mon Sep 17 00:00:00 2001 From: Neal Gompa Date: Aug 23 2018 14:25:51 +0000 Subject: Declare Python 3 support and prefer it in packaging Now that Pagure supports Python 3 and it appears to work across the board, we should prefer it by default and package for Python 3 whenever it is reasonably possible. Also, since we dropped EL6 support, Python 2.6 support is also dropped. Signed-off-by: Neal Gompa --- diff --git a/README.rst b/README.rst index 7be5b81..66d7dd9 100644 --- a/README.rst +++ b/README.rst @@ -137,16 +137,16 @@ Manually * Install the needed system libraries:: - sudo dnf install git python2-virtualenv libgit2-devel redis \ + sudo dnf install git python3-virtualenv libgit2-devel redis \ libjpeg-devel gcc libffi-devel redhat-rpm-config .. note:: Do note the version of libgit2 that you install, for example in ``libgit2-0.23.4-1`` you need to keep in mind the ``0.23`` - .. note:: On Fedora 23 and earlier or on RHEL and derivative (CentOS, - Scientific Linux) the package `python2-virtualenv` is named - `python-virtualenv` + .. note:: On RHEL and derivative (CentOS, Scientific Linux) the package + `python3-virtualenv` is named `python34-virtualenv` and is + available through EPEL. * Retrieve the sources:: @@ -157,7 +157,7 @@ Manually * create the virtualenv:: - virtualenv pagure_env + virtualenv-3 pagure_env source ./pagure_env/bin/activate * Install the correct version of pygit2:: diff --git a/createdb.py b/createdb.py index 27a261c..f7210a1 100644 --- a/createdb.py +++ b/createdb.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python2 +#!/usr/bin/env python from __future__ import print_function, unicode_literals diff --git a/files/pagure.conf b/files/pagure.conf index 150997c..f6b6bea 100644 --- a/files/pagure.conf +++ b/files/pagure.conf @@ -33,7 +33,7 @@ #SSLCertificateChainFile /etc/pki/tls/....intermediate.crt #SSLCertificateKeyFile /etc/pki/tls/....key - #Alias /static /usr/lib/python2.7/site-packages/pagure/static/ + #Alias /static /usr/lib/pythonX.Y/site-packages/pagure/static/ # #WSGIProcessGroup paguredocs @@ -64,7 +64,7 @@ #SSLCertificateChainFile /etc/pki/tls/....intermediate.crt #SSLCertificateKeyFile /etc/pki/tls/....key - #Alias /static /usr/lib/python2.7/site-packages/pagure/static/ + #Alias /static /usr/lib/pythonX.Y/site-packages/pagure/static/ #Alias /releases /var/www/releases ## Section used to support cloning git repo over http (https in this case) diff --git a/files/pagure.spec b/files/pagure.spec index 4d1549d..306359c 100644 --- a/files/pagure.spec +++ b/files/pagure.spec @@ -1,8 +1,14 @@ %{?python_enable_dependency_generator} -%if (0%{?fedora} && 0%{?fedora} <= 27) || (0%{?rhel} && 0%{?rhel} <= 7) + +%if (0%{?rhel} && 0%{?rhel} <= 7) +# Since the Python 3 stack in EPEL is missing too many dependencies, +# we're sticking with Python 2 there for now. +%global __python %{__python2} %global python_pkgversion %{nil} %else -%global python_pkgversion 2 +# Default to Python 3 when not EL +%global __python %{__python3} +%global python_pkgversion %{python3_pkgversion} %endif @@ -63,7 +69,7 @@ Requires: python%{python_pkgversion}-straight-plugin Requires: python%{python_pkgversion}-wtforms %endif -%if (0%{?fedora} && 0%{?fedora} <= 27) || (0%{?rhel} && 0%{?rhel} <= 7) +%if (0%{?rhel} && 0%{?rhel} <= 7) Requires: mod_wsgi %else Requires: python%{python_pkgversion}-mod_wsgi @@ -178,13 +184,21 @@ of this pagure instance. chmod +x pagure/hooks/files/* chmod +x files/api_key_expire_mail.py +%if 0%{?rhel} && 0%{?rhel} <= 7 +# Fix requirements.txt for EL7 setuptools +## Remove environment markers, as they're not supported +sed -e "s/;python_version.*$//g" -i requirements.txt +## Drop python3-openid requirement +sed -e "s/^python3-openid$//g" -i requirements.txt +%endif + %build -%py2_build +%py_build %install -%py2_install +%py_install # Install apache configuration file mkdir -p $RPM_BUILD_ROOT/%{_sysconfdir}/httpd/conf.d/ @@ -203,7 +217,7 @@ install -p -m 644 files/doc_pagure.wsgi $RPM_BUILD_ROOT/%{_datadir}/pagure/doc_p install -p -m 644 createdb.py $RPM_BUILD_ROOT/%{_datadir}/pagure/pagure_createdb.py # Install the api_key_expire_mail.py script -install -p -m 755 files/api_key_expire_mail.py $RPM_BUILD_ROOT/%{_datadir}/pagure/api_key_expire_mail.py +install -p -m 644 files/api_key_expire_mail.py $RPM_BUILD_ROOT/%{_datadir}/pagure/api_key_expire_mail.py # Install the alembic configuration file install -p -m 644 files/alembic.ini $RPM_BUILD_ROOT/%{_sysconfdir}/pagure/alembic.ini @@ -264,6 +278,28 @@ install -p -m 755 pagure-ev/pagure_stream_server.py \ install -p -m 644 pagure-ev/pagure_ev.service \ $RPM_BUILD_ROOT/%{_unitdir}/pagure_ev.service +# Fix the shebang for various scripts +sed -e "s|#!/usr/bin/env python|#!%{__python}|" -i \ + $RPM_BUILD_ROOT/%{_libexecdir}/pagure-ev/pagure_stream_server.py \ + $RPM_BUILD_ROOT/%{_datadir}/pagure/comment_email_milter.py \ + $RPM_BUILD_ROOT/%{_datadir}/pagure/pagure_createdb.py \ + $RPM_BUILD_ROOT/%{_datadir}/pagure/api_key_expire_mail.py \ + $RPM_BUILD_ROOT/%{python_sitelib}/pagure/hooks/files/*.py + +# Switch interpreter for systemd units +sed -e "s|/usr/bin/python|%{__python}|g" -i $RPM_BUILD_ROOT/%{_unitdir}/*.service + +%if 0%{?rhel} && 0%{?rhel} <= 7 +# Change to correct static file path for apache httpd +sed -e "s/pythonX.Y/python%{python2_version}/g" -i $RPM_BUILD_ROOT/%{_sysconfdir}/httpd/conf.d/pagure.conf +%else +# Switch all systemd units to use the correct celery +sed -e "s|/usr/bin/celery|/usr/bin/celery-3|g" -i $RPM_BUILD_ROOT/%{_unitdir}/*.service + +# Change to correct static file path for apache httpd +sed -e "s/pythonX.Y/python%{python3_version}/g" -i $RPM_BUILD_ROOT/%{_sysconfdir}/httpd/conf.d/pagure.conf +%endif + %post %systemd_post pagure_worker.service @@ -334,9 +370,9 @@ install -p -m 644 pagure-ev/pagure_ev.service \ %config(noreplace) %{_datadir}/pagure/*.wsgi %{_datadir}/pagure/*.py* %{_datadir}/pagure/alembic/ -%{python2_sitelib}/pagure/ -%exclude %{python2_sitelib}/pagure/themes/pagureio -%{python2_sitelib}/pagure*.egg-info +%{python_sitelib}/pagure/ +%exclude %{python_sitelib}/pagure/themes/pagureio +%{python_sitelib}/pagure*.egg-info %{_bindir}/pagure-admin %{_unitdir}/pagure_worker.service %{_unitdir}/pagure_gitolite_worker.service diff --git a/files/pagure_api_key_expire_mail.service b/files/pagure_api_key_expire_mail.service index 4b39835..94a9f48 100644 --- a/files/pagure_api_key_expire_mail.service +++ b/files/pagure_api_key_expire_mail.service @@ -3,7 +3,7 @@ Description=Send reminder emails about API key expiration Documentation=https://pagure.io/pagure [Service] -ExecStart=/usr/share/pagure/api_key_expire_mail.py +ExecStart=/usr/bin/python /usr/share/pagure/api_key_expire_mail.py Environment="PAGURE_CONFIG=/etc/pagure/pagure.cfg" Type=simple User=git diff --git a/pagure-milters/comment_email_milter.py b/pagure-milters/comment_email_milter.py index 037dff3..c557afb 100644 --- a/pagure-milters/comment_email_milter.py +++ b/pagure-milters/comment_email_milter.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python2 +#!/usr/bin/env python # -*- coding: utf-8 -*- # Milter calls methods of your class at milter events. diff --git a/pagure-milters/pagure_milter.service b/pagure-milters/pagure_milter.service index 7cc6b01..4a0f39b 100644 --- a/pagure-milters/pagure_milter.service +++ b/pagure-milters/pagure_milter.service @@ -4,7 +4,7 @@ After=postfix.target Documentation=https://github.com/pypingou/pagure [Service] -ExecStart=/usr/bin/python2 /usr/share/pagure/comment_email_milter.py +ExecStart=/usr/bin/python /usr/share/pagure/comment_email_milter.py Type=simple User=postfix Group=postfix diff --git a/pagure/hooks/files/default_hook.py b/pagure/hooks/files/default_hook.py index 6eea6a3..0dd4376 100755 --- a/pagure/hooks/files/default_hook.py +++ b/pagure/hooks/files/default_hook.py @@ -1,4 +1,4 @@ -#! /usr/bin/env python2 +#!/usr/bin/env python """Pagure specific hook to be added to all projects in pagure by default. diff --git a/pagure/hooks/files/git_multimail.py b/pagure/hooks/files/git_multimail.py index e096d4b..30eb1c6 100755 --- a/pagure/hooks/files/git_multimail.py +++ b/pagure/hooks/files/git_multimail.py @@ -1,4 +1,4 @@ -#! /usr/bin/env python2 +#!/usr/bin/env python # flake8: noqa diff --git a/pagure/hooks/files/pagure_block_unsigned.py b/pagure/hooks/files/pagure_block_unsigned.py index cdb066e..00430a4 100755 --- a/pagure/hooks/files/pagure_block_unsigned.py +++ b/pagure/hooks/files/pagure_block_unsigned.py @@ -1,4 +1,4 @@ -#! /usr/bin/env python2 +#!/usr/bin/env python """Pagure specific hook to block commit not having a 'Signed-off-by' diff --git a/pagure/hooks/files/pagure_force_commit_hook.py b/pagure/hooks/files/pagure_force_commit_hook.py index 4b04f81..495f441 100755 --- a/pagure/hooks/files/pagure_force_commit_hook.py +++ b/pagure/hooks/files/pagure_force_commit_hook.py @@ -1,4 +1,4 @@ -#! /usr/bin/env python2 +#!/usr/bin/env python """Pagure specific hook to block non-fastforward pushes. diff --git a/pagure/hooks/files/pagure_hook.py b/pagure/hooks/files/pagure_hook.py index 14ba072..5747824 100755 --- a/pagure/hooks/files/pagure_hook.py +++ b/pagure/hooks/files/pagure_hook.py @@ -1,4 +1,4 @@ -#! /usr/bin/env python2 +#!/usr/bin/env python """Pagure specific hook to add comment on issues if the commits fixes or diff --git a/pagure/hooks/files/pagure_hook_requests.py b/pagure/hooks/files/pagure_hook_requests.py index 219f774..2cce399 100755 --- a/pagure/hooks/files/pagure_hook_requests.py +++ b/pagure/hooks/files/pagure_hook_requests.py @@ -1,4 +1,4 @@ -#! /usr/bin/env python2 +#!/usr/bin/env python """Pagure specific hook to update pull-requests stored in the database diff --git a/pagure/hooks/files/pagure_hook_tickets.py b/pagure/hooks/files/pagure_hook_tickets.py index c5a723d..a435d6d 100755 --- a/pagure/hooks/files/pagure_hook_tickets.py +++ b/pagure/hooks/files/pagure_hook_tickets.py @@ -1,4 +1,4 @@ -#! /usr/bin/env python2 +#!/usr/bin/env python """Pagure specific hook to update tickets stored in the database based on diff --git a/pagure/hooks/files/rtd_hook.py b/pagure/hooks/files/rtd_hook.py index 8b7194a..fd583d6 100755 --- a/pagure/hooks/files/rtd_hook.py +++ b/pagure/hooks/files/rtd_hook.py @@ -1,4 +1,4 @@ -#! /usr/bin/env python2 +#!/usr/bin/env python """Pagure specific hook to trigger a build on a readthedocs.org project. diff --git a/requirements-fedora.txt b/requirements-fedora.txt index 45e170c..b770faf 100644 --- a/requirements-fedora.txt +++ b/requirements-fedora.txt @@ -1,24 +1,23 @@ -python-alembic -python-arrow -python-binaryornot -python-bleach -python-blinker -python-chardet -python-cryptography -python-docutils -python-enum34 -python-fedora-flask -python-flask -python-flask-wtf -py-bcrypt -python-jinja2 -python-markdown -python-munch -python-openid-cla -python-openid-teams -python-psutil -python-pygit2 -python-redis -python-sqlalchemy -python-straight-plugin -python-wtforms +python3-alembic +python3-arrow +python3-binaryornot +python3-bleach +python3-blinker +python3-chardet +python3-cryptography +python3-docutils +python3-fedora-flask +python3-flask +python3-flask-wtf +python3-bcrypt +python3-jinja2 +python3-markdown +python3-munch +python3-openid-cla +python3-openid-teams +python3-psutil +python3-pygit2 +python3-redis +python3-sqlalchemy +python3-straight-plugin +python3-wtforms diff --git a/requirements.txt b/requirements.txt index 0539223..392bd0d 100644 --- a/requirements.txt +++ b/requirements.txt @@ -10,7 +10,7 @@ celery chardet cryptography docutils -enum34 +enum34;python_version<"3.4" flask flask-wtf kitchen @@ -19,7 +19,8 @@ munch Pillow psutil pygit2 >= 0.24.0 -python-openid +python-openid;python_version<="2.7" +python3-openid;python_version>="3.0" python-openid-cla python-openid-teams redis diff --git a/rundocserver.py b/rundocserver.py index a3de285..0e397e5 100755 --- a/rundocserver.py +++ b/rundocserver.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python2 +#!/usr/bin/env python from __future__ import unicode_literals diff --git a/runserver.py b/runserver.py index e0fb9d0..4080d03 100755 --- a/runserver.py +++ b/runserver.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python2 +#!/usr/bin/env python from __future__ import unicode_literals diff --git a/runworker.py b/runworker.py index a1e3214..c5c88fa 100755 --- a/runworker.py +++ b/runworker.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python2 +#!/usr/bin/env python from __future__ import unicode_literals diff --git a/setup.py b/setup.py index 38cdaf1..d64a458 100644 --- a/setup.py +++ b/setup.py @@ -65,8 +65,12 @@ setup( 'License :: OSI Approved :: GNU General Public License v2 or later (GPLv2+)', 'Operating System :: POSIX :: Linux', 'Programming Language :: Python :: 2', - 'Programming Language :: Python :: 2.6', 'Programming Language :: Python :: 2.7', + 'Programming Language :: Python :: 3', + 'Programming Language :: Python :: 3.4', + 'Programming Language :: Python :: 3.5', + 'Programming Language :: Python :: 3.6', + 'Programming Language :: Python :: 3.7', 'Topic :: Internet :: WWW/HTTP :: WSGI :: Application', 'Topic :: Software Development :: Bug Tracking', 'Topic :: Software Development :: Version Control',