From 4ca6e3f95f090b38ea4a1b74a437286271e287c5 Mon Sep 17 00:00:00 2001 From: Micah Jerome Ellison Date: Sun, 12 Jul 2020 16:24:46 -0700 Subject: [PATCH] Display warning if Python version is less than 3.7 (#994) * Add Python version check and faulty test to confirm it's working (should fail on 3.6 build only) * Apply formatting * Fix behave Python version test * Make error message more descriptive and friendly --- features/core.feature | 4 ++++ features/steps/core.py | 14 ++++++++++++++ jrnl/cli.py | 15 ++++++++++++++- 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/features/core.feature b/features/core.feature index 5bec4e95..53d37f8b 100644 --- a/features/core.feature +++ b/features/core.feature @@ -135,3 +135,7 @@ Feature: Basic reading and writing to a journal When we run "jrnl --diagnostic" Then the output should contain "jrnl" And the output should contain "Python" + + Scenario: Version warning appears for versions below 3.7 + When we run "jrnl --diagnostic" + Then the Python version warning should appear if our version is below 3.7 diff --git a/features/steps/core.py b/features/steps/core.py index 13b11bd2..5cf5b79b 100644 --- a/features/steps/core.py +++ b/features/steps/core.py @@ -372,6 +372,20 @@ def list_journal_directory(context, journal="default"): print(os.path.join(root, file)) +@then("the Python version warning should appear if our version is below {version}") +def check_python_warning_if_version_low_enough(context, version): + import packaging.version + import platform + + if packaging.version.parse(platform.python_version()) < packaging.version.parse( + version + ): + out = context.stderr_capture.getvalue() + assert "WARNING: Python versions" in out + else: + assert True + + @then("fail") def debug_fail(context): assert False diff --git a/jrnl/cli.py b/jrnl/cli.py index 8e583391..72ba5ea9 100644 --- a/jrnl/cli.py +++ b/jrnl/cli.py @@ -21,6 +21,7 @@ import argparse import logging +import packaging.version import platform import re import sys @@ -29,7 +30,7 @@ import jrnl from . import install, plugins, util from .Journal import PlainJournal, open_journal -from .util import ERROR_COLOR, RESET_COLOR, UserAbort +from .util import WARNING_COLOR, ERROR_COLOR, RESET_COLOR, UserAbort log = logging.getLogger(__name__) logging.getLogger("keyring.backend").setLevel(logging.ERROR) @@ -313,6 +314,18 @@ def configure_logger(debug=False): def run(manual_args=None): + if packaging.version.parse(platform.python_version()) < packaging.version.parse( + "3.7" + ): + print( + f"""{WARNING_COLOR} +WARNING: Python versions below 3.7 will no longer be supported as of jrnl v2.5 +(the next release). You are currently on Python {platform.python_version()}. Please update to +Python 3.7 (or higher) soon. +{RESET_COLOR}""", + file=sys.stderr, + ) + if manual_args is None: manual_args = sys.argv[1:]