Skip to content

Commit

Permalink
Merge pull request #134 from awslabs/develop
Browse files Browse the repository at this point in the history
release 0.5.0: Merge to master
  • Loading branch information
sriram-mv authored Oct 17, 2019
2 parents 0620b0e + 24d16a3 commit fc4f20c
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 10 deletions.
2 changes: 1 addition & 1 deletion aws_lambda_builders/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""
AWS Lambda Builder Library
"""
__version__ = '0.4.0'
__version__ = '0.5.0'
RPC_PROTOCOL_VERSION = "0.3"
2 changes: 1 addition & 1 deletion aws_lambda_builders/workflows/java_maven/workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class JavaMavenWorkflow(BaseWorkflow):
dependency_manager="maven",
application_framework=None)

EXCLUDED_FILES = (".aws-sam")
EXCLUDED_FILES = (".aws-sam", ".git")

def __init__(self,
source_dir,
Expand Down
16 changes: 12 additions & 4 deletions aws_lambda_builders/workflows/python_pip/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,23 @@ def pip_import_string(python_exe):
cmd = [
python_exe,
"-c",
"import pip; assert int(pip.__version__.split('.')[0]) <= 9"
"import pip; print(pip.__version__)"
]
p = os_utils.popen(cmd,stdout=os_utils.pipe, stderr=os_utils.pipe)
p.communicate()
p = os_utils.popen(cmd, stdout=os_utils.pipe, stderr=os_utils.pipe)
stdout, stderr = p.communicate()
pip_version = stdout.decode('utf-8').strip()
pip_major_version = int(pip_version.split('.')[0])
pip_minor_version = int(pip_version.split('.')[1])

# Pip moved its internals to an _internal module in version 10.
# In order to be compatible with version 9 which has it at at the
# top level we need to figure out the correct import path here.
if p.returncode == 0:
if pip_major_version == 9:
return 'from pip import main'
# Pip changed their import structure again in 19.3
# https://github.com/pypa/pip/commit/09fd200
elif pip_major_version >= 19 and pip_minor_version >= 3:
return 'from pip._internal.main import main'
else:
return 'from pip._internal import main'

Expand Down
2 changes: 1 addition & 1 deletion aws_lambda_builders/workflows/python_pip/workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class PythonPipWorkflow(BaseWorkflow):
".python-version",

# mypy, Pyre
".mypy_cache", ".dmypy.json", ".pyre"
".mypy_cache", ".dmypy.json", ".pyre",

# environments
".env", ".venv", "venv", "venv.bak", "env.bak", "ENV",
Expand Down
9 changes: 9 additions & 0 deletions tests/unit/workflows/java_maven/test_workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,12 @@ def test_workflow_sets_up_validators(self):
self.assertEqual(len(validators), 1)

self.assertIsInstance(validators[0], MavenValidator)

def test_workflow_excluded_files(self):
workflow = JavaMavenWorkflow("source", "artifacts", "scratch_dir", "manifest")

self.assertIsInstance(workflow.actions[0], CopySourceAction)

self.assertEqual(".aws-sam", workflow.actions[0].excludes[0])

self.assertEqual(".git", workflow.actions[0].excludes[1])
17 changes: 14 additions & 3 deletions tests/unit/workflows/python_pip/test_packager.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import sys
from collections import namedtuple
from unittest import TestCase

import mock
import pytest
Expand Down Expand Up @@ -70,7 +71,7 @@ def osutils():

class FakePopen(object):
def __init__(self, rc, out, err):
self.returncode = 0
self.returncode = rc
self._out = out
self._err = err

Expand Down Expand Up @@ -303,14 +304,24 @@ def test_inject_unknown_error_if_no_stderr(self, pip_factory):
assert str(einfo.value) == 'Unknown error'


class TestSubprocessPip(object):
class TestSubprocessPip(TestCase):
def test_does_use_custom_pip_import_string(self):
fake_osutils = FakePopenOSUtils([FakePopen(0, '', '')])
expected_import_statement = 'foobarbaz'
pip = SubprocessPip(osutils=fake_osutils,
import_string=expected_import_statement)
import_string=expected_import_statement,
python_exe=sys.executable)
pip.main(['--version'])

pip_execution_string = fake_osutils.popens[0][0][0][2]
import_statement = pip_execution_string.split(';')[1].strip()
assert import_statement == expected_import_statement

def test_check_pip_runner_string_pip(self):
fake_osutils = FakePopenOSUtils([FakePopen(0, '', '')])
pip = SubprocessPip(osutils=fake_osutils,
python_exe=sys.executable)
pip.main(['--version'])

pip_runner_string = fake_osutils.popens[0][0][0][2].split(";")[-1:][0]
self.assertIn("main", pip_runner_string)

0 comments on commit fc4f20c

Please sign in to comment.