Skip to content

Commit 7cfa9da

Browse files
authored
Revert "feat: Python 37 support (#32)"
This reverts commit 624b6c3.
1 parent f0aa501 commit 7cfa9da

File tree

10 files changed

+51
-78
lines changed

10 files changed

+51
-78
lines changed

.appveyor.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ environment:
77

88
- PYTHON: "C:\\Python27-x64"
99
- PYTHON: "C:\\Python36-x64"
10-
- PYTHON: "C:\\Python37-x64"
10+
# - PYTHON: "C:\\Python37-x64"
1111

1212

1313
build: off

.travis.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ python:
55
- "2.7"
66
- "3.6"
77
# Enable 3.7 without globally enabling sudo and dist: xenial for other build jobs
8-
matrix:
9-
include:
10-
- python: 3.7
11-
dist: xenial
12-
sudo: true
8+
#matrix:
9+
# include:
10+
# - python: 3.7
11+
# dist: xenial
12+
# sudo: true
1313
install:
1414
# Install the code requirements
1515
- make init

aws_lambda_builders/validate.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@ def validate_python_cmd(required_language, required_runtime_version):
3232
class RuntimeValidator(object):
3333
SUPPORTED_RUNTIMES = [
3434
"python2.7",
35-
"python3.6",
36-
"python3.7",
35+
"python3.6"
3736
]
3837

3938
@classmethod

aws_lambda_builders/workflows/python_pip/actions.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,15 @@ def __init__(self, artifacts_dir, manifest_path, scratch_dir, runtime):
1717
self.manifest_path = manifest_path
1818
self.scratch_dir = scratch_dir
1919
self.runtime = runtime
20-
self.package_builder = PythonPipDependencyBuilder(runtime=runtime)
20+
self.package_builder = PythonPipDependencyBuilder()
2121

2222
def execute(self):
2323
try:
2424
self.package_builder.build_dependencies(
2525
self.artifacts_dir,
2626
self.manifest_path,
27-
self.scratch_dir
27+
self.scratch_dir,
28+
self.runtime,
2829
)
2930
except PackagerError as ex:
3031
raise ActionFailedError(str(ex))

aws_lambda_builders/workflows/python_pip/compat.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import os
2+
import six
23

34

45
def pip_import_string():
@@ -100,3 +101,9 @@ def raise_compile_error(*args, **kwargs):
100101
pip_no_compile_c_env_vars = {
101102
'CC': '/var/false'
102103
}
104+
105+
106+
if six.PY3:
107+
lambda_abi = 'cp36m'
108+
else:
109+
lambda_abi = 'cp27mu'

aws_lambda_builders/workflows/python_pip/packager.py

Lines changed: 13 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from email.parser import FeedParser
1010

1111

12+
from .compat import lambda_abi
1213
from .compat import pip_import_string
1314
from .compat import pip_no_compile_c_env_vars
1415
from .compat import pip_no_compile_c_shim
@@ -58,36 +59,10 @@ class PackageDownloadError(PackagerError):
5859
pass
5960

6061

61-
class UnsupportedPythonVersion(PackagerError):
62-
"""Generic networking error during a package download."""
63-
def __init__(self, version):
64-
super(UnsupportedPythonVersion, self).__init__(
65-
"'%s' version of python is not supported" % version
66-
)
67-
68-
69-
def get_lambda_abi(runtime):
70-
supported = {
71-
"python2.7": "cp27mu",
72-
"python3.6": "cp36m",
73-
"python3.7": "cp37m"
74-
}
75-
76-
if runtime not in supported:
77-
raise UnsupportedPythonVersion(runtime)
78-
79-
return supported[runtime]
80-
81-
8262
class PythonPipDependencyBuilder(object):
83-
def __init__(self, runtime, osutils=None, dependency_builder=None):
63+
def __init__(self, osutils=None, dependency_builder=None):
8464
"""Initialize a PythonPipDependencyBuilder.
8565
86-
:type runtime: str
87-
:param runtime: Python version to build dependencies for. This can
88-
either be python2.7, python3.6 or python3.7. These are currently the
89-
only supported values.
90-
9166
:type osutils: :class:`lambda_builders.utils.OSUtils`
9267
:param osutils: A class used for all interactions with the
9368
outside OS.
@@ -101,11 +76,11 @@ def __init__(self, runtime, osutils=None, dependency_builder=None):
10176
self.osutils = OSUtils()
10277

10378
if dependency_builder is None:
104-
dependency_builder = DependencyBuilder(self.osutils, runtime)
79+
dependency_builder = DependencyBuilder(self.osutils)
10580
self._dependency_builder = dependency_builder
10681

10782
def build_dependencies(self, artifacts_dir_path, scratch_dir_path,
108-
requirements_path, ui=None, config=None):
83+
requirements_path, runtime, ui=None, config=None):
10984
"""Builds a python project's dependencies into an artifact directory.
11085
11186
:type artifacts_dir_path: str
@@ -118,6 +93,11 @@ def build_dependencies(self, artifacts_dir_path, scratch_dir_path,
11893
:param requirements_path: Path to a requirements.txt file to inspect
11994
for a list of dependencies.
12095
96+
:type runtime: str
97+
:param runtime: Python version to build dependencies for. This can
98+
either be python2.7 or python3.6. These are currently the only
99+
supported values.
100+
121101
:type ui: :class:`lambda_builders.utils.UI` or None
122102
:param ui: A class that traps all progress information such as status
123103
and errors. If injected by the caller, it can be used to monitor
@@ -161,16 +141,13 @@ class DependencyBuilder(object):
161141
'sqlalchemy'
162142
}
163143

164-
def __init__(self, osutils, runtime, pip_runner=None):
144+
def __init__(self, osutils, pip_runner=None):
165145
"""Initialize a DependencyBuilder.
166146
167147
:type osutils: :class:`lambda_builders.utils.OSUtils`
168148
:param osutils: A class used for all interactions with the
169149
outside OS.
170150
171-
:type runtime: str
172-
:param runtime: AWS Lambda Python runtime to build for
173-
174151
:type pip_runner: :class:`PipRunner`
175152
:param pip_runner: This class is responsible for executing our pip
176153
on our behalf.
@@ -179,7 +156,6 @@ def __init__(self, osutils, runtime, pip_runner=None):
179156
if pip_runner is None:
180157
pip_runner = PipRunner(SubprocessPip(osutils))
181158
self._pip = pip_runner
182-
self.runtime = runtime
183159

184160
def build_site_packages(self, requirements_filepath,
185161
target_directory,
@@ -336,9 +312,8 @@ def _download_all_dependencies(self, requirements_filename, directory):
336312
def _download_binary_wheels(self, packages, directory):
337313
# Try to get binary wheels for each package that isn't compatible.
338314
LOG.debug("Downloading missing wheels: %s", packages)
339-
lambda_abi = get_lambda_abi(self.runtime)
340315
self._pip.download_manylinux_wheels(
341-
[pkg.identifier for pkg in packages], directory, lambda_abi)
316+
[pkg.identifier for pkg in packages], directory)
342317

343318
def _build_sdists(self, sdists, directory, compile_c=True):
344319
LOG.debug("Build missing wheels from sdists "
@@ -366,9 +341,6 @@ def _is_compatible_wheel_filename(self, filename):
366341
# Verify platform is compatible
367342
if platform not in self._MANYLINUX_COMPATIBLE_PLATFORM:
368343
return False
369-
370-
lambda_runtime_abi = get_lambda_abi(self.runtime)
371-
372344
# Verify that the ABI is compatible with lambda. Either none or the
373345
# correct type for the python version cp27mu for py27 and cp36m for
374346
# py36.
@@ -379,7 +351,7 @@ def _is_compatible_wheel_filename(self, filename):
379351
# Deploying python 3 function which means we need cp36m abi
380352
# We can also accept abi3 which is the CPython 3 Stable ABI and
381353
# will work on any version of python 3.
382-
return abi == lambda_runtime_abi or abi == 'abi3'
354+
return abi == 'cp36m' or abi == 'abi3'
383355
elif prefix_version == 'cp2':
384356
# Deploying to python 2 function which means we need cp27mu abi
385357
return abi == 'cp27mu'
@@ -643,7 +615,7 @@ def download_all_dependencies(self, requirements_filename, directory):
643615
# complain at deployment time.
644616
self.build_wheel(wheel_package_path, directory)
645617

646-
def download_manylinux_wheels(self, packages, directory, lambda_abi):
618+
def download_manylinux_wheels(self, packages, directory):
647619
"""Download wheel files for manylinux for all the given packages."""
648620
# If any one of these dependencies fails pip will bail out. Since we
649621
# are only interested in all the ones we can download, we need to feed

tests/functional/workflows/python_pip/test_packager.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import sys
21
import os
32
import zipfile
43
import tarfile
@@ -17,7 +16,7 @@
1716
from aws_lambda_builders.workflows.python_pip.packager import SDistMetadataFetcher
1817
from aws_lambda_builders.workflows.python_pip.packager import \
1918
InvalidSourceDistributionNameError
20-
from aws_lambda_builders.workflows.python_pip.packager import get_lambda_abi
19+
from aws_lambda_builders.workflows.python_pip.compat import lambda_abi
2120
from aws_lambda_builders.workflows.python_pip.compat import pip_no_compile_c_env_vars
2221
from aws_lambda_builders.workflows.python_pip.compat import pip_no_compile_c_shim
2322
from aws_lambda_builders.workflows.python_pip.utils import OSUtils
@@ -215,7 +214,7 @@ def _write_requirements_txt(self, packages, directory):
215214
def _make_appdir_and_dependency_builder(self, reqs, tmpdir, runner):
216215
appdir = str(_create_app_structure(tmpdir))
217216
self._write_requirements_txt(reqs, appdir)
218-
builder = DependencyBuilder(OSUtils(), "python3.6", runner)
217+
builder = DependencyBuilder(OSUtils(), runner)
219218
return appdir, builder
220219

221220
def test_can_build_local_dir_as_whl(self, tmpdir, pip_runner, osutils):
@@ -645,7 +644,7 @@ def test_can_replace_incompat_whl(self, tmpdir, osutils, pip_runner):
645644
expected_args=[
646645
'--only-binary=:all:', '--no-deps', '--platform',
647646
'manylinux1_x86_64', '--implementation', 'cp',
648-
'--abi', get_lambda_abi(builder.runtime), '--dest', mock.ANY,
647+
'--abi', lambda_abi, '--dest', mock.ANY,
649648
'bar==1.2'
650649
],
651650
packages=[
@@ -678,7 +677,7 @@ def test_whitelist_sqlalchemy(self, tmpdir, osutils, pip_runner):
678677
expected_args=[
679678
'--only-binary=:all:', '--no-deps', '--platform',
680679
'manylinux1_x86_64', '--implementation', 'cp',
681-
'--abi', get_lambda_abi(builder.runtime), '--dest', mock.ANY,
680+
'--abi', lambda_abi, '--dest', mock.ANY,
682681
'sqlalchemy==1.1.18'
683682
],
684683
packages=[
@@ -840,7 +839,7 @@ def test_build_into_existing_dir_with_preinstalled_packages(
840839
expected_args=[
841840
'--only-binary=:all:', '--no-deps', '--platform',
842841
'manylinux1_x86_64', '--implementation', 'cp',
843-
'--abi', get_lambda_abi(builder.runtime), '--dest', mock.ANY,
842+
'--abi', lambda_abi, '--dest', mock.ANY,
844843
'foo==1.2'
845844
],
846845
packages=[

tests/integration/workflows/python_pip/test_python_pip.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,11 @@ def test_must_build_python_project(self):
4747
self.assertEquals(expected_files, output_files)
4848

4949
def test_runtime_validate_python_project_fail_open_unsupported_runtime(self):
50-
with self.assertRaises(WorkflowFailedError):
51-
self.builder.build(self.source_dir, self.artifacts_dir, self.scratch_dir, self.manifest_path_valid,
52-
runtime="python2.8")
50+
self.builder.build(self.source_dir, self.artifacts_dir, self.scratch_dir, self.manifest_path_valid,
51+
runtime="python2.8")
52+
expected_files = self.test_data_files.union({"numpy", "numpy-1.15.4.data", "numpy-1.15.4.dist-info"})
53+
output_files = set(os.listdir(self.artifacts_dir))
54+
self.assertEquals(expected_files, output_files)
5355

5456
def test_must_fail_to_resolve_dependencies(self):
5557

tests/unit/workflows/python_pip/test_actions.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ def test_action_must_call_builder(self, PythonPipDependencyBuilderMock):
2020

2121
builder_instance.build_dependencies.assert_called_with("artifacts",
2222
"scratch_dir",
23-
"manifest")
23+
"manifest",
24+
"runtime")
2425

2526
@patch("aws_lambda_builders.workflows.python_pip.actions.PythonPipDependencyBuilder")
2627
def test_must_raise_exception_on_failure(self, PythonPipDependencyBuilderMock):

tests/unit/workflows/python_pip/test_packager.py

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import sys
12
from collections import namedtuple
23

34
import mock
@@ -11,7 +12,6 @@
1112
from aws_lambda_builders.workflows.python_pip.packager import Package
1213
from aws_lambda_builders.workflows.python_pip.packager import PipRunner
1314
from aws_lambda_builders.workflows.python_pip.packager import SubprocessPip
14-
from aws_lambda_builders.workflows.python_pip.packager import get_lambda_abi
1515
from aws_lambda_builders.workflows.python_pip.packager \
1616
import InvalidSourceDistributionNameError
1717
from aws_lambda_builders.workflows.python_pip.packager import NoSuchPackageError
@@ -85,29 +85,17 @@ def popen(self, *args, **kwargs):
8585
return self._processes.pop()
8686

8787

88-
class TestGetLambdaAbi(object):
89-
def test_get_lambda_abi_python27(self):
90-
assert "cp27mu" == get_lambda_abi("python2.7")
91-
92-
def test_get_lambda_abi_python36(self):
93-
assert "cp36m" == get_lambda_abi("python3.6")
94-
95-
def test_get_lambda_abi_python37(self):
96-
assert "cp37m" == get_lambda_abi("python3.7")
97-
98-
9988
class TestPythonPipDependencyBuilder(object):
10089
def test_can_call_dependency_builder(self, osutils):
10190
mock_dep_builder = mock.Mock(spec=DependencyBuilder)
10291
osutils_mock = mock.Mock(spec=osutils)
10392
builder = PythonPipDependencyBuilder(
10493
osutils=osutils_mock,
10594
dependency_builder=mock_dep_builder,
106-
runtime="runtime"
10795
)
10896
builder.build_dependencies(
10997
'artifacts/path/', 'scratch_dir/path/',
110-
'path/to/requirements.txt'
98+
'path/to/requirements.txt', 'python3.6'
11199
)
112100
mock_dep_builder.build_site_packages.assert_called_once_with(
113101
'path/to/requirements.txt', 'artifacts/path/', 'scratch_dir/path/')
@@ -230,10 +218,14 @@ def test_download_wheels(self, pip_factory):
230218
# for getting lambda compatible wheels.
231219
pip, runner = pip_factory()
232220
packages = ['foo', 'bar', 'baz']
233-
runner.download_manylinux_wheels(packages, 'directory', "abi")
221+
runner.download_manylinux_wheels(packages, 'directory')
222+
if sys.version_info[0] == 2:
223+
abi = 'cp27mu'
224+
else:
225+
abi = 'cp36m'
234226
expected_prefix = ['download', '--only-binary=:all:', '--no-deps',
235227
'--platform', 'manylinux1_x86_64',
236-
'--implementation', 'cp', '--abi', "abi",
228+
'--implementation', 'cp', '--abi', abi,
237229
'--dest', 'directory']
238230
for i, package in enumerate(packages):
239231
assert pip.calls[i].args == expected_prefix + [package]
@@ -242,7 +234,7 @@ def test_download_wheels(self, pip_factory):
242234

243235
def test_download_wheels_no_wheels(self, pip_factory):
244236
pip, runner = pip_factory()
245-
runner.download_manylinux_wheels([], 'directory', "abi")
237+
runner.download_manylinux_wheels([], 'directory')
246238
assert len(pip.calls) == 0
247239

248240
def test_raise_no_such_package_error(self, pip_factory):

0 commit comments

Comments
 (0)