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
6 changes: 4 additions & 2 deletions aws_lambda_builders/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ class UnsupportedManifestError(LambdaBuilderError):


class MisMatchRuntimeError(LambdaBuilderError):
MESSAGE = "A runtime version mismatch was found for the given language " \
"'{language}', required runtime '{required_runtime}'"
MESSAGE = "{language} executable found in your path does not " \
"match runtime. " \
"\n Expected version: {required_runtime}, Found version: {found_runtime}. " \
"\n Possibly related: https://github.com/awslabs/aws-lambda-builders/issues/30"


class WorkflowNotFoundError(LambdaBuilderError):
Expand Down
6 changes: 4 additions & 2 deletions aws_lambda_builders/validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ def validate_python_cmd(required_language, required_runtime_version):
"python",
"-c",
"import sys; "
"sys.stdout.write('python' + str(sys.version_info.major) + '.' + str(sys.version_info.minor)); "
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

haha neat ;)

"assert sys.version_info.major == {major} "
"and sys.version_info.minor == {minor}".format(
major=major,
Expand Down Expand Up @@ -63,10 +64,11 @@ def validate_runtime(cls, required_language, required_runtime):
p = subprocess.Popen(cmd,
cwd=os.getcwd(),
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
p.communicate()
found_runtime, _ = p.communicate()
if p.returncode != 0:
raise MisMatchRuntimeError(language=required_language,
required_runtime=required_runtime)
required_runtime=required_runtime,
found_runtime=str(found_runtime.decode('utf-8')))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the decode valid in python2.7?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

checked it with an integ test, and ran it under python2.

under python2, even if its already string and we decode. we get to unicode.

Python 2.7.10 (default, Feb  7 2017, 00:08:15)
Type "copyright", "credits" or "license" for more information.

IPython 5.8.0 -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.

In [1]: mystring="python"

In [2]: type(mystring)
Out[2]: str

In [3]: mystring.decode('utf-8')
Out[3]: u'python'

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

perfect

else:
LOG.warning("'%s' runtime has not "
"been validated!", required_language)
17 changes: 16 additions & 1 deletion tests/integration/workflows/python_pip/test_python_pip.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from unittest import TestCase

from aws_lambda_builders.builder import LambdaBuilder
from aws_lambda_builders.exceptions import WorkflowFailedError
from aws_lambda_builders.exceptions import WorkflowFailedError, MisMatchRuntimeError


class TestPythonPipWorkflow(TestCase):
Expand All @@ -33,6 +33,12 @@ def setUp(self):
language=self.builder.capability.language,
major=sys.version_info.major,
minor=sys.version_info.minor)
self.runtime_mismatch = {
'python3.6': 'python2.7',
'python3.7': 'python2.7',
'python2.7': 'python3.6'

}

def tearDown(self):
shutil.rmtree(self.artifacts_dir)
Expand All @@ -46,6 +52,15 @@ def test_must_build_python_project(self):
output_files = set(os.listdir(self.artifacts_dir))
self.assertEquals(expected_files, output_files)

def test_mismatch_runtime_python_project(self):
with self.assertRaises(MisMatchRuntimeError) as mismatch_error:
self.builder.build(self.source_dir, self.artifacts_dir, self.scratch_dir, self.manifest_path_valid,
runtime=self.runtime_mismatch[self.runtime])
self.assertEquals(mismatch_error.msg,
MisMatchRuntimeError(language="python",
required_runtime=self.runtime_mismatch[self.runtime],
found_runtime=self.runtime).MESSAGE)

def test_runtime_validate_python_project_fail_open_unsupported_runtime(self):
with self.assertRaises(WorkflowFailedError):
self.builder.build(self.source_dir, self.artifacts_dir, self.scratch_dir, self.manifest_path_valid,
Expand Down
5 changes: 3 additions & 2 deletions tests/unit/test_runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def __init__(self, returncode):
self.returncode = returncode

def communicate(self):
pass
return b'python3,6', None


class TestRuntime(TestCase):
Expand Down Expand Up @@ -44,6 +44,7 @@ def test_runtime_validate_mismatch_version_runtime(self):

def test_python_command(self):
cmd = validate_python_cmd("python", "python2.7")
version_strings = ["sys.version_info.major == 2", "sys.version_info.minor == 7"]
version_strings = ["sys.stdout.write", "sys.version_info.major == 2",
"sys.version_info.minor == 7"]
for version_string in version_strings:
self.assertTrue(any([part for part in cmd if version_string in part]))