Skip to content

Commit

Permalink
Merge pull request #9113 from rtibbles/deprecate
Browse files Browse the repository at this point in the history
Deprecation warnings for Python 3.4 and 3.5
  • Loading branch information
marcellamaki authored Feb 15, 2022
2 parents f614f2b + bed1d14 commit bce179a
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 8 deletions.
42 changes: 41 additions & 1 deletion kolibri/utils/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,39 @@
import os
import platform
import sys
from warnings import warn

try:
# Do this to allow this to be accessed
# during build, when dependencies are not
# installed.
# TODO: Move version tools to build tools, so we don't have to do this
from colorlog import ColoredFormatter
from colorlog import getLogger
from colorlog import StreamHandler
except ImportError:
StreamHandler = None
getLogger = None
ColoredFormatter = None

from .logger import LOG_COLORS


logging.basicConfig(format="%(levelname)s: %(message)s", level=logging.INFO)
logging.StreamHandler(sys.stdout)

if StreamHandler and getLogger and ColoredFormatter:
handler = StreamHandler()
handler.setFormatter(
ColoredFormatter(
fmt="%(log_color)s%(levelname)-8s %(message)s", log_colors=LOG_COLORS
)
)
logger = getLogger("env")
logger.addHandler(handler)
else:
logger = logging.getLogger("env")


def settings_module():
from .build_config.default_settings import settings_path
Expand Down Expand Up @@ -68,7 +97,16 @@ def prepend_cext_path(dist_path):
# add it + the matching noarch (OpenSSL) modules to sys.path
sys.path = [str(dirname), str(noarch_dir)] + sys.path
else:
logging.info("No C extensions are available for this platform")
logger.info("No C extensions are available for this platform")


def check_python_versions():
if sys.version_info.major == 3 and (
sys.version_info.minor == 4 or sys.version_info.minor == 5
):
warning_text = "Python 3.4 and 3.5 support will be dropped in Kolibri 0.16, please upgrade your Python version"
logger.warn(warning_text)
warn(warning_text, DeprecationWarning)


def set_env():
Expand All @@ -82,6 +120,8 @@ def set_env():
"""
from kolibri import dist as kolibri_dist # noqa

check_python_versions()

sys.path = [os.path.realpath(os.path.dirname(kolibri_dist.__file__))] + sys.path

# Add path for c extensions to sys.path
Expand Down
16 changes: 9 additions & 7 deletions kolibri/utils/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@

NO_FILE_BASED_LOGGING = os.environ.get("KOLIBRI_NO_FILE_BASED_LOGGING", False)

LOG_COLORS = {
"DEBUG": "blue",
"INFO": "white",
"WARNING": "yellow",
"ERROR": "red",
"CRITICAL": "bold_red",
}


class KolibriTimedRotatingFileHandler(TimedRotatingFileHandler):
"""
Expand Down Expand Up @@ -143,13 +151,7 @@ def get_default_logging_config(LOG_ROOT, debug=False, debug_database=False):
"color": {
"()": "colorlog.ColoredFormatter",
"format": "%(log_color)s%(levelname)-8s %(message)s",
"log_colors": {
"DEBUG": "blue",
"INFO": "white",
"WARNING": "yellow",
"ERROR": "red",
"CRITICAL": "bold_red",
},
"log_colors": LOG_COLORS,
},
},
"handlers": {
Expand Down

0 comments on commit bce179a

Please sign in to comment.