From f813a4526f62e659dfcb2c1e581d03e595f664ea Mon Sep 17 00:00:00 2001
From: Christian Heimes <cheimes@redhat.com>
Date: Wed, 30 May 2018 09:26:16 +0200
Subject: [PATCH] Start to deprecate Python 2 support

Python 2 will reach EOL in 18 months. Start to issue deprecation
warnings on Python 2.

No longer claim support for Python 3.5. Python 3.5 is untested.

Fixes: https://pagure.io/freeipa/issue/7568
Signed-off-by: Christian Heimes <cheimes@redhat.com>
---
 ipalib/__init__.py              | 15 ++++++++++++++-
 ipaplatform/base/constants.py   |  2 ++
 ipaplatform/debian/constants.py |  2 ++
 ipasetup.py.in                  |  1 -
 4 files changed, 18 insertions(+), 2 deletions(-)

diff --git a/ipalib/__init__.py b/ipalib/__init__.py
index f1ffe51f3b..e997707326 100644
--- a/ipalib/__init__.py
+++ b/ipalib/__init__.py
@@ -881,13 +881,15 @@ class my_command(Command):
     http://freeipa.org/page/Contribute
 
 '''
+import sys
+import warnings
+
 from ipapython.version import VERSION as __version__
 
 def _enable_warnings(error=False):
     """Enable additional warnings during development
     """
     import ctypes
-    import warnings
 
     # get reference to Py_BytesWarningFlag from Python CAPI
     byteswarnings = ctypes.c_int.in_dll(  # pylint: disable=no-member
@@ -915,6 +917,17 @@ def _enable_warnings(error=False):
 if 'git' in __version__:
     _enable_warnings(False)
 
+# noqa: E402
+from ipaplatform.constants import constants
+
+if sys.version_info < constants.PYTHON_DEPRECATED_BEFORE:
+    warnings.warn(
+        "Support for Python version {d[0]}.{d[1]}.{d[2]} is deprecated. "
+        "Python version 3.6 or newer will be required in the next major "
+        "release.".format(d=sys.version_info),
+        category=DeprecationWarning
+    )
+
 # noqa: E402
 from ipalib import plugable
 from ipalib.backend import Backend
diff --git a/ipaplatform/base/constants.py b/ipaplatform/base/constants.py
index f67acd7e30..118b267b85 100644
--- a/ipaplatform/base/constants.py
+++ b/ipaplatform/base/constants.py
@@ -45,6 +45,8 @@ class BaseConstantsNamespace(object):
     # high ciphers without RC4, MD5, TripleDES, pre-shared key, secure
     # remote password, and DSA cert authentication.
     TLS_HIGH_CIPHERS = "HIGH:!aNULL:!eNULL:!MD5:!RC4:!3DES:!PSK:!SRP:!aDSS"
+    # Minimal Python version for deprecation warning
+    PYTHON_DEPRECATED_BEFORE = (3, 6, 0)
 
 
 constants = BaseConstantsNamespace()
diff --git a/ipaplatform/debian/constants.py b/ipaplatform/debian/constants.py
index 73e0418b55..a834fdd536 100644
--- a/ipaplatform/debian/constants.py
+++ b/ipaplatform/debian/constants.py
@@ -26,5 +26,7 @@ class DebianConstantsNamespace(BaseConstantsNamespace):
     ODS_USER = "opendnssec"
     ODS_GROUP = "opendnssec"
     SECURE_NFS_VAR = "NEED_GSSD"
+    # Debian/Ubuntu still use Python 2
+    PYTHON_DEPRECATED_BEFORE = (2, 7, 5)
 
 constants = DebianConstantsNamespace()
diff --git a/ipasetup.py.in b/ipasetup.py.in
index 8ec28c1583..0a17561783 100644
--- a/ipasetup.py.in
+++ b/ipasetup.py.in
@@ -107,7 +107,6 @@ common_args = dict(
         "Programming Language :: Python :: 2",
         "Programming Language :: Python :: 2.7",
         "Programming Language :: Python :: 3",
-        "Programming Language :: Python :: 3.5",
         "Programming Language :: Python :: 3.6",
         "Programming Language :: Python :: Implementation :: CPython",
         "Operating System :: POSIX",
