Browse Source

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 <ngompa13@gmail.com>
Neal Gompa 5 years ago
parent
commit
55fa35a37f

+ 5 - 5
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::

+ 1 - 1
createdb.py

@@ -1,4 +1,4 @@
-#!/usr/bin/env python2
+#!/usr/bin/env python
 
 from __future__ import print_function, unicode_literals
 

+ 2 - 2
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/
 
   #<Location />
     #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)

+ 45 - 9
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

+ 1 - 1
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

+ 1 - 1
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.

+ 1 - 1
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

+ 1 - 1
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.

+ 1 - 1
pagure/hooks/files/git_multimail.py

@@ -1,4 +1,4 @@
-#! /usr/bin/env python2
+#!/usr/bin/env python
 
 # flake8: noqa
 

+ 1 - 1
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'

+ 1 - 1
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.

+ 1 - 1
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

+ 1 - 1
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

+ 1 - 1
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

+ 1 - 1
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.

+ 23 - 24
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

+ 3 - 2
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

+ 1 - 1
rundocserver.py

@@ -1,4 +1,4 @@
-#!/usr/bin/env python2
+#!/usr/bin/env python
 
 from __future__ import unicode_literals
 

+ 1 - 1
runserver.py

@@ -1,4 +1,4 @@
-#!/usr/bin/env python2
+#!/usr/bin/env python
 
 from __future__ import unicode_literals
 

+ 1 - 1
runworker.py

@@ -1,4 +1,4 @@
-#!/usr/bin/env python2
+#!/usr/bin/env python
 
 from __future__ import unicode_literals
 

+ 5 - 1
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',