Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions samcli/cli/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import logging
import importlib
import sys
import click

logger = logging.getLogger(__name__)
Expand All @@ -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):
"""
Expand Down Expand Up @@ -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):
"""
Expand Down
Empty file.
31 changes: 31 additions & 0 deletions tests/integration/deprecation/test_deprecation_warning.py
Original file line number Diff line number Diff line change
@@ -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())