Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: update preview runtime warning message and add missing py310 tests #4908

Merged
merged 5 commits into from Mar 23, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 7 additions & 1 deletion appveyor-ubuntu.yml
Expand Up @@ -35,6 +35,7 @@ environment:
NOSE_PARAMETERIZED_NO_WARN: 1
INSTALL_PY_38_PIP: 1
INSTALL_PY_39_PIP: 1
INSTALL_PY_310_PIP: 1
APPVEYOR_CONSOLE_DISABLE_PTY: true

- PYTHON_HOME: "C:\\Python38-x64"
Expand All @@ -44,6 +45,7 @@ environment:
NOSE_PARAMETERIZED_NO_WARN: 1
INSTALL_PY_37_PIP: 1
INSTALL_PY_39_PIP: 1
INSTALL_PY_310_PIP: 1
APPVEYOR_CONSOLE_DISABLE_PTY: true

- PYTHON_HOME: "C:\\Python39-x64"
Expand All @@ -53,6 +55,7 @@ environment:
NOSE_PARAMETERIZED_NO_WARN: 1
INSTALL_PY_37_PIP: 1
INSTALL_PY_38_PIP: 1
INSTALL_PY_310_PIP: 1
APPVEYOR_CONSOLE_DISABLE_PTY: true

install:
Expand Down Expand Up @@ -87,17 +90,20 @@ install:
- sh: "sudo apt-get -y install python3.7"
- sh: "sudo apt-get -y install python3.8"
- sh: "sudo apt-get -y install python3.9 python3.9-dev python3.9-venv"
- sh: "sudo apt-get -y install python3.10 python3.10-dev python3.10-venv"

- sh: "which python3.8"
- sh: "which python3.7"
- sh: "which python3.9"
- sh: "which python3.10"

- sh: "PATH=$PATH:/usr/bin/python3.9:/usr/bin/python3.8:/usr/bin/python3.7"
- sh: "PATH=$PATH:/usr/bin/python3.9:/usr/bin/python3.8:/usr/bin/python3.7:/usr/bin/python3.10"
- sh: "curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py"
- sh: "curl https://bootstrap.pypa.io/pip/3.6/get-pip.py -o get-pip-36.py"

- sh: "sudo apt-get -y install python3-distutils"
- sh: "sudo apt-get -y install python3.9-distutils"
- ps: "If ($env:INSTALL_PY_310_PIP) {python3.10 get-pip.py --user}"
- ps: "If ($env:INSTALL_PY_39_PIP) {python3.9 get-pip.py --user}"
- ps: "If ($env:INSTALL_PY_38_PIP) {python3.8 get-pip.py --user}"
- ps: "If ($env:INSTALL_PY_37_PIP) {python3.7 get-pip.py --user}"
Expand Down
3 changes: 2 additions & 1 deletion appveyor-windows.yml
Expand Up @@ -69,7 +69,7 @@ install:

# Make sure the temp directory exists for Python to use.
- ps: "mkdir -Force C:\\tmp"
- 'set PATH=%PYTHON_HOME%;C:\Ruby27-x64\bin;%PATH%;C:\Python37-x64;C:\Python39-x64'
- 'set PATH=%PYTHON_HOME%;C:\Ruby27-x64\bin;%PATH%;C:\Python37-x64;C:\Python39-x64;C:\Python310-x64'
- "echo %PYTHON_HOME%"
- "echo %PATH%"
- "python --version"
Expand All @@ -84,6 +84,7 @@ install:
# Install pip for the python versions which is used by the tests
- "C:\\Python37-x64\\python.exe -m pip install --upgrade pip"
- "C:\\Python39-x64\\python.exe -m pip install --upgrade pip"
- "C:\\Python310-x64\\python.exe -m pip install --upgrade pip"

# Install AWS CLI Globally via pip3
- "pip install awscli"
Expand Down
24 changes: 13 additions & 11 deletions samcli/commands/package/package_context.py
Expand Up @@ -31,10 +31,10 @@
from samcli.lib.package.s3_uploader import S3Uploader
from samcli.lib.package.uploaders import Uploaders
from samcli.lib.providers.provider import ResourceIdentifier, Stack, get_resource_full_path_by_id
from samcli.lib.providers.sam_function_provider import SamFunctionProvider
from samcli.lib.providers.sam_stack_provider import SamLocalStackProvider
from samcli.lib.utils.boto_utils import get_boto_config_with_user_agent
from samcli.lib.utils.preview_runtimes import PREVIEW_RUNTIMES
from samcli.lib.utils.resources import AWS_LAMBDA_FUNCTION, AWS_SERVERLESS_FUNCTION
from samcli.yamlhelper import yaml_dump

LOG = logging.getLogger(__name__)
Expand Down Expand Up @@ -170,16 +170,18 @@ def _export(self, template_path, use_json):

@staticmethod
def _warn_preview_runtime(stacks: List[Stack]) -> None:
function_provider = SamFunctionProvider(stacks)
for function in function_provider.get_all():
if function.runtime in PREVIEW_RUNTIMES:
click.secho(
"Warning: This stack contains one or more Lambda functions using a runtime which is not "
"yet generally available. This runtime should not be used for production applications. "
"For more information on supported runtimes, see "
"https://docs.aws.amazon.com/lambda/latest/dg/lambda-runtimes.html.",
fg="yellow",
)
for stack in stacks:
for _, resource_dict in stack.resources.items():
if resource_dict.get("Type") not in [AWS_SERVERLESS_FUNCTION, AWS_LAMBDA_FUNCTION]:
continue
if resource_dict.get("Properties", {}).get("Runtime", "") in PREVIEW_RUNTIMES:
click.secho(
"Warning: This stack contains one or more Lambda functions using a runtime which is not "
"yet generally available. This runtime should not be used for production applications. "
"For more information on supported runtimes, see "
"https://docs.aws.amazon.com/lambda/latest/dg/lambda-runtimes.html.",
fg="yellow",
)
return

@staticmethod
Expand Down
1 change: 1 addition & 0 deletions tests/integration/buildcmd/test_build_cmd.py
Expand Up @@ -398,6 +398,7 @@ def _validate_skipped_built_function(
("template.yaml", "Function", True, "python3.7", "Python", False, False, "CodeUri"),
("template.yaml", "Function", True, "python3.8", "Python", False, False, "CodeUri"),
("template.yaml", "Function", True, "python3.9", "Python", False, False, "CodeUri"),
("template.yaml", "Function", True, "python3.10", "Python", False, False, "CodeUri"),
("template.yaml", "Function", True, "python3.7", "PythonPEP600", False, False, "CodeUri"),
("template.yaml", "Function", True, "python3.8", "PythonPEP600", False, False, "CodeUri"),
("template.yaml", "Function", True, "python3.7", "Python", "use_container", False, "CodeUri"),
Expand Down
@@ -1,7 +1,8 @@
# These are some hard packages to build. Using them here helps us verify that building works on various platforms

# NOTE: Fixing to <1.20.3 as numpy1.20.3 started to use a new wheel naming convention (PEP 600)
numpy<1.20.3
numpy<1.20.3; python_version <= '3.9'
numpy==1.23.5; python_version >= '3.10'
# `cryptography` has a dependency on `pycparser` which, for some reason doesn't build inside a Docker container.
# Turning this off until we resolve this issue: https://github.com/awslabs/aws-lambda-builders/issues/29
# cryptography~=2.4
22 changes: 16 additions & 6 deletions tests/unit/commands/package/test_package_context.py
Expand Up @@ -10,6 +10,7 @@
from samcli.lib.package.artifact_exporter import Template
from samcli.lib.providers.sam_stack_provider import SamLocalStackProvider
from samcli.lib.samlib.resource_metadata_normalizer import ResourceMetadataNormalizer
from samcli.lib.utils.resources import AWS_LAMBDA_FUNCTION, AWS_SERVERLESS_FUNCTION


class TestPackageCommand(TestCase):
Expand Down Expand Up @@ -156,22 +157,31 @@ def test_boto_clients_created_with_config(
(
"preview_runtime",
True,
AWS_SERVERLESS_FUNCTION,
),
(
"ga_runtime",
False,
AWS_SERVERLESS_FUNCTION,
),
(
"preview_runtime",
True,
AWS_LAMBDA_FUNCTION,
),
(
"ga_runtime",
False,
AWS_LAMBDA_FUNCTION,
),
]
)
@patch("samcli.commands.package.package_context.PREVIEW_RUNTIMES", {"preview_runtime"})
@patch("samcli.commands.package.package_context.SamFunctionProvider")
@patch("samcli.commands.package.package_context.click")
def test_warn_preview_runtime(self, runtime, should_warn, patched_click, patched_function_provider):
function_provider = Mock()
patched_function_provider.return_value = function_provider
function_provider.get_all.return_value = [Mock(runtime=runtime)]
def test_warn_preview_runtime(self, runtime, should_warn, function_type, patched_click):
resources = {"MyFunction": {"Type": function_type, "Properties": {"Runtime": runtime}}}

self.package_command_context._warn_preview_runtime([Mock()])
self.package_command_context._warn_preview_runtime([Mock(resources=resources)])

if should_warn:
patched_click.secho.assert_called_once()
Expand Down