diff --git a/samcli/cli/command.py b/samcli/cli/command.py index 84fd9c0aad..aedf5d3f3c 100644 --- a/samcli/cli/command.py +++ b/samcli/cli/command.py @@ -4,6 +4,7 @@ import logging import importlib +import sys import click logger = logging.getLogger(__name__) @@ -20,6 +21,13 @@ "samcli.commands.publish" } +DEPRECATION_NOTICE = ( + "Warning : AWS SAM CLI will no longer support " + "installations on Python 2.7 starting on October 1st, 2019." + " Install AWS SAM CLI via https://docs.aws.amazon.com/serverless-application-model/" + "latest/developerguide/serverless-sam-cli-install.html for continued support with new versions. \n" +) + class BaseCommand(click.MultiCommand): """ @@ -58,6 +66,9 @@ def __init__(self, cmd_packages=None, *args, **kwargs): self._commands = {} self._commands = BaseCommand._set_commands(cmd_packages) + if sys.version_info.major == 2: + click.secho(DEPRECATION_NOTICE, fg="yellow", err=True) + @staticmethod def _set_commands(package_names): """ diff --git a/tests/integration/deprecation/__init__.py b/tests/integration/deprecation/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/integration/deprecation/test_deprecation_warning.py b/tests/integration/deprecation/test_deprecation_warning.py new file mode 100644 index 0000000000..aebf882f76 --- /dev/null +++ b/tests/integration/deprecation/test_deprecation_warning.py @@ -0,0 +1,31 @@ +import os +import subprocess +import sys + +from unittest import TestCase + +from samcli.cli.command import DEPRECATION_NOTICE + + +class TestPy2DeprecationWarning(TestCase): + + def base_command(self): + command = "sam" + if os.getenv("SAM_CLI_DEV"): + command = "samdev" + + return command + + def run_cmd(self): + # Checking with base command to see if warning is present if running in python2 + cmd_list = [self.base_command()] + process = subprocess.Popen(cmd_list, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + return process + + def test_print_deprecation_warning_if_py2(self): + process = self.run_cmd() + (stdoutdata, stderrdata) = process.communicate() + + # Deprecation notice should be part of the command output if running in python 2 + if sys.version_info.major == 2: + self.assertIn(DEPRECATION_NOTICE, stderrdata.decode())