From d921cd83ff22d0cd60a61b79347e54015ac8b364 Mon Sep 17 00:00:00 2001 From: Frank van Tol Date: Mon, 22 Jun 2020 13:45:22 +0200 Subject: [PATCH 01/31] Implementing #175 --- aws_lambda_builders/workflows/python_pip/workflow.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/aws_lambda_builders/workflows/python_pip/workflow.py b/aws_lambda_builders/workflows/python_pip/workflow.py index f623d03cc..2ed5c0976 100644 --- a/aws_lambda_builders/workflows/python_pip/workflow.py +++ b/aws_lambda_builders/workflows/python_pip/workflow.py @@ -20,6 +20,7 @@ class PythonPipWorkflow(BaseWorkflow): ".aws-sam", ".chalice", ".git", + ".gitignore", # Compiled files "*.pyc", "__pycache__", @@ -51,6 +52,7 @@ class PythonPipWorkflow(BaseWorkflow): "venv.bak", "env.bak", "ENV", + "env", # Editors # TODO: Move the commonly ignored files to base class ".vscode", From d993b1c83ae0c073b9200df4f958972a4a7febc6 Mon Sep 17 00:00:00 2001 From: Frank van Tol Date: Mon, 22 Jun 2020 22:17:13 +0200 Subject: [PATCH 02/31] Updating certifi version to match test --- tests/integration/workflows/custom_make/test_custom_make.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/integration/workflows/custom_make/test_custom_make.py b/tests/integration/workflows/custom_make/test_custom_make.py index 7c19f8009..508c66827 100644 --- a/tests/integration/workflows/custom_make/test_custom_make.py +++ b/tests/integration/workflows/custom_make/test_custom_make.py @@ -46,7 +46,7 @@ def test_must_build_python_project_through_makefile(self): "idna", "urllib3-1.25.9.dist-info", "chardet-3.0.4.dist-info", - "certifi-2020.4.5.1.dist-info", + "certifi-2020.6.20.dist-info", "certifi", "idna-2.9.dist-info", "requests", From fdf27ec9c7c2350f7cc991b6ec920569509b34f6 Mon Sep 17 00:00:00 2001 From: Wilton Wang Date: Wed, 22 Jul 2020 17:06:38 -0700 Subject: [PATCH 03/31] Added Dynamic Encoding Selection Based on Windows System Default --- .gitignore | 1 + .../workflows/dotnet_clipackage/dotnetcli.py | 14 +++++++++++--- .../workflows/dotnet_clipackage/utils.py | 4 ++-- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index c7f990167..b031dced1 100644 --- a/.gitignore +++ b/.gitignore @@ -187,6 +187,7 @@ typings/ # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 # User-specific stuff: +.vscode # Sensitive or high-churn files: diff --git a/aws_lambda_builders/workflows/dotnet_clipackage/dotnetcli.py b/aws_lambda_builders/workflows/dotnet_clipackage/dotnetcli.py index b1fe104f1..dd570f5e4 100644 --- a/aws_lambda_builders/workflows/dotnet_clipackage/dotnetcli.py +++ b/aws_lambda_builders/workflows/dotnet_clipackage/dotnetcli.py @@ -49,14 +49,22 @@ def run(self, args, cwd=None): LOG.debug("executing dotnet: %s", invoke_dotnet) - p = self.os_utils.popen(invoke_dotnet, stdout=self.os_utils.pipe, stderr=self.os_utils.pipe, cwd=cwd) + #TODO Support for other OS + encoding, encoding_err = self.os_utils.popen(["powershell.exe", + "[system.console]::OutputEncoding.CodePage"], + stdout=self.os_utils.pipe, stderr=self.os_utils.pipe, encoding="ascii").communicate() + + encoding = encoding.strip() + LOG.info("Encoding: %s" % encoding) + + p = self.os_utils.popen(invoke_dotnet, stdout=self.os_utils.pipe, stderr=self.os_utils.pipe, cwd=cwd, encoding=encoding) out, err = p.communicate() # The package command contains lots of useful information on how the package was created and # information when the package command was not successful. For that reason the output is # always written to the output to help developers diagnose issues. - LOG.info(out.decode("utf8").strip()) + LOG.info(out.strip()) if p.returncode != 0: - raise DotnetCLIExecutionError(message=err.decode("utf8").strip()) + raise DotnetCLIExecutionError(message=err.strip()) diff --git a/aws_lambda_builders/workflows/dotnet_clipackage/utils.py b/aws_lambda_builders/workflows/dotnet_clipackage/utils.py index 0df1a3fcd..fffeca068 100644 --- a/aws_lambda_builders/workflows/dotnet_clipackage/utils.py +++ b/aws_lambda_builders/workflows/dotnet_clipackage/utils.py @@ -15,8 +15,8 @@ class OSUtils(object): Convenience wrapper around common system functions """ - def popen(self, command, stdout=None, stderr=None, env=None, cwd=None): - p = subprocess.Popen(command, stdout=stdout, stderr=stderr, env=env, cwd=cwd) + def popen(self, command, stdout=None, stderr=None, env=None, cwd=None, encoding=None): + p = subprocess.Popen(command, stdout=stdout, stderr=stderr, env=env, cwd=cwd, encoding=encoding) return p def is_windows(self): From bf0cb25a5e908286061883aa78fd192674e294d6 Mon Sep 17 00:00:00 2001 From: Wilton Wang Date: Fri, 24 Jul 2020 13:48:35 -0700 Subject: [PATCH 04/31] Fixed dotnet output system dependent encoding --- .../workflows/dotnet_clipackage/dotnetcli.py | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/aws_lambda_builders/workflows/dotnet_clipackage/dotnetcli.py b/aws_lambda_builders/workflows/dotnet_clipackage/dotnetcli.py index dd570f5e4..d0083ff70 100644 --- a/aws_lambda_builders/workflows/dotnet_clipackage/dotnetcli.py +++ b/aws_lambda_builders/workflows/dotnet_clipackage/dotnetcli.py @@ -4,6 +4,7 @@ import sys import logging +import locale from .utils import OSUtils @@ -49,14 +50,8 @@ def run(self, args, cwd=None): LOG.debug("executing dotnet: %s", invoke_dotnet) - #TODO Support for other OS - encoding, encoding_err = self.os_utils.popen(["powershell.exe", - "[system.console]::OutputEncoding.CodePage"], - stdout=self.os_utils.pipe, stderr=self.os_utils.pipe, encoding="ascii").communicate() - - encoding = encoding.strip() - LOG.info("Encoding: %s" % encoding) - + # DotNet output is in system locale dependent encoding + encoding = locale.getpreferredencoding() p = self.os_utils.popen(invoke_dotnet, stdout=self.os_utils.pipe, stderr=self.os_utils.pipe, cwd=cwd, encoding=encoding) out, err = p.communicate() From 04b91a8fc659d07ff6b16b96e7baef4ebf2d7222 Mon Sep 17 00:00:00 2001 From: Wilton Wang Date: Fri, 24 Jul 2020 15:45:58 -0700 Subject: [PATCH 05/31] Updated test_custom_make urllib3 Version --- tests/integration/workflows/custom_make/test_custom_make.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/integration/workflows/custom_make/test_custom_make.py b/tests/integration/workflows/custom_make/test_custom_make.py index 8b4e59fdd..6eec92c9f 100644 --- a/tests/integration/workflows/custom_make/test_custom_make.py +++ b/tests/integration/workflows/custom_make/test_custom_make.py @@ -44,7 +44,7 @@ def test_must_build_python_project_through_makefile(self): "chardet", "urllib3", "idna", - "urllib3-1.25.9.dist-info", + "urllib3-1.25.10.dist-info", "chardet-3.0.4.dist-info", "certifi-2020.4.5.2.dist-info", "certifi", From 991c4b8a5c918b0277f10b0f866248eb412845be Mon Sep 17 00:00:00 2001 From: Wilton Wang Date: Fri, 24 Jul 2020 16:24:46 -0700 Subject: [PATCH 06/31] Reformatted with black --- aws_lambda_builders/workflows/dotnet_clipackage/dotnetcli.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/aws_lambda_builders/workflows/dotnet_clipackage/dotnetcli.py b/aws_lambda_builders/workflows/dotnet_clipackage/dotnetcli.py index d0083ff70..e9ab15f68 100644 --- a/aws_lambda_builders/workflows/dotnet_clipackage/dotnetcli.py +++ b/aws_lambda_builders/workflows/dotnet_clipackage/dotnetcli.py @@ -52,7 +52,9 @@ def run(self, args, cwd=None): # DotNet output is in system locale dependent encoding encoding = locale.getpreferredencoding() - p = self.os_utils.popen(invoke_dotnet, stdout=self.os_utils.pipe, stderr=self.os_utils.pipe, cwd=cwd, encoding=encoding) + p = self.os_utils.popen( + invoke_dotnet, stdout=self.os_utils.pipe, stderr=self.os_utils.pipe, cwd=cwd, encoding=encoding + ) out, err = p.communicate() From a11a6ead4ecabf33cebe2122f39c9fb69fe95536 Mon Sep 17 00:00:00 2001 From: Wilton Wang Date: Mon, 27 Jul 2020 11:11:17 -0700 Subject: [PATCH 07/31] Rollback Changes to popen for Python 2 Support --- .../workflows/dotnet_clipackage/dotnetcli.py | 8 +++----- aws_lambda_builders/workflows/dotnet_clipackage/utils.py | 4 ++-- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/aws_lambda_builders/workflows/dotnet_clipackage/dotnetcli.py b/aws_lambda_builders/workflows/dotnet_clipackage/dotnetcli.py index e9ab15f68..6b7226129 100644 --- a/aws_lambda_builders/workflows/dotnet_clipackage/dotnetcli.py +++ b/aws_lambda_builders/workflows/dotnet_clipackage/dotnetcli.py @@ -52,16 +52,14 @@ def run(self, args, cwd=None): # DotNet output is in system locale dependent encoding encoding = locale.getpreferredencoding() - p = self.os_utils.popen( - invoke_dotnet, stdout=self.os_utils.pipe, stderr=self.os_utils.pipe, cwd=cwd, encoding=encoding - ) + p = self.os_utils.popen(invoke_dotnet, stdout=self.os_utils.pipe, stderr=self.os_utils.pipe, cwd=cwd) out, err = p.communicate() # The package command contains lots of useful information on how the package was created and # information when the package command was not successful. For that reason the output is # always written to the output to help developers diagnose issues. - LOG.info(out.strip()) + LOG.info(out.decode(encoding).strip()) if p.returncode != 0: - raise DotnetCLIExecutionError(message=err.strip()) + raise DotnetCLIExecutionError(message=err.decode(encoding).strip()) diff --git a/aws_lambda_builders/workflows/dotnet_clipackage/utils.py b/aws_lambda_builders/workflows/dotnet_clipackage/utils.py index fffeca068..0df1a3fcd 100644 --- a/aws_lambda_builders/workflows/dotnet_clipackage/utils.py +++ b/aws_lambda_builders/workflows/dotnet_clipackage/utils.py @@ -15,8 +15,8 @@ class OSUtils(object): Convenience wrapper around common system functions """ - def popen(self, command, stdout=None, stderr=None, env=None, cwd=None, encoding=None): - p = subprocess.Popen(command, stdout=stdout, stderr=stderr, env=env, cwd=cwd, encoding=encoding) + def popen(self, command, stdout=None, stderr=None, env=None, cwd=None): + p = subprocess.Popen(command, stdout=stdout, stderr=stderr, env=env, cwd=cwd) return p def is_windows(self): From 29dbbfd349c7c95c7d34ce5ec45e9caa86519064 Mon Sep 17 00:00:00 2001 From: Wilton Wang Date: Tue, 4 Aug 2020 14:43:18 -0700 Subject: [PATCH 08/31] Added Doc Page for DotNet Output Encoding --- aws_lambda_builders/workflows/dotnet_clipackage/dotnetcli.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/aws_lambda_builders/workflows/dotnet_clipackage/dotnetcli.py b/aws_lambda_builders/workflows/dotnet_clipackage/dotnetcli.py index 6b7226129..5986b3656 100644 --- a/aws_lambda_builders/workflows/dotnet_clipackage/dotnetcli.py +++ b/aws_lambda_builders/workflows/dotnet_clipackage/dotnetcli.py @@ -51,6 +51,8 @@ def run(self, args, cwd=None): LOG.debug("executing dotnet: %s", invoke_dotnet) # DotNet output is in system locale dependent encoding + # https://docs.microsoft.com/en-us/dotnet/api/system.console.outputencoding?view=netcore-3.1#remarks + # "The default code page that the console uses is determined by the system locale." encoding = locale.getpreferredencoding() p = self.os_utils.popen(invoke_dotnet, stdout=self.os_utils.pipe, stderr=self.os_utils.pipe, cwd=cwd) From 03db11dd6c82f9bb4a20be0729814db07dc695b3 Mon Sep 17 00:00:00 2001 From: Sriram Madapusi Vasudevan Date: Wed, 12 Aug 2020 14:36:18 -0700 Subject: [PATCH 09/31] fix(ruby): use stdout stream to raise exceptions from bundler - relevant error information is in stdout instead of stderr for bundler. --- aws_lambda_builders/workflows/ruby_bundler/bundler.py | 5 +++-- tests/unit/workflows/ruby_bundler/test_bundler.py | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/aws_lambda_builders/workflows/ruby_bundler/bundler.py b/aws_lambda_builders/workflows/ruby_bundler/bundler.py index 33405f233..fecee69a9 100644 --- a/aws_lambda_builders/workflows/ruby_bundler/bundler.py +++ b/aws_lambda_builders/workflows/ruby_bundler/bundler.py @@ -48,9 +48,10 @@ def run(self, args, cwd=None): p = self.osutils.popen(invoke_bundler, stdout=self.osutils.pipe, stderr=self.osutils.pipe, cwd=cwd) - out, err = p.communicate() + out, _ = p.communicate() if p.returncode != 0: - raise BundlerExecutionError(message=err.decode("utf8").strip()) + # Bundler has relevant information in stdout, not stderr. + raise BundlerExecutionError(message=out.decode("utf8").strip()) return out.decode("utf8").strip() diff --git a/tests/unit/workflows/ruby_bundler/test_bundler.py b/tests/unit/workflows/ruby_bundler/test_bundler.py index 7a83af11a..fb8ab4612 100644 --- a/tests/unit/workflows/ruby_bundler/test_bundler.py +++ b/tests/unit/workflows/ruby_bundler/test_bundler.py @@ -58,7 +58,7 @@ def test_returns_popen_out_decoded_if_retcode_is_0(self): def test_raises_BundlerExecutionError_with_err_text_if_retcode_is_not_0(self): self.popen.returncode = 1 - self.popen.err = b"some error text\n\n" + self.popen.out = b"some error text\n\n" with self.assertRaises(BundlerExecutionError) as raised: self.under_test.run(["install", "--without", "development", "test"]) self.assertEqual(raised.exception.args[0], "Bundler Failed: some error text") From 33db20d6bfd045c64f48d5ff4c1a5eb0fde86586 Mon Sep 17 00:00:00 2001 From: Mehmet Nuri Deveci <5735811+mndeveci@users.noreply.github.com> Date: Wed, 2 Sep 2020 16:27:38 -0700 Subject: [PATCH 10/31] chore: bump version to 1.1.0 --- aws_lambda_builders/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aws_lambda_builders/__init__.py b/aws_lambda_builders/__init__.py index 92d3e3346..50f740c9d 100644 --- a/aws_lambda_builders/__init__.py +++ b/aws_lambda_builders/__init__.py @@ -1,5 +1,5 @@ """ AWS Lambda Builder Library """ -__version__ = "1.0.0" +__version__ = "1.1.0" RPC_PROTOCOL_VERSION = "0.3" From 2742ef7c15c483d9297ec1fda6f5b6fdaef15fa1 Mon Sep 17 00:00:00 2001 From: Sam Liu Date: Mon, 26 Oct 2020 20:57:45 -0700 Subject: [PATCH 11/31] chore: Upgrade pytest to 6.1.1 --- requirements/dev.txt | 6 +-- tests/functional/test_builder.py | 2 +- tests/functional/test_cli.py | 6 +-- tests/functional/test_utils.py | 8 ++-- .../workflows/java_gradle/test_java_utils.py | 4 +- .../workflows/java_maven/test_java_utils.py | 4 +- .../workflows/custom_make/test_custom_make.py | 4 +- .../dotnet_clipackage/test_dotnet.py | 4 +- .../workflows/go_dep/test_go_dep.py | 8 ++-- .../workflows/go_modules/test_go.py | 4 +- .../workflows/nodejs_npm/test_nodejs_npm.py | 12 +++--- .../workflows/python_pip/test_python_pip.py | 2 +- .../workflows/ruby_bundler/test_ruby.py | 6 +-- tests/unit/test_builder.py | 6 +-- tests/unit/test_path_resolver.py | 6 +-- tests/unit/test_registry.py | 26 ++++++------ tests/unit/test_validator.py | 2 +- tests/unit/test_workflow.py | 42 +++++++++---------- .../workflows/java_gradle/test_actions.py | 8 ++-- .../unit/workflows/java_gradle/test_gradle.py | 8 ++-- .../java_gradle/test_gradlew_resolver.py | 8 ++-- .../unit/workflows/java_maven/test_actions.py | 8 ++-- tests/unit/workflows/java_maven/test_maven.py | 8 ++-- .../java_maven/test_maven_resolver.py | 4 +- 24 files changed, 98 insertions(+), 98 deletions(-) diff --git a/requirements/dev.txt b/requirements/dev.txt index 8344b5801..5614139ad 100644 --- a/requirements/dev.txt +++ b/requirements/dev.txt @@ -1,7 +1,7 @@ coverage==4.3.4 flake8==3.3.0; python_version < '3.8' flake8==3.7.9; python_version >= '3.8' -pytest-cov==2.4.0 +pytest-cov==2.10.1 # astroid > 2.0.4 is not compatible with pylint1.7 astroid>=1.5.8,<2.1.0; python_version < '3.8' pylint==1.7.2; python_version < '3.8' @@ -9,8 +9,8 @@ pylint==2.4.4; python_version >= '3.8' isort>=4.2.5,<5; python_version < '3.8' # Test requirements -pytest==3.0.7 -py==1.4.33 +pytest>=6.1.1; python_version >= '3.6' +pytest~=4.6.11; python_version < '3.6' # pytest dropped python 2 support after 4.6.x mock==2.0.0 parameterized==0.6.1 pathlib2==2.3.2; python_version<"3.4" diff --git a/tests/functional/test_builder.py b/tests/functional/test_builder.py index ac0fb3e51..9561ef442 100644 --- a/tests/functional/test_builder.py +++ b/tests/functional/test_builder.py @@ -59,4 +59,4 @@ def test_run_hello_workflow_with_exec_paths(self): with open(self.expected_filename, "r") as fp: contents = fp.read() - self.assertEquals(contents, self.expected_contents) + self.assertEqual(contents, self.expected_contents) diff --git a/tests/functional/test_cli.py b/tests/functional/test_cli.py index 7a2285e6b..e937cf23a 100644 --- a/tests/functional/test_cli.py +++ b/tests/functional/test_cli.py @@ -104,14 +104,14 @@ def test_run_hello_workflow_with_backcompat(self, flavor, protocol_version): response = json.loads(stdout_data) self.assertNotIn("error", response) self.assertIn("result", response) - self.assertEquals(response["result"]["artifacts_dir"], self.artifacts_dir) + self.assertEqual(response["result"]["artifacts_dir"], self.artifacts_dir) self.assertTrue(os.path.exists(self.expected_filename)) contents = "" with open(self.expected_filename, "r") as fp: contents = fp.read() - self.assertEquals(contents, self.expected_contents) + self.assertEqual(contents, self.expected_contents) shutil.rmtree(self.scratch_dir) @parameterized.expand([("request_through_stdin"), ("request_through_argument")]) @@ -160,4 +160,4 @@ def test_run_hello_workflow_incompatible(self, flavor): # Validate the response object. It should be error response response = json.loads(stdout_data) self.assertIn("error", response) - self.assertEquals(response["error"]["code"], 505) + self.assertEqual(response["error"]["code"], 505) diff --git a/tests/functional/test_utils.py b/tests/functional/test_utils.py index db2657c40..f19604dff 100644 --- a/tests/functional/test_utils.py +++ b/tests/functional/test_utils.py @@ -35,10 +35,10 @@ def test_must_respect_excludes_list(self): excludes = [".git", ".aws-sam", "*.pyc"] copytree(self.source, self.dest, ignore=shutil.ignore_patterns(*excludes)) - self.assertEquals(set(os.listdir(self.dest)), {"nested", "a"}) - self.assertEquals(set(os.listdir(os.path.join(self.dest, "nested"))), set()) - self.assertEquals(set(os.listdir(os.path.join(self.dest, "a"))), {"c"}) - self.assertEquals(set(os.listdir(os.path.join(self.dest, "a"))), {"c"}) + self.assertEqual(set(os.listdir(self.dest)), {"nested", "a"}) + self.assertEqual(set(os.listdir(os.path.join(self.dest, "nested"))), set()) + self.assertEqual(set(os.listdir(os.path.join(self.dest, "a"))), {"c"}) + self.assertEqual(set(os.listdir(os.path.join(self.dest, "a"))), {"c"}) def file(*args): diff --git a/tests/functional/workflows/java_gradle/test_java_utils.py b/tests/functional/workflows/java_gradle/test_java_utils.py index e8d4d0478..943a5db24 100644 --- a/tests/functional/workflows/java_gradle/test_java_utils.py +++ b/tests/functional/workflows/java_gradle/test_java_utils.py @@ -33,13 +33,13 @@ def test_listdir(self): names = ["a", "b", "c"] for n in names: self.new_file(self.src, n) - self.assertEquals(set(names), set(self.os_utils.listdir(self.src))) + self.assertEqual(set(names), set(self.os_utils.listdir(self.src))) def test_copy(self): f = self.new_file(self.src, "a") expected = os.path.join(self.dst, "a") copy_ret = self.os_utils.copy(f, expected) - self.assertEquals(expected, copy_ret) + self.assertEqual(expected, copy_ret) self.assertTrue("a" in os.listdir(self.dst)) def test_exists(self): diff --git a/tests/functional/workflows/java_maven/test_java_utils.py b/tests/functional/workflows/java_maven/test_java_utils.py index 9f0bb4c2e..feb93ef12 100644 --- a/tests/functional/workflows/java_maven/test_java_utils.py +++ b/tests/functional/workflows/java_maven/test_java_utils.py @@ -33,13 +33,13 @@ def test_listdir(self): names = ["a", "b", "c"] for n in names: self.new_file(self.src, n) - self.assertEquals(set(names), set(self.os_utils.listdir(self.src))) + self.assertEqual(set(names), set(self.os_utils.listdir(self.src))) def test_copy(self): f = self.new_file(self.src, "a") expected = os.path.join(self.dst, "a") copy_ret = self.os_utils.copy(f, expected) - self.assertEquals(expected, copy_ret) + self.assertEqual(expected, copy_ret) self.assertTrue("a" in os.listdir(self.dst)) def test_exists(self): diff --git a/tests/integration/workflows/custom_make/test_custom_make.py b/tests/integration/workflows/custom_make/test_custom_make.py index 6eec92c9f..1f641178e 100644 --- a/tests/integration/workflows/custom_make/test_custom_make.py +++ b/tests/integration/workflows/custom_make/test_custom_make.py @@ -44,7 +44,7 @@ def test_must_build_python_project_through_makefile(self): "chardet", "urllib3", "idna", - "urllib3-1.25.10.dist-info", + "urllib3-1.25.11.dist-info", "chardet-3.0.4.dist-info", "certifi-2020.4.5.2.dist-info", "certifi", @@ -55,7 +55,7 @@ def test_must_build_python_project_through_makefile(self): expected_files = self.test_data_files.union(dependencies_installed) output_files = set(os.listdir(self.artifacts_dir)) - self.assertEquals(expected_files, output_files) + self.assertEqual(expected_files, output_files) def test_must_build_python_project_through_makefile_unknown_target(self): with self.assertRaises(WorkflowFailedError): diff --git a/tests/integration/workflows/dotnet_clipackage/test_dotnet.py b/tests/integration/workflows/dotnet_clipackage/test_dotnet.py index f570b0f33..2565aae42 100644 --- a/tests/integration/workflows/dotnet_clipackage/test_dotnet.py +++ b/tests/integration/workflows/dotnet_clipackage/test_dotnet.py @@ -40,7 +40,7 @@ def test_with_defaults_file(self): output_files = set(os.listdir(self.artifacts_dir)) - self.assertEquals(expected_files, output_files) + self.assertEqual(expected_files, output_files) def test_require_parameters(self): source_dir = os.path.join(self.TEST_DATA_FOLDER, "RequireParameters") @@ -66,4 +66,4 @@ def test_require_parameters(self): output_files = set(os.listdir(self.artifacts_dir)) - self.assertEquals(expected_files, output_files) + self.assertEqual(expected_files, output_files) diff --git a/tests/integration/workflows/go_dep/test_go_dep.py b/tests/integration/workflows/go_dep/test_go_dep.py index 85e58689f..185d272bf 100644 --- a/tests/integration/workflows/go_dep/test_go_dep.py +++ b/tests/integration/workflows/go_dep/test_go_dep.py @@ -42,7 +42,7 @@ def test_builds_project_with_no_deps(self): expected_files = {"main"} output_files = set(os.listdir(self.artifacts_dir)) - self.assertEquals(expected_files, output_files) + self.assertEqual(expected_files, output_files) def test_builds_project_and_excludes_hidden_aws_sam(self): source_dir = os.path.join(self.TEST_DATA_FOLDER, "src", "excluded-files") @@ -59,7 +59,7 @@ def test_builds_project_and_excludes_hidden_aws_sam(self): expected_files = {"main"} output_files = set(os.listdir(self.artifacts_dir)) - self.assertEquals(expected_files, output_files) + self.assertEqual(expected_files, output_files) def test_builds_project_with_no_gopkg_file(self): source_dir = os.path.join(self.TEST_DATA_FOLDER, "src", "no-gopkg") @@ -74,7 +74,7 @@ def test_builds_project_with_no_gopkg_file(self): options={"artifact_executable_name": "main"}, ) - self.assertEquals( + self.assertEqual( "GoDepBuilder:DepEnsure - Exec Failed: could not find project Gopkg.toml," + " use dep init to initiate a manifest", str(ex.exception), @@ -95,7 +95,7 @@ def test_builds_project_with_remote_deps(self): expected_files = {"main"} output_files = set(os.listdir(self.artifacts_dir)) - self.assertEquals(expected_files, output_files) + self.assertEqual(expected_files, output_files) def test_builds_project_with_failed_remote_deps(self): source_dir = os.path.join(self.TEST_DATA_FOLDER, "src", "failed-remote") diff --git a/tests/integration/workflows/go_modules/test_go.py b/tests/integration/workflows/go_modules/test_go.py index d8e1e98ce..3fd79415e 100644 --- a/tests/integration/workflows/go_modules/test_go.py +++ b/tests/integration/workflows/go_modules/test_go.py @@ -38,7 +38,7 @@ def test_builds_project_without_dependencies(self): expected_files = {"no-deps-main"} output_files = set(os.listdir(self.artifacts_dir)) print(output_files) - self.assertEquals(expected_files, output_files) + self.assertEqual(expected_files, output_files) def test_builds_project_with_dependencies(self): source_dir = os.path.join(self.TEST_DATA_FOLDER, "with-deps") @@ -52,7 +52,7 @@ def test_builds_project_with_dependencies(self): ) expected_files = {"with-deps-main"} output_files = set(os.listdir(self.artifacts_dir)) - self.assertEquals(expected_files, output_files) + self.assertEqual(expected_files, output_files) def test_fails_if_modules_cannot_resolve_dependencies(self): source_dir = os.path.join(self.TEST_DATA_FOLDER, "broken-deps") diff --git a/tests/integration/workflows/nodejs_npm/test_nodejs_npm.py b/tests/integration/workflows/nodejs_npm/test_nodejs_npm.py index b0c50b7c7..83a8de6e0 100644 --- a/tests/integration/workflows/nodejs_npm/test_nodejs_npm.py +++ b/tests/integration/workflows/nodejs_npm/test_nodejs_npm.py @@ -41,7 +41,7 @@ def test_builds_project_without_dependencies(self): expected_files = {"package.json", "included.js"} output_files = set(os.listdir(self.artifacts_dir)) - self.assertEquals(expected_files, output_files) + self.assertEqual(expected_files, output_files) def test_builds_project_and_excludes_hidden_aws_sam(self): source_dir = os.path.join(self.TEST_DATA_FOLDER, "excluded-files") @@ -56,7 +56,7 @@ def test_builds_project_and_excludes_hidden_aws_sam(self): expected_files = {"package.json", "included.js"} output_files = set(os.listdir(self.artifacts_dir)) - self.assertEquals(expected_files, output_files) + self.assertEqual(expected_files, output_files) def test_builds_project_with_remote_dependencies(self): source_dir = os.path.join(self.TEST_DATA_FOLDER, "npm-deps") @@ -71,11 +71,11 @@ def test_builds_project_with_remote_dependencies(self): expected_files = {"package.json", "included.js", "node_modules"} output_files = set(os.listdir(self.artifacts_dir)) - self.assertEquals(expected_files, output_files) + self.assertEqual(expected_files, output_files) expected_modules = {"minimal-request-promise"} output_modules = set(os.listdir(os.path.join(self.artifacts_dir, "node_modules"))) - self.assertEquals(expected_modules, output_modules) + self.assertEqual(expected_modules, output_modules) def test_builds_project_with_npmrc(self): source_dir = os.path.join(self.TEST_DATA_FOLDER, "npmrc") @@ -91,11 +91,11 @@ def test_builds_project_with_npmrc(self): expected_files = {"package.json", "included.js", "node_modules"} output_files = set(os.listdir(self.artifacts_dir)) - self.assertEquals(expected_files, output_files) + self.assertEqual(expected_files, output_files) expected_modules = {"fake-http-request"} output_modules = set(os.listdir(os.path.join(self.artifacts_dir, "node_modules"))) - self.assertEquals(expected_modules, output_modules) + self.assertEqual(expected_modules, output_modules) def test_fails_if_npm_cannot_resolve_dependencies(self): diff --git a/tests/integration/workflows/python_pip/test_python_pip.py b/tests/integration/workflows/python_pip/test_python_pip.py index eb34293a0..dec957957 100644 --- a/tests/integration/workflows/python_pip/test_python_pip.py +++ b/tests/integration/workflows/python_pip/test_python_pip.py @@ -50,7 +50,7 @@ def test_must_build_python_project(self): else: expected_files = self.test_data_files.union({"numpy", "numpy-1.17.4.dist-info"}) output_files = set(os.listdir(self.artifacts_dir)) - self.assertEquals(expected_files, output_files) + self.assertEqual(expected_files, output_files) def test_mismatch_runtime_python_project(self): # NOTE : Build still works if other versions of python are accessible on the path. eg: /usr/bin/python2.7 diff --git a/tests/integration/workflows/ruby_bundler/test_ruby.py b/tests/integration/workflows/ruby_bundler/test_ruby.py index 3de6eb4c3..9d392d811 100644 --- a/tests/integration/workflows/ruby_bundler/test_ruby.py +++ b/tests/integration/workflows/ruby_bundler/test_ruby.py @@ -33,7 +33,7 @@ def test_builds_project_without_dependencies(self): ) expected_files = {"handler.rb", "Gemfile", "Gemfile.lock", ".bundle", "vendor"} output_files = set(os.listdir(self.artifacts_dir)) - self.assertEquals(expected_files, output_files) + self.assertEqual(expected_files, output_files) def test_builds_project_with_dependencies(self): source_dir = os.path.join(self.TEST_DATA_FOLDER, "with-deps") @@ -42,7 +42,7 @@ def test_builds_project_with_dependencies(self): ) expected_files = {"handler.rb", "Gemfile", "Gemfile.lock", ".bundle", "vendor"} output_files = set(os.listdir(self.artifacts_dir)) - self.assertEquals(expected_files, output_files) + self.assertEqual(expected_files, output_files) def test_builds_project_and_ignores_excluded_files(self): source_dir = os.path.join(self.TEST_DATA_FOLDER, "excluded-files") @@ -51,7 +51,7 @@ def test_builds_project_and_ignores_excluded_files(self): ) expected_files = {"handler.rb", "Gemfile", "Gemfile.lock", ".bundle", "vendor"} output_files = set(os.listdir(self.artifacts_dir)) - self.assertEquals(expected_files, output_files) + self.assertEqual(expected_files, output_files) def test_fails_if_bundler_cannot_resolve_dependencies(self): source_dir = os.path.join(self.TEST_DATA_FOLDER, "broken-deps") diff --git a/tests/unit/test_builder.py b/tests/unit/test_builder.py index 0551a14f8..15ca779a0 100644 --- a/tests/unit/test_builder.py +++ b/tests/unit/test_builder.py @@ -23,7 +23,7 @@ def test_must_load_all_default_workflows(self, get_workflow_mock, importlib_mock # instantiate builder = LambdaBuilder(self.lang, self.lang_framework, self.app_framework) - self.assertEquals(builder.supported_workflows, [self.DEFAULT_WORKFLOW_MODULE]) + self.assertEqual(builder.supported_workflows, [self.DEFAULT_WORKFLOW_MODULE]) # First check if the module was loaded importlib_mock.import_module.assert_called_once_with(self.DEFAULT_WORKFLOW_MODULE) @@ -44,7 +44,7 @@ def test_must_support_loading_custom_workflows(self, get_workflow_mock, importli # instantiate builder = LambdaBuilder(self.lang, self.lang_framework, self.app_framework, supported_workflows=modules) - self.assertEquals(builder.supported_workflows, modules) + self.assertEqual(builder.supported_workflows, modules) # Make sure the modules are loaded in same order as passed importlib_mock.import_module.assert_has_calls([call(m) for m in modules], any_order=False) @@ -56,7 +56,7 @@ def test_must_not_load_any_workflows(self, get_workflow_mock, importlib_mock): modules = [] # Load no modules builder = LambdaBuilder(self.lang, self.lang_framework, self.app_framework, supported_workflows=modules) - self.assertEquals(builder.supported_workflows, []) + self.assertEqual(builder.supported_workflows, []) # Make sure the modules are loaded in same order as passed importlib_mock.import_module.assert_not_called() diff --git a/tests/unit/test_path_resolver.py b/tests/unit/test_path_resolver.py index 35137028d..20d52ae7b 100644 --- a/tests/unit/test_path_resolver.py +++ b/tests/unit/test_path_resolver.py @@ -12,8 +12,8 @@ def setUp(self): self.path_resolver = PathResolver(runtime="chitti2.0", binary="chitti") def test_inits(self): - self.assertEquals(self.path_resolver.runtime, "chitti2.0") - self.assertEquals(self.path_resolver.binary, "chitti") + self.assertEqual(self.path_resolver.runtime, "chitti2.0") + self.assertEqual(self.path_resolver.binary, "chitti") def test_which_fails(self): with self.assertRaises(ValueError): @@ -23,4 +23,4 @@ def test_which_fails(self): def test_which_success_immediate(self): with mock.patch.object(self.path_resolver, "_which") as which_mock: which_mock.return_value = os.getcwd() - self.assertEquals(self.path_resolver.exec_paths, os.getcwd()) + self.assertEqual(self.path_resolver.exec_paths, os.getcwd()) diff --git a/tests/unit/test_registry.py b/tests/unit/test_registry.py index 4acd42c25..d1e0f70cd 100644 --- a/tests/unit/test_registry.py +++ b/tests/unit/test_registry.py @@ -19,7 +19,7 @@ def test_must_add_item(self): capability = Capability(language="a", dependency_manager="b", application_framework="c") self.registry[capability] = self.workflow_data - self.assertEquals(self.workflow_data, self.registry[capability]) + self.assertEqual(self.workflow_data, self.registry[capability]) @parameterized.expand( [ @@ -31,7 +31,7 @@ def test_must_add_item(self): def test_must_add_item_with_optional_capabilities(self, capability): self.registry[capability] = self.workflow_data - self.assertEquals(self.workflow_data, self.registry[capability]) + self.assertEqual(self.workflow_data, self.registry[capability]) def test_must_add_multiple_items(self): capability1 = Capability(language="a", dependency_manager="b", application_framework="c") @@ -40,7 +40,7 @@ def test_must_add_multiple_items(self): self.registry[capability1] = "some data" self.registry[capability2] = "some other data" - self.assertEquals(len(self.registry), 2) + self.assertEqual(len(self.registry), 2) self.assertTrue(capability1 in self.registry) self.assertTrue(capability2 in self.registry) @@ -48,7 +48,7 @@ def test_fail_on_duplciate_entry(self): capability = Capability(language="a", dependency_manager="b", application_framework="c") self.registry[capability] = self.workflow_data - self.assertEquals(self.workflow_data, self.registry[capability]) + self.assertEqual(self.workflow_data, self.registry[capability]) with self.assertRaises(KeyError): self.registry[capability] = "some other data" @@ -57,11 +57,11 @@ def test_must_clear_entries(self): capability = Capability(language="a", dependency_manager="b", application_framework="c") self.registry[capability] = self.workflow_data - self.assertEquals(len(self.registry), 1) + self.assertEqual(len(self.registry), 1) self.registry.clear() - self.assertEquals(len(self.registry), 0) + self.assertEqual(len(self.registry), 0) class TestRegistryLocking(TestCase): @@ -78,7 +78,7 @@ def setUp(self): def test_set_item_must_lock(self): self.registry[self.capability] = self.workflow_data - self.assertEquals(self.mock_lock.method_calls, self.expected_lock_call_order) + self.assertEqual(self.mock_lock.method_calls, self.expected_lock_call_order) def test_set_item_with_duplicate_must_release_lock(self): self.registry[self.capability] = self.workflow_data @@ -90,7 +90,7 @@ def test_set_item_with_duplicate_must_release_lock(self): # Try register duplicate self.registry[self.capability] = self.workflow_data - self.assertEquals(self.mock_lock.method_calls, self.expected_lock_call_order) + self.assertEqual(self.mock_lock.method_calls, self.expected_lock_call_order) def test_get_item_must_not_use_lock(self): self.registry[self.capability] = self.workflow_data @@ -98,7 +98,7 @@ def test_get_item_must_not_use_lock(self): _ = self.registry[self.capability] # noqa: F841 - self.assertEquals(self.mock_lock.method_calls, []) + self.assertEqual(self.mock_lock.method_calls, []) def test_contains_must_not_use_lock(self): self.registry[self.capability] = self.workflow_data @@ -106,7 +106,7 @@ def test_contains_must_not_use_lock(self): _ = self.capability in self.registry # noqa: F841 - self.assertEquals(self.mock_lock.method_calls, []) + self.assertEqual(self.mock_lock.method_calls, []) def test_clear_must_lock(self): self.registry[self.capability] = self.workflow_data @@ -114,7 +114,7 @@ def test_clear_must_lock(self): self.registry.clear() - self.assertEquals(self.mock_lock.method_calls, self.expected_lock_call_order) + self.assertEqual(self.mock_lock.method_calls, self.expected_lock_call_order) class TestGetWorkflow(TestCase): @@ -131,13 +131,13 @@ def test_must_get_workflow_from_custom_registry(self): self.registry[self.capability] = self.workflow_data result = get_workflow(self.capability, registry=self.registry) - self.assertEquals(result, self.workflow_data) + self.assertEqual(result, self.workflow_data) def test_must_get_workflow_from_default_registry(self): DEFAULT_REGISTRY[self.capability] = self.workflow_data result = get_workflow(self.capability) - self.assertEquals(result, self.workflow_data) + self.assertEqual(result, self.workflow_data) def test_must_raise_if_workflow_not_found(self): diff --git a/tests/unit/test_validator.py b/tests/unit/test_validator.py index d48abaaa8..e1cc8844a 100644 --- a/tests/unit/test_validator.py +++ b/tests/unit/test_validator.py @@ -8,7 +8,7 @@ def setUp(self): self.validator = RuntimeValidator(runtime="chitti2.0") def test_inits(self): - self.assertEquals(self.validator.runtime, "chitti2.0") + self.assertEqual(self.validator.runtime, "chitti2.0") def test_validate_runtime(self): self.validator.validate("/usr/bin/chitti") diff --git a/tests/unit/test_workflow.py b/tests/unit/test_workflow.py index a50f40d1d..390297e49 100644 --- a/tests/unit/test_workflow.py +++ b/tests/unit/test_workflow.py @@ -36,8 +36,8 @@ class TestWorkflow(BaseWorkflow): CAPABILITY = self.CAPABILITY1 result_cls = get_workflow(self.CAPABILITY1) - self.assertEquals(len(DEFAULT_REGISTRY), 1) - self.assertEquals(result_cls, TestWorkflow) + self.assertEqual(len(DEFAULT_REGISTRY), 1) + self.assertEqual(result_cls, TestWorkflow) def test_must_register_two_workflows(self): class TestWorkflow1(BaseWorkflow): @@ -48,9 +48,9 @@ class TestWorkflow2(BaseWorkflow): NAME = "TestWorkflow2" CAPABILITY = self.CAPABILITY2 - self.assertEquals(len(DEFAULT_REGISTRY), 2) - self.assertEquals(get_workflow(self.CAPABILITY1), TestWorkflow1) - self.assertEquals(get_workflow(self.CAPABILITY2), TestWorkflow2) + self.assertEqual(len(DEFAULT_REGISTRY), 2) + self.assertEqual(get_workflow(self.CAPABILITY1), TestWorkflow1) + self.assertEqual(get_workflow(self.CAPABILITY2), TestWorkflow2) def test_must_fail_if_name_not_present(self): @@ -59,8 +59,8 @@ def test_must_fail_if_name_not_present(self): class TestWorkflow1(BaseWorkflow): CAPABILITY = self.CAPABILITY1 - self.assertEquals(len(DEFAULT_REGISTRY), 0) - self.assertEquals(str(ctx.exception), "Workflow must provide a valid name") + self.assertEqual(len(DEFAULT_REGISTRY), 0) + self.assertEqual(str(ctx.exception), "Workflow must provide a valid name") def test_must_fail_if_capabilities_not_present(self): @@ -69,8 +69,8 @@ def test_must_fail_if_capabilities_not_present(self): class TestWorkflow1(BaseWorkflow): NAME = "somename" - self.assertEquals(len(DEFAULT_REGISTRY), 0) - self.assertEquals(str(ctx.exception), "Workflow 'somename' must register valid capabilities") + self.assertEqual(len(DEFAULT_REGISTRY), 0) + self.assertEqual(str(ctx.exception), "Workflow 'somename' must register valid capabilities") def test_must_fail_if_capabilities_is_wrong_type(self): @@ -80,8 +80,8 @@ class TestWorkflow1(BaseWorkflow): NAME = "somename" CAPABILITY = "wrong data type" - self.assertEquals(len(DEFAULT_REGISTRY), 0) - self.assertEquals(str(ctx.exception), "Workflow 'somename' must register valid capabilities") + self.assertEqual(len(DEFAULT_REGISTRY), 0) + self.assertEqual(str(ctx.exception), "Workflow 'somename' must register valid capabilities") class TestBaseWorkflow_init(TestCase): @@ -104,14 +104,14 @@ def test_must_initialize_variables(self): options={"c": "d"}, ) - self.assertEquals(self.work.source_dir, "source_dir") - self.assertEquals(self.work.artifacts_dir, "artifacts_dir") - self.assertEquals(self.work.scratch_dir, "scratch_dir") - self.assertEquals(self.work.manifest_path, "manifest_path") - self.assertEquals(self.work.runtime, "runtime") - self.assertEquals(self.work.executable_search_paths, [str(sys.executable)]) - self.assertEquals(self.work.optimizations, {"a": "b"}) - self.assertEquals(self.work.options, {"c": "d"}) + self.assertEqual(self.work.source_dir, "source_dir") + self.assertEqual(self.work.artifacts_dir, "artifacts_dir") + self.assertEqual(self.work.scratch_dir, "scratch_dir") + self.assertEqual(self.work.manifest_path, "manifest_path") + self.assertEqual(self.work.runtime, "runtime") + self.assertEqual(self.work.executable_search_paths, [str(sys.executable)]) + self.assertEqual(self.work.optimizations, {"a": "b"}) + self.assertEqual(self.work.options, {"c": "d"}) class TestBaseWorkflow_is_supported(TestCase): @@ -202,7 +202,7 @@ def test_must_execute_actions_in_sequence(self): self.work.binaries = {"binary": BinaryPath(resolver=resolver_mock, validator=validator_mock, binary="binary")} self.work.run() - self.assertEquals( + self.assertEqual( action_mock.method_calls, [call.action1.execute(), call.action2.execute(), call.action3.execute()] ) self.assertTrue(validator_mock.validate.call_count, 1) @@ -334,4 +334,4 @@ def test_must_pretty_print_workflow_info(self): \tName=Action2, Purpose=RESOLVE_DEPENDENCIES, Description=Resolves dependencies \tName=Action3, Purpose=COMPILE_SOURCE, Description=Compiles code""" - self.assertEquals(result, expected) + self.assertEqual(result, expected) diff --git a/tests/unit/workflows/java_gradle/test_actions.py b/tests/unit/workflows/java_gradle/test_actions.py index 08af9d344..ce8eb5da4 100644 --- a/tests/unit/workflows/java_gradle/test_actions.py +++ b/tests/unit/workflows/java_gradle/test_actions.py @@ -42,7 +42,7 @@ def test_error_in_init_file_copy_raises_action_error(self): ) with self.assertRaises(ActionFailedError) as raised: action.execute() - self.assertEquals(raised.exception.args[0], "Copy failed!") + self.assertEqual(raised.exception.args[0], "Copy failed!") def test_error_building_project_raises_action_error(self): self.subprocess_gradle.build.side_effect = GradleExecutionError(message="Build failed!") @@ -51,13 +51,13 @@ def test_error_building_project_raises_action_error(self): ) with self.assertRaises(ActionFailedError) as raised: action.execute() - self.assertEquals(raised.exception.args[0], "Gradle Failed: Build failed!") + self.assertEqual(raised.exception.args[0], "Gradle Failed: Build failed!") def test_computes_correct_cache_dir(self): action = JavaGradleBuildAction( self.source_dir, self.manifest_path, self.subprocess_gradle, self.scratch_dir, self.os_utils ) - self.assertEquals( + self.assertEqual( action.gradle_cache_dir, os.path.join(self.scratch_dir, JavaGradleBuildAction.GRADLE_CACHE_DIR_NAME) ) @@ -88,4 +88,4 @@ def test_error_in_artifact_copy_raises_action_error(self): action = JavaGradleCopyArtifactsAction(self.source_dir, self.artifacts_dir, self.build_dir, self.os_utils) with self.assertRaises(ActionFailedError) as raised: action.execute() - self.assertEquals(raised.exception.args[0], "scandir failed!") + self.assertEqual(raised.exception.args[0], "scandir failed!") diff --git a/tests/unit/workflows/java_gradle/test_gradle.py b/tests/unit/workflows/java_gradle/test_gradle.py index 1c46bf966..bdf98e80b 100644 --- a/tests/unit/workflows/java_gradle/test_gradle.py +++ b/tests/unit/workflows/java_gradle/test_gradle.py @@ -40,19 +40,19 @@ def setUp(self, MockOSUtils): def test_no_os_utils_build_init_throws(self): with self.assertRaises(ValueError) as err_assert: SubprocessGradle(gradle_binary=self.gradle_binary) - self.assertEquals(err_assert.exception.args[0], "Must provide OSUtils") + self.assertEqual(err_assert.exception.args[0], "Must provide OSUtils") def test_no_gradle_exec_init_throws(self): with self.assertRaises(ValueError) as err_assert: SubprocessGradle(None) - self.assertEquals(err_assert.exception.args[0], "Must provide Gradle BinaryPath") + self.assertEqual(err_assert.exception.args[0], "Must provide Gradle BinaryPath") def test_no_build_file_throws(self): self.os_utils.exists.side_effect = lambda d: False gradle = SubprocessGradle(gradle_binary=self.gradle_binary, os_utils=self.os_utils) with self.assertRaises(BuildFileNotFoundError) as raised: gradle.build(self.source_dir, self.manifest_path) - self.assertEquals( + self.assertEqual( raised.exception.args[0], "Gradle Failed: Gradle build file not found: %s" % self.manifest_path ) @@ -92,7 +92,7 @@ def test_raises_exception_if_retcode_not_0(self): gradle = SubprocessGradle(gradle_binary=self.gradle_binary, os_utils=self.os_utils) with self.assertRaises(GradleExecutionError) as err: gradle.build(self.source_dir, self.manifest_path) - self.assertEquals(err.exception.args[0], "Gradle Failed: Some Error Message") + self.assertEqual(err.exception.args[0], "Gradle Failed: Some Error Message") def test_includes_build_properties_in_command(self): gradle = SubprocessGradle(gradle_binary=self.gradle_binary, os_utils=self.os_utils) diff --git a/tests/unit/workflows/java_gradle/test_gradlew_resolver.py b/tests/unit/workflows/java_gradle/test_gradlew_resolver.py index 900f35a59..74486b9c8 100644 --- a/tests/unit/workflows/java_gradle/test_gradlew_resolver.py +++ b/tests/unit/workflows/java_gradle/test_gradlew_resolver.py @@ -16,7 +16,7 @@ def test_gradlew_exists_returns_gradlew(self): self.mock_os_utils.which.side_effect = lambda executable, executable_search_paths: [gradlew_path] resolver = GradleResolver(os_utils=self.mock_os_utils) - self.assertEquals(resolver.exec_paths, [gradlew_path]) + self.assertEqual(resolver.exec_paths, [gradlew_path]) def test_gradlew_not_exists_returns_gradle_on_path(self): gradle_path = "/path/to/gradle" @@ -25,17 +25,17 @@ def test_gradlew_not_exists_returns_gradle_on_path(self): ) resolver = GradleResolver(os_utils=self.mock_os_utils) - self.assertEquals(resolver.exec_paths, [gradle_path]) + self.assertEqual(resolver.exec_paths, [gradle_path]) def test_throws_value_error_if_no_exec_found(self): self.mock_os_utils.which.side_effect = lambda executable, executable_search_paths: [] resolver = GradleResolver(os_utils=self.mock_os_utils) with self.assertRaises(ValueError) as raised: resolver.exec_paths() - self.assertEquals(raised.exception.args[0], "No Gradle executable found!") + self.assertEqual(raised.exception.args[0], "No Gradle executable found!") @parameterized.expand([[True, "gradlew.bat"], [False, "gradlew"]]) def test_uses_correct_gradlew_name(self, is_windows, expected_wrapper_name): self.mock_os_utils.is_windows.side_effect = [is_windows] resolver = GradleResolver(os_utils=self.mock_os_utils) - self.assertEquals(resolver.wrapper_name, expected_wrapper_name) + self.assertEqual(resolver.wrapper_name, expected_wrapper_name) diff --git a/tests/unit/workflows/java_maven/test_actions.py b/tests/unit/workflows/java_maven/test_actions.py index dfd47cc30..9e207d186 100644 --- a/tests/unit/workflows/java_maven/test_actions.py +++ b/tests/unit/workflows/java_maven/test_actions.py @@ -28,7 +28,7 @@ def test_error_building_project_raises_action_error(self): action = JavaMavenBuildAction(self.scratch_dir, self.subprocess_maven) with self.assertRaises(ActionFailedError) as raised: action.execute() - self.assertEquals(raised.exception.args[0], "Maven Failed: Build failed!") + self.assertEqual(raised.exception.args[0], "Maven Failed: Build failed!") class TestJavaMavenCopyDependencyAction(TestCase): @@ -48,7 +48,7 @@ def test_error_building_project_raises_action_error(self): action = JavaMavenCopyDependencyAction(self.scratch_dir, self.subprocess_maven) with self.assertRaises(ActionFailedError) as raised: action.execute() - self.assertEquals(raised.exception.args[0], "Maven Failed: Build failed!") + self.assertEqual(raised.exception.args[0], "Maven Failed: Build failed!") class TestJavaMavenCopyArtifactsAction(TestCase): @@ -93,13 +93,13 @@ def test_error_in_artifact_copy_raises_action_error(self): action = JavaMavenCopyArtifactsAction(self.scratch_dir, self.artifacts_dir, self.os_utils) with self.assertRaises(ActionFailedError) as raised: action.execute() - self.assertEquals(raised.exception.args[0], "copy failed!") + self.assertEqual(raised.exception.args[0], "copy failed!") def test_missing_required_target_class_directory_raises_action_error(self): self.os_utils.exists.return_value = False action = JavaMavenCopyArtifactsAction(self.scratch_dir, self.artifacts_dir, self.os_utils) with self.assertRaises(ActionFailedError) as raised: action.execute() - self.assertEquals( + self.assertEqual( raised.exception.args[0], "Required target/classes directory was not " "produced from 'mvn package'" ) diff --git a/tests/unit/workflows/java_maven/test_maven.py b/tests/unit/workflows/java_maven/test_maven.py index f24efad50..d4ada149c 100644 --- a/tests/unit/workflows/java_maven/test_maven.py +++ b/tests/unit/workflows/java_maven/test_maven.py @@ -35,12 +35,12 @@ def setUp(self, MockOSUtils): def test_no_os_utils_build_init_throws(self): with self.assertRaises(ValueError) as err_assert: SubprocessMaven(maven_binary=self.maven_binary) - self.assertEquals(err_assert.exception.args[0], "Must provide OSUtils") + self.assertEqual(err_assert.exception.args[0], "Must provide OSUtils") def test_no_maven_exec_init_throws(self): with self.assertRaises(ValueError) as err_assert: SubprocessMaven(None) - self.assertEquals(err_assert.exception.args[0], "Must provide Maven BinaryPath") + self.assertEqual(err_assert.exception.args[0], "Must provide Maven BinaryPath") def test_build_project(self): maven = SubprocessMaven(maven_binary=self.maven_binary, os_utils=self.os_utils) @@ -55,7 +55,7 @@ def test_build_raises_exception_if_retcode_not_0(self): maven = SubprocessMaven(maven_binary=self.maven_binary, os_utils=self.os_utils) with self.assertRaises(MavenExecutionError) as err: maven.build(self.source_dir) - self.assertEquals(err.exception.args[0], "Maven Failed: Some Error Message") + self.assertEqual(err.exception.args[0], "Maven Failed: Some Error Message") def test_copy_dependency(self): maven = SubprocessMaven(maven_binary=self.maven_binary, os_utils=self.os_utils) @@ -73,4 +73,4 @@ def test_copy_dependency_raises_exception_if_retcode_not_0(self): maven = SubprocessMaven(maven_binary=self.maven_binary, os_utils=self.os_utils) with self.assertRaises(MavenExecutionError) as err: maven.copy_dependency(self.source_dir) - self.assertEquals(err.exception.args[0], "Maven Failed: Some Error Message") + self.assertEqual(err.exception.args[0], "Maven Failed: Some Error Message") diff --git a/tests/unit/workflows/java_maven/test_maven_resolver.py b/tests/unit/workflows/java_maven/test_maven_resolver.py index ca78d624a..ae5d7f803 100644 --- a/tests/unit/workflows/java_maven/test_maven_resolver.py +++ b/tests/unit/workflows/java_maven/test_maven_resolver.py @@ -15,11 +15,11 @@ def test_returns_maven_on_path(self): self.mock_os_utils.which.side_effect = lambda executable, executable_search_paths: [maven_path] resolver = MavenResolver(os_utils=self.mock_os_utils) - self.assertEquals(resolver.exec_paths, [maven_path]) + self.assertEqual(resolver.exec_paths, [maven_path]) def test_throws_value_error_if_no_exec_found(self): self.mock_os_utils.which.side_effect = lambda executable, executable_search_paths: [] resolver = MavenResolver(os_utils=self.mock_os_utils) with self.assertRaises(ValueError) as raised: resolver.exec_paths() - self.assertEquals(raised.exception.args[0], "No Maven executable found!") + self.assertEqual(raised.exception.args[0], "No Maven executable found!") From 38b7bdb470c414457ac3fdd34eb9ca2f8a0fae44 Mon Sep 17 00:00:00 2001 From: Sam Liu Date: Mon, 26 Oct 2020 23:06:14 -0700 Subject: [PATCH 12/31] chore: Upgrade mock to 4.0.2 --- requirements/dev.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements/dev.txt b/requirements/dev.txt index 5614139ad..101424d6e 100644 --- a/requirements/dev.txt +++ b/requirements/dev.txt @@ -11,7 +11,7 @@ isort>=4.2.5,<5; python_version < '3.8' # Test requirements pytest>=6.1.1; python_version >= '3.6' pytest~=4.6.11; python_version < '3.6' # pytest dropped python 2 support after 4.6.x -mock==2.0.0 +mock==4.0.2 parameterized==0.6.1 pathlib2==2.3.2; python_version<"3.4" futures==3.2.0; python_version<"3.2.3" From da654d05704ac823fa02167f5a0577283a919a7d Mon Sep 17 00:00:00 2001 From: Sam Liu Date: Mon, 26 Oct 2020 23:07:05 -0700 Subject: [PATCH 13/31] chore: Upgrade parameterize to 0.7.4 --- requirements/dev.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements/dev.txt b/requirements/dev.txt index 101424d6e..7a268fce7 100644 --- a/requirements/dev.txt +++ b/requirements/dev.txt @@ -12,7 +12,7 @@ isort>=4.2.5,<5; python_version < '3.8' pytest>=6.1.1; python_version >= '3.6' pytest~=4.6.11; python_version < '3.6' # pytest dropped python 2 support after 4.6.x mock==4.0.2 -parameterized==0.6.1 +parameterized==0.7.4 pathlib2==2.3.2; python_version<"3.4" futures==3.2.0; python_version<"3.2.3" # Py3.2 backport From a17e082d5d6b9f7a974bb378d914b639ebbd606d Mon Sep 17 00:00:00 2001 From: Sam Liu Date: Mon, 26 Oct 2020 23:10:41 -0700 Subject: [PATCH 14/31] chore: Upgrade coverage to 5.3 --- requirements/dev.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements/dev.txt b/requirements/dev.txt index 7a268fce7..6dc536633 100644 --- a/requirements/dev.txt +++ b/requirements/dev.txt @@ -1,4 +1,4 @@ -coverage==4.3.4 +coverage==5.3 flake8==3.3.0; python_version < '3.8' flake8==3.7.9; python_version >= '3.8' pytest-cov==2.10.1 From 89a054c6a8fe7b7105ac7871fe6a3c8a17574d01 Mon Sep 17 00:00:00 2001 From: Sam Liu Date: Mon, 26 Oct 2020 23:11:22 -0700 Subject: [PATCH 15/31] chore: Upgrade flake8 to 3.8.4 --- requirements/dev.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements/dev.txt b/requirements/dev.txt index 6dc536633..940563848 100644 --- a/requirements/dev.txt +++ b/requirements/dev.txt @@ -1,6 +1,6 @@ coverage==5.3 flake8==3.3.0; python_version < '3.8' -flake8==3.7.9; python_version >= '3.8' +flake8==3.8.4; python_version >= '3.8' pytest-cov==2.10.1 # astroid > 2.0.4 is not compatible with pylint1.7 astroid>=1.5.8,<2.1.0; python_version < '3.8' From f7e2eeef099711141cd4cf2e76e03d8be121125d Mon Sep 17 00:00:00 2001 From: Sam Liu Date: Mon, 26 Oct 2020 23:32:43 -0700 Subject: [PATCH 16/31] chore: Upgrade pylint to 2.6.0 --- requirements/dev.txt | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/requirements/dev.txt b/requirements/dev.txt index 940563848..7bb0f9264 100644 --- a/requirements/dev.txt +++ b/requirements/dev.txt @@ -2,10 +2,7 @@ coverage==5.3 flake8==3.3.0; python_version < '3.8' flake8==3.8.4; python_version >= '3.8' pytest-cov==2.10.1 -# astroid > 2.0.4 is not compatible with pylint1.7 -astroid>=1.5.8,<2.1.0; python_version < '3.8' -pylint==1.7.2; python_version < '3.8' -pylint==2.4.4; python_version >= '3.8' +pylint~=2.6.0 isort>=4.2.5,<5; python_version < '3.8' # Test requirements From 44284ea904c13ad89111486fa0be703bc6014483 Mon Sep 17 00:00:00 2001 From: Sam Liu Date: Mon, 26 Oct 2020 23:33:04 -0700 Subject: [PATCH 17/31] Consider using Python 3 style super() without arguments (super-with-arguments) --- aws_lambda_builders/workflows/custom_make/actions.py | 2 +- aws_lambda_builders/workflows/custom_make/workflow.py | 4 +--- .../workflows/dotnet_clipackage/actions.py | 4 ++-- .../workflows/dotnet_clipackage/workflow.py | 4 +--- aws_lambda_builders/workflows/go_dep/actions.py | 4 ++-- aws_lambda_builders/workflows/go_dep/workflow.py | 4 +--- aws_lambda_builders/workflows/go_modules/workflow.py | 4 +--- aws_lambda_builders/workflows/java_gradle/gradle.py | 2 +- aws_lambda_builders/workflows/java_gradle/workflow.py | 2 +- aws_lambda_builders/workflows/java_maven/actions.py | 4 ++-- aws_lambda_builders/workflows/java_maven/workflow.py | 2 +- aws_lambda_builders/workflows/nodejs_npm/actions.py | 8 ++++---- aws_lambda_builders/workflows/nodejs_npm/workflow.py | 4 +--- aws_lambda_builders/workflows/python_pip/packager.py | 6 +++--- aws_lambda_builders/workflows/python_pip/workflow.py | 4 +--- aws_lambda_builders/workflows/ruby_bundler/actions.py | 4 ++-- aws_lambda_builders/workflows/ruby_bundler/workflow.py | 4 +--- .../testdata/workflows/hello_workflow/write_hello.py | 2 +- tests/unit/test_builder.py | 2 +- 19 files changed, 28 insertions(+), 42 deletions(-) diff --git a/aws_lambda_builders/workflows/custom_make/actions.py b/aws_lambda_builders/workflows/custom_make/actions.py index 67579a74a..6f073812d 100644 --- a/aws_lambda_builders/workflows/custom_make/actions.py +++ b/aws_lambda_builders/workflows/custom_make/actions.py @@ -39,7 +39,7 @@ def __init__(self, artifacts_dir, scratch_dir, manifest_path, osutils, subproces :type subprocess_make aws_lambda_builders.workflows.custom_make.make.SubprocessMake :param subprocess_make: An instance of the Make process wrapper """ - super(CustomMakeAction, self).__init__() + super().__init__() self.artifacts_dir = artifacts_dir self.scratch_dir = scratch_dir self.manifest_path = manifest_path diff --git a/aws_lambda_builders/workflows/custom_make/workflow.py b/aws_lambda_builders/workflows/custom_make/workflow.py index e1f66e0ba..f71e5d160 100644 --- a/aws_lambda_builders/workflows/custom_make/workflow.py +++ b/aws_lambda_builders/workflows/custom_make/workflow.py @@ -24,9 +24,7 @@ class CustomMakeWorkflow(BaseWorkflow): def __init__(self, source_dir, artifacts_dir, scratch_dir, manifest_path, runtime=None, osutils=None, **kwargs): - super(CustomMakeWorkflow, self).__init__( - source_dir, artifacts_dir, scratch_dir, manifest_path, runtime=runtime, **kwargs - ) + super().__init__(source_dir, artifacts_dir, scratch_dir, manifest_path, runtime=runtime, **kwargs) self.os_utils = OSUtils() diff --git a/aws_lambda_builders/workflows/dotnet_clipackage/actions.py b/aws_lambda_builders/workflows/dotnet_clipackage/actions.py index 5ed686ca6..00a0a0f94 100644 --- a/aws_lambda_builders/workflows/dotnet_clipackage/actions.py +++ b/aws_lambda_builders/workflows/dotnet_clipackage/actions.py @@ -24,7 +24,7 @@ class GlobalToolInstallAction(BaseAction): PURPOSE = Purpose.COMPILE_SOURCE def __init__(self, subprocess_dotnet): - super(GlobalToolInstallAction, self).__init__() + super().__init__() self.subprocess_dotnet = subprocess_dotnet def execute(self): @@ -49,7 +49,7 @@ class RunPackageAction(BaseAction): PURPOSE = Purpose.COMPILE_SOURCE def __init__(self, source_dir, subprocess_dotnet, artifacts_dir, options, mode, os_utils=None): - super(RunPackageAction, self).__init__() + super().__init__() self.source_dir = source_dir self.subprocess_dotnet = subprocess_dotnet self.artifacts_dir = artifacts_dir diff --git a/aws_lambda_builders/workflows/dotnet_clipackage/workflow.py b/aws_lambda_builders/workflows/dotnet_clipackage/workflow.py index 6756beffc..227e67ad9 100644 --- a/aws_lambda_builders/workflows/dotnet_clipackage/workflow.py +++ b/aws_lambda_builders/workflows/dotnet_clipackage/workflow.py @@ -21,9 +21,7 @@ class DotnetCliPackageWorkflow(BaseWorkflow): def __init__(self, source_dir, artifacts_dir, scratch_dir, manifest_path, runtime=None, mode=None, **kwargs): - super(DotnetCliPackageWorkflow, self).__init__( - source_dir, artifacts_dir, scratch_dir, manifest_path, runtime=runtime, mode=mode, **kwargs - ) + super().__init__(source_dir, artifacts_dir, scratch_dir, manifest_path, runtime=runtime, mode=mode, **kwargs) options = kwargs["options"] if "options" in kwargs else {} subprocess_dotnetcli = SubprocessDotnetCLI(os_utils=OSUtils()) diff --git a/aws_lambda_builders/workflows/go_dep/actions.py b/aws_lambda_builders/workflows/go_dep/actions.py index f424e7c0b..53bb9f5a8 100644 --- a/aws_lambda_builders/workflows/go_dep/actions.py +++ b/aws_lambda_builders/workflows/go_dep/actions.py @@ -24,7 +24,7 @@ class DepEnsureAction(BaseAction): PURPOSE = Purpose.RESOLVE_DEPENDENCIES def __init__(self, base_dir, subprocess_dep): - super(DepEnsureAction, self).__init__() + super().__init__() self.base_dir = base_dir self.subprocess_dep = subprocess_dep @@ -47,7 +47,7 @@ class GoBuildAction(BaseAction): PURPOSE = Purpose.COMPILE_SOURCE def __init__(self, base_dir, source_path, output_path, subprocess_go, env=None): - super(GoBuildAction, self).__init__() + super().__init__() self.base_dir = base_dir self.source_path = source_path diff --git a/aws_lambda_builders/workflows/go_dep/workflow.py b/aws_lambda_builders/workflows/go_dep/workflow.py index b357418fa..d1405326e 100644 --- a/aws_lambda_builders/workflows/go_dep/workflow.py +++ b/aws_lambda_builders/workflows/go_dep/workflow.py @@ -29,9 +29,7 @@ class GoDepWorkflow(BaseWorkflow): def __init__(self, source_dir, artifacts_dir, scratch_dir, manifest_path, runtime=None, osutils=None, **kwargs): - super(GoDepWorkflow, self).__init__( - source_dir, artifacts_dir, scratch_dir, manifest_path, runtime=runtime, **kwargs - ) + super().__init__(source_dir, artifacts_dir, scratch_dir, manifest_path, runtime=runtime, **kwargs) options = kwargs["options"] if "options" in kwargs else {} handler = options.get("artifact_executable_name", None) diff --git a/aws_lambda_builders/workflows/go_modules/workflow.py b/aws_lambda_builders/workflows/go_modules/workflow.py index 0932e81f5..311c849af 100644 --- a/aws_lambda_builders/workflows/go_modules/workflow.py +++ b/aws_lambda_builders/workflows/go_modules/workflow.py @@ -19,9 +19,7 @@ def __init__( self, source_dir, artifacts_dir, scratch_dir, manifest_path, runtime=None, osutils=None, mode=None, **kwargs ): - super(GoModulesWorkflow, self).__init__( - source_dir, artifacts_dir, scratch_dir, manifest_path, runtime=runtime, **kwargs - ) + super().__init__(source_dir, artifacts_dir, scratch_dir, manifest_path, runtime=runtime, **kwargs) if osutils is None: osutils = OSUtils() diff --git a/aws_lambda_builders/workflows/java_gradle/gradle.py b/aws_lambda_builders/workflows/java_gradle/gradle.py index ffdf38c4d..51405466c 100644 --- a/aws_lambda_builders/workflows/java_gradle/gradle.py +++ b/aws_lambda_builders/workflows/java_gradle/gradle.py @@ -17,7 +17,7 @@ def __init__(self, **kwargs): class BuildFileNotFoundError(GradleExecutionError): def __init__(self, build_file_path): - super(BuildFileNotFoundError, self).__init__(message="Gradle build file not found: %s" % build_file_path) + super().__init__(message="Gradle build file not found: %s" % build_file_path) class SubprocessGradle(object): diff --git a/aws_lambda_builders/workflows/java_gradle/workflow.py b/aws_lambda_builders/workflows/java_gradle/workflow.py index e28c06c94..934c0d338 100644 --- a/aws_lambda_builders/workflows/java_gradle/workflow.py +++ b/aws_lambda_builders/workflows/java_gradle/workflow.py @@ -23,7 +23,7 @@ class JavaGradleWorkflow(BaseWorkflow): INIT_FILE = "lambda-build-init.gradle" def __init__(self, source_dir, artifacts_dir, scratch_dir, manifest_path, **kwargs): - super(JavaGradleWorkflow, self).__init__(source_dir, artifacts_dir, scratch_dir, manifest_path, **kwargs) + super().__init__(source_dir, artifacts_dir, scratch_dir, manifest_path, **kwargs) self.os_utils = OSUtils() self.build_dir = None diff --git a/aws_lambda_builders/workflows/java_maven/actions.py b/aws_lambda_builders/workflows/java_maven/actions.py index 169459cda..0225343d5 100644 --- a/aws_lambda_builders/workflows/java_maven/actions.py +++ b/aws_lambda_builders/workflows/java_maven/actions.py @@ -27,7 +27,7 @@ class JavaMavenBuildAction(JavaMavenBaseAction, BaseAction): PURPOSE = Purpose.COMPILE_SOURCE def __init__(self, scratch_dir, subprocess_maven): - super(JavaMavenBuildAction, self).__init__(scratch_dir, subprocess_maven) + super().__init__(scratch_dir, subprocess_maven) self.scratch_dir = scratch_dir self.subprocess_maven = subprocess_maven @@ -44,7 +44,7 @@ class JavaMavenCopyDependencyAction(JavaMavenBaseAction, BaseAction): PURPOSE = Purpose.COPY_SOURCE def __init__(self, scratch_dir, subprocess_maven): - super(JavaMavenCopyDependencyAction, self).__init__(scratch_dir, subprocess_maven) + super().__init__(scratch_dir, subprocess_maven) self.scratch_dir = scratch_dir self.subprocess_maven = subprocess_maven diff --git a/aws_lambda_builders/workflows/java_maven/workflow.py b/aws_lambda_builders/workflows/java_maven/workflow.py index 6586ee4f0..27bbc0ab9 100644 --- a/aws_lambda_builders/workflows/java_maven/workflow.py +++ b/aws_lambda_builders/workflows/java_maven/workflow.py @@ -22,7 +22,7 @@ class JavaMavenWorkflow(BaseWorkflow): EXCLUDED_FILES = (".aws-sam", ".git") def __init__(self, source_dir, artifacts_dir, scratch_dir, manifest_path, **kwargs): - super(JavaMavenWorkflow, self).__init__(source_dir, artifacts_dir, scratch_dir, manifest_path, **kwargs) + super().__init__(source_dir, artifacts_dir, scratch_dir, manifest_path, **kwargs) self.os_utils = OSUtils() # Assuming root_dir is the same as source_dir for now diff --git a/aws_lambda_builders/workflows/nodejs_npm/actions.py b/aws_lambda_builders/workflows/nodejs_npm/actions.py index 43259bd8c..865992998 100644 --- a/aws_lambda_builders/workflows/nodejs_npm/actions.py +++ b/aws_lambda_builders/workflows/nodejs_npm/actions.py @@ -38,7 +38,7 @@ def __init__(self, artifacts_dir, scratch_dir, manifest_path, osutils, subproces :type subprocess_npm: aws_lambda_builders.workflows.nodejs_npm.npm.SubprocessNpm :param subprocess_npm: An instance of the NPM process wrapper """ - super(NodejsNpmPackAction, self).__init__() + super().__init__() self.artifacts_dir = artifacts_dir self.manifest_path = manifest_path self.scratch_dir = scratch_dir @@ -90,7 +90,7 @@ def __init__(self, artifacts_dir, subprocess_npm): :param subprocess_npm: An instance of the NPM process wrapper """ - super(NodejsNpmInstallAction, self).__init__() + super().__init__() self.artifacts_dir = artifacts_dir self.subprocess_npm = subprocess_npm @@ -135,7 +135,7 @@ def __init__(self, artifacts_dir, source_dir, osutils): :param osutils: An instance of OS Utilities for file manipulation """ - super(NodejsNpmrcCopyAction, self).__init__() + super().__init__() self.artifacts_dir = artifacts_dir self.source_dir = source_dir self.osutils = osutils @@ -177,7 +177,7 @@ def __init__(self, artifacts_dir, osutils): :param osutils: An instance of OS Utilities for file manipulation """ - super(NodejsNpmrcCleanUpAction, self).__init__() + super().__init__() self.artifacts_dir = artifacts_dir self.osutils = osutils diff --git a/aws_lambda_builders/workflows/nodejs_npm/workflow.py b/aws_lambda_builders/workflows/nodejs_npm/workflow.py index b48ea4430..491392505 100644 --- a/aws_lambda_builders/workflows/nodejs_npm/workflow.py +++ b/aws_lambda_builders/workflows/nodejs_npm/workflow.py @@ -24,9 +24,7 @@ class NodejsNpmWorkflow(BaseWorkflow): def __init__(self, source_dir, artifacts_dir, scratch_dir, manifest_path, runtime=None, osutils=None, **kwargs): - super(NodejsNpmWorkflow, self).__init__( - source_dir, artifacts_dir, scratch_dir, manifest_path, runtime=runtime, **kwargs - ) + super().__init__(source_dir, artifacts_dir, scratch_dir, manifest_path, runtime=runtime, **kwargs) if osutils is None: osutils = OSUtils() diff --git a/aws_lambda_builders/workflows/python_pip/packager.py b/aws_lambda_builders/workflows/python_pip/packager.py index 4f3639a5b..d1a3bd61a 100644 --- a/aws_lambda_builders/workflows/python_pip/packager.py +++ b/aws_lambda_builders/workflows/python_pip/packager.py @@ -36,7 +36,7 @@ class InvalidSourceDistributionNameError(PackagerError): class RequirementsFileNotFoundError(PackagerError): def __init__(self, requirements_path): - super(RequirementsFileNotFoundError, self).__init__("Requirements file not found: %s" % requirements_path) + super().__init__("Requirements file not found: %s" % requirements_path) class MissingDependencyError(PackagerError): @@ -50,7 +50,7 @@ class NoSuchPackageError(PackagerError): """Raised when a package name or version could not be found.""" def __init__(self, package_name): - super(NoSuchPackageError, self).__init__("Could not satisfy the requirement: %s" % package_name) + super().__init__("Could not satisfy the requirement: %s" % package_name) class PackageDownloadError(PackagerError): @@ -63,7 +63,7 @@ class UnsupportedPythonVersion(PackagerError): """Generic networking error during a package download.""" def __init__(self, version): - super(UnsupportedPythonVersion, self).__init__("'%s' version of python is not supported" % version) + super().__init__("'%s' version of python is not supported" % version) def get_lambda_abi(runtime): diff --git a/aws_lambda_builders/workflows/python_pip/workflow.py b/aws_lambda_builders/workflows/python_pip/workflow.py index f623d03cc..194953418 100644 --- a/aws_lambda_builders/workflows/python_pip/workflow.py +++ b/aws_lambda_builders/workflows/python_pip/workflow.py @@ -59,9 +59,7 @@ class PythonPipWorkflow(BaseWorkflow): def __init__(self, source_dir, artifacts_dir, scratch_dir, manifest_path, runtime=None, **kwargs): - super(PythonPipWorkflow, self).__init__( - source_dir, artifacts_dir, scratch_dir, manifest_path, runtime=runtime, **kwargs - ) + super().__init__(source_dir, artifacts_dir, scratch_dir, manifest_path, runtime=runtime, **kwargs) self.actions = [ PythonPipBuildAction(artifacts_dir, scratch_dir, manifest_path, runtime, binaries=self.binaries), diff --git a/aws_lambda_builders/workflows/ruby_bundler/actions.py b/aws_lambda_builders/workflows/ruby_bundler/actions.py index ffc9ad048..3711b2e53 100644 --- a/aws_lambda_builders/workflows/ruby_bundler/actions.py +++ b/aws_lambda_builders/workflows/ruby_bundler/actions.py @@ -21,7 +21,7 @@ class RubyBundlerInstallAction(BaseAction): PURPOSE = Purpose.RESOLVE_DEPENDENCIES def __init__(self, source_dir, subprocess_bundler): - super(RubyBundlerInstallAction, self).__init__() + super().__init__() self.source_dir = source_dir self.subprocess_bundler = subprocess_bundler @@ -43,7 +43,7 @@ class RubyBundlerVendorAction(BaseAction): PURPOSE = Purpose.RESOLVE_DEPENDENCIES def __init__(self, source_dir, subprocess_bundler): - super(RubyBundlerVendorAction, self).__init__() + super().__init__() self.source_dir = source_dir self.subprocess_bundler = subprocess_bundler diff --git a/aws_lambda_builders/workflows/ruby_bundler/workflow.py b/aws_lambda_builders/workflows/ruby_bundler/workflow.py index f57f6cf60..7f85d2239 100644 --- a/aws_lambda_builders/workflows/ruby_bundler/workflow.py +++ b/aws_lambda_builders/workflows/ruby_bundler/workflow.py @@ -24,9 +24,7 @@ class RubyBundlerWorkflow(BaseWorkflow): def __init__(self, source_dir, artifacts_dir, scratch_dir, manifest_path, runtime=None, osutils=None, **kwargs): - super(RubyBundlerWorkflow, self).__init__( - source_dir, artifacts_dir, scratch_dir, manifest_path, runtime=runtime, **kwargs - ) + super().__init__(source_dir, artifacts_dir, scratch_dir, manifest_path, runtime=runtime, **kwargs) if osutils is None: osutils = OSUtils() diff --git a/tests/functional/testdata/workflows/hello_workflow/write_hello.py b/tests/functional/testdata/workflows/hello_workflow/write_hello.py index a2cf94370..ed39efee7 100644 --- a/tests/functional/testdata/workflows/hello_workflow/write_hello.py +++ b/tests/functional/testdata/workflows/hello_workflow/write_hello.py @@ -36,6 +36,6 @@ class WriteHelloWorkflow(BaseWorkflow): CAPABILITY = Capability(language="python", dependency_manager="test", application_framework="test") def __init__(self, source_dir, artifacts_dir, *args, **kwargs): - super(WriteHelloWorkflow, self).__init__(source_dir, artifacts_dir, *args, **kwargs) + super().__init__(source_dir, artifacts_dir, *args, **kwargs) self.actions = [WriteHelloAction(artifacts_dir)] diff --git a/tests/unit/test_builder.py b/tests/unit/test_builder.py index 15ca779a0..2f2d19456 100644 --- a/tests/unit/test_builder.py +++ b/tests/unit/test_builder.py @@ -84,7 +84,7 @@ def __init__( executable_search_paths=None, mode=None, ): - super(MyWorkflow, self).__init__( + super().__init__( source_dir, artifacts_dir, scratch_dir, From 1e57bf972bace08385be82e597bd0a231ef7bbfd Mon Sep 17 00:00:00 2001 From: Sam Liu Date: Mon, 26 Oct 2020 23:34:38 -0700 Subject: [PATCH 18/31] Implicit string concatenation found in assignment (implicit-str-concat) --- aws_lambda_builders/workflows/python_pip/packager.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aws_lambda_builders/workflows/python_pip/packager.py b/aws_lambda_builders/workflows/python_pip/packager.py index d1a3bd61a..41cdf3c79 100644 --- a/aws_lambda_builders/workflows/python_pip/packager.py +++ b/aws_lambda_builders/workflows/python_pip/packager.py @@ -550,7 +550,7 @@ def main(self, args, env_vars=None, shim=None): class PipRunner(object): """Wrapper around pip calls used by chalice.""" - _LINK_IS_DIR_PATTERN = "Processing (.+?)\n" " Link is a directory," " ignoring download_dir" + _LINK_IS_DIR_PATTERN = "Processing (.+?)\n Link is a directory, ignoring download_dir" def __init__(self, python_exe, pip, osutils=None): if osutils is None: From cd7c16e2ace9cd57fa2a34466713805ce3f3e850 Mon Sep 17 00:00:00 2001 From: Sam Liu Date: Mon, 26 Oct 2020 23:37:20 -0700 Subject: [PATCH 19/31] Consider explicitly re-raising using the 'from' keyword (raise-missing-from) --- aws_lambda_builders/workflow.py | 6 +++--- aws_lambda_builders/workflows/custom_make/actions.py | 4 ++-- .../workflows/dotnet_clipackage/actions.py | 6 ++++-- aws_lambda_builders/workflows/go_dep/actions.py | 4 ++-- aws_lambda_builders/workflows/go_modules/actions.py | 2 +- aws_lambda_builders/workflows/java_gradle/actions.py | 6 +++--- aws_lambda_builders/workflows/java_maven/actions.py | 6 +++--- aws_lambda_builders/workflows/nodejs_npm/actions.py | 8 ++++---- aws_lambda_builders/workflows/python_pip/actions.py | 4 ++-- aws_lambda_builders/workflows/ruby_bundler/actions.py | 4 ++-- 10 files changed, 26 insertions(+), 24 deletions(-) diff --git a/aws_lambda_builders/workflow.py b/aws_lambda_builders/workflow.py index 42263085b..65f548c97 100644 --- a/aws_lambda_builders/workflow.py +++ b/aws_lambda_builders/workflow.py @@ -52,7 +52,7 @@ def wrapper(self, *args, **kwargs): else binary_checker.binary_path ) except ValueError as ex: - raise WorkflowFailedError(workflow_name=self.NAME, action_name="Resolver", reason=str(ex)) + raise WorkflowFailedError(workflow_name=self.NAME, action_name="Resolver", reason=str(ex)) from ex for executable_path in exec_paths: try: valid_path = binary_checker.validator.validate(executable_path) @@ -273,12 +273,12 @@ def run(self): except ActionFailedError as ex: LOG.debug("%s failed", action_info, exc_info=ex) - raise WorkflowFailedError(workflow_name=self.NAME, action_name=action.NAME, reason=str(ex)) + raise WorkflowFailedError(workflow_name=self.NAME, action_name=action.NAME, reason=str(ex)) from ex except Exception as ex: LOG.debug("%s raised unhandled exception", action_info, exc_info=ex) - raise WorkflowUnknownError(workflow_name=self.NAME, action_name=action.NAME, reason=str(ex)) + raise WorkflowUnknownError(workflow_name=self.NAME, action_name=action.NAME, reason=str(ex)) from ex def __repr__(self): """ diff --git a/aws_lambda_builders/workflows/custom_make/actions.py b/aws_lambda_builders/workflows/custom_make/actions.py index 6f073812d..74f929332 100644 --- a/aws_lambda_builders/workflows/custom_make/actions.py +++ b/aws_lambda_builders/workflows/custom_make/actions.py @@ -72,7 +72,7 @@ def execute(self): try: self.manifest_check() except MakeFileNotFoundError as ex: - raise ActionFailedError(str(ex)) + raise ActionFailedError(str(ex)) from ex # Create the Artifacts Directory if it doesnt exist. if not self.osutils.exists(self.artifacts_dir): @@ -94,4 +94,4 @@ def execute(self): cwd=self.scratch_dir, ) except MakeExecutionError as ex: - raise ActionFailedError(str(ex)) + raise ActionFailedError(str(ex)) from ex diff --git a/aws_lambda_builders/workflows/dotnet_clipackage/actions.py b/aws_lambda_builders/workflows/dotnet_clipackage/actions.py index 00a0a0f94..79ed99b71 100644 --- a/aws_lambda_builders/workflows/dotnet_clipackage/actions.py +++ b/aws_lambda_builders/workflows/dotnet_clipackage/actions.py @@ -36,7 +36,9 @@ def execute(self): try: self.subprocess_dotnet.run(["tool", "update", "-g", "Amazon.Lambda.Tools", "--ignore-failed-sources"]) except DotnetCLIExecutionError as ex: - raise ActionFailedError("Error configuring the Amazon.Lambda.Tools .NET Core Global Tool: " + str(ex)) + raise ActionFailedError( + "Error configuring the Amazon.Lambda.Tools .NET Core Global Tool: " + str(ex) + ) from ex class RunPackageAction(BaseAction): @@ -83,4 +85,4 @@ def execute(self): self.os_utils.expand_zip(zipfullpath, self.artifacts_dir) except DotnetCLIExecutionError as ex: - raise ActionFailedError(str(ex)) + raise ActionFailedError(str(ex)) from ex diff --git a/aws_lambda_builders/workflows/go_dep/actions.py b/aws_lambda_builders/workflows/go_dep/actions.py index 53bb9f5a8..423afab53 100644 --- a/aws_lambda_builders/workflows/go_dep/actions.py +++ b/aws_lambda_builders/workflows/go_dep/actions.py @@ -33,7 +33,7 @@ def execute(self): try: self.subprocess_dep.run(["ensure"], cwd=self.base_dir) except ExecutionError as ex: - raise ActionFailedError(str(ex)) + raise ActionFailedError(str(ex)) from ex class GoBuildAction(BaseAction): @@ -63,4 +63,4 @@ def execute(self): try: self.subprocess_go.run(["build", "-o", self.output_path, self.source_path], cwd=self.source_path, env=env) except ExecutionError as ex: - raise ActionFailedError(str(ex)) + raise ActionFailedError(str(ex)) from ex diff --git a/aws_lambda_builders/workflows/go_modules/actions.py b/aws_lambda_builders/workflows/go_modules/actions.py index 1354a2704..785caaed9 100644 --- a/aws_lambda_builders/workflows/go_modules/actions.py +++ b/aws_lambda_builders/workflows/go_modules/actions.py @@ -21,4 +21,4 @@ def execute(self): try: self.builder.build(self.source_dir, self.output_path) except BuilderError as ex: - raise ActionFailedError(str(ex)) + raise ActionFailedError(str(ex)) from ex diff --git a/aws_lambda_builders/workflows/java_gradle/actions.py b/aws_lambda_builders/workflows/java_gradle/actions.py index ddf8ded9c..cd8844a9c 100644 --- a/aws_lambda_builders/workflows/java_gradle/actions.py +++ b/aws_lambda_builders/workflows/java_gradle/actions.py @@ -38,7 +38,7 @@ def _copy_init_script(self): dst = os.path.join(self.scratch_dir, self.INIT_SCRIPT) return self.os_utils.copy(src, dst) except Exception as ex: - raise ActionFailedError(str(ex)) + raise ActionFailedError(str(ex)) from ex def _build_project(self, init_script_file): try: @@ -52,7 +52,7 @@ def _build_project(self, init_script_file): {self.SCRATCH_DIR_PROPERTY: os.path.abspath(self.scratch_dir)}, ) except GradleExecutionError as ex: - raise ActionFailedError(str(ex)) + raise ActionFailedError(str(ex)) from ex class JavaGradleCopyArtifactsAction(BaseAction): @@ -76,4 +76,4 @@ def _copy_artifacts(self): self.os_utils.makedirs(self.artifacts_dir) self.os_utils.copytree(lambda_build_output, self.artifacts_dir) except Exception as ex: - raise ActionFailedError(str(ex)) + raise ActionFailedError(str(ex)) from ex diff --git a/aws_lambda_builders/workflows/java_maven/actions.py b/aws_lambda_builders/workflows/java_maven/actions.py index 0225343d5..671ff6ad8 100644 --- a/aws_lambda_builders/workflows/java_maven/actions.py +++ b/aws_lambda_builders/workflows/java_maven/actions.py @@ -35,7 +35,7 @@ def execute(self): try: self.subprocess_maven.build(self.scratch_dir) except MavenExecutionError as ex: - raise ActionFailedError(str(ex)) + raise ActionFailedError(str(ex)) from ex class JavaMavenCopyDependencyAction(JavaMavenBaseAction, BaseAction): @@ -52,7 +52,7 @@ def execute(self): try: self.subprocess_maven.copy_dependency(self.scratch_dir) except MavenExecutionError as ex: - raise ActionFailedError(str(ex)) + raise ActionFailedError(str(ex)) from ex class JavaMavenCopyArtifactsAction(BaseAction): @@ -80,4 +80,4 @@ def _copy_artifacts(self): if self.os_utils.exists(dependency_output): self.os_utils.copytree(dependency_output, os.path.join(self.artifacts_dir, "lib")) except Exception as ex: - raise ActionFailedError(str(ex)) + raise ActionFailedError(str(ex)) from ex diff --git a/aws_lambda_builders/workflows/nodejs_npm/actions.py b/aws_lambda_builders/workflows/nodejs_npm/actions.py index 865992998..a98a951ab 100644 --- a/aws_lambda_builders/workflows/nodejs_npm/actions.py +++ b/aws_lambda_builders/workflows/nodejs_npm/actions.py @@ -67,7 +67,7 @@ def execute(self): self.osutils.extract_tarfile(tarfile_path, self.artifacts_dir) except NpmExecutionError as ex: - raise ActionFailedError(str(ex)) + raise ActionFailedError(str(ex)) from ex class NodejsNpmInstallAction(BaseAction): @@ -109,7 +109,7 @@ def execute(self): ) except NpmExecutionError as ex: - raise ActionFailedError(str(ex)) + raise ActionFailedError(str(ex)) from ex class NodejsNpmrcCopyAction(BaseAction): @@ -154,7 +154,7 @@ def execute(self): self.osutils.copy_file(npmrc_path, self.artifacts_dir) except OSError as ex: - raise ActionFailedError(str(ex)) + raise ActionFailedError(str(ex)) from ex class NodejsNpmrcCleanUpAction(BaseAction): @@ -195,4 +195,4 @@ def execute(self): self.osutils.remove_file(npmrc_path) except OSError as ex: - raise ActionFailedError(str(ex)) + raise ActionFailedError(str(ex)) from ex diff --git a/aws_lambda_builders/workflows/python_pip/actions.py b/aws_lambda_builders/workflows/python_pip/actions.py index f4cd225bd..daa47b83c 100644 --- a/aws_lambda_builders/workflows/python_pip/actions.py +++ b/aws_lambda_builders/workflows/python_pip/actions.py @@ -28,7 +28,7 @@ def execute(self): try: pip = SubprocessPip(osutils=os_utils, python_exe=python_path) except MissingPipError as ex: - raise ActionFailedError(str(ex)) + raise ActionFailedError(str(ex)) from ex pip_runner = PipRunner(python_exe=python_path, pip=pip) dependency_builder = DependencyBuilder(osutils=os_utils, pip_runner=pip_runner, runtime=self.runtime) @@ -42,4 +42,4 @@ def execute(self): requirements_path=self.manifest_path, ) except PackagerError as ex: - raise ActionFailedError(str(ex)) + raise ActionFailedError(str(ex)) from ex diff --git a/aws_lambda_builders/workflows/ruby_bundler/actions.py b/aws_lambda_builders/workflows/ruby_bundler/actions.py index 3711b2e53..c5d04fb17 100644 --- a/aws_lambda_builders/workflows/ruby_bundler/actions.py +++ b/aws_lambda_builders/workflows/ruby_bundler/actions.py @@ -30,7 +30,7 @@ def execute(self): LOG.debug("Running bundle install in %s", self.source_dir) self.subprocess_bundler.run(["install", "--without", "development", "test"], cwd=self.source_dir) except BundlerExecutionError as ex: - raise ActionFailedError(str(ex)) + raise ActionFailedError(str(ex)) from ex class RubyBundlerVendorAction(BaseAction): @@ -54,4 +54,4 @@ def execute(self): ["install", "--deployment", "--without", "development", "test"], cwd=self.source_dir ) except BundlerExecutionError as ex: - raise ActionFailedError(str(ex)) + raise ActionFailedError(str(ex)) from ex From 3b1d315fc7a27e910c806d7fd320a98e8b2e7710 Mon Sep 17 00:00:00 2001 From: Sam Liu Date: Mon, 26 Oct 2020 23:40:10 -0700 Subject: [PATCH 20/31] Only install backports.tempfile for 2.7 & 3.6 --- requirements/dev.txt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/requirements/dev.txt b/requirements/dev.txt index 7bb0f9264..a95224295 100644 --- a/requirements/dev.txt +++ b/requirements/dev.txt @@ -12,5 +12,6 @@ mock==4.0.2 parameterized==0.7.4 pathlib2==2.3.2; python_version<"3.4" futures==3.2.0; python_version<"3.2.3" -# Py3.2 backport -backports.tempfile==1.0 + +# tempfile backport for < 3.6 +backports.tempfile==1.0; python_version<"3.7" From 5b1bd957be2faa32f09819f350adacfc722b4a2a Mon Sep 17 00:00:00 2001 From: Sam Liu Date: Tue, 27 Oct 2020 01:06:53 -0700 Subject: [PATCH 21/31] python 2 fallbacks (pylint & mock) --- requirements/dev.txt | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/requirements/dev.txt b/requirements/dev.txt index a95224295..86f7affde 100644 --- a/requirements/dev.txt +++ b/requirements/dev.txt @@ -2,13 +2,18 @@ coverage==5.3 flake8==3.3.0; python_version < '3.8' flake8==3.8.4; python_version >= '3.8' pytest-cov==2.10.1 -pylint~=2.6.0 + +# pylint 2 does not support Python 2. pylint 1.x requires astroid 1.x +astroid~=1.6.0; python_version < '3.6' +pylint~=1.9.5; python_version < '3.6' +pylint~=2.6.0; python_version >= '3.6' isort>=4.2.5,<5; python_version < '3.8' # Test requirements pytest>=6.1.1; python_version >= '3.6' pytest~=4.6.11; python_version < '3.6' # pytest dropped python 2 support after 4.6.x -mock==4.0.2 +mock==3.0.5; python_version < '3.6' +mock==4.0.2; python_version >= '3.6' parameterized==0.7.4 pathlib2==2.3.2; python_version<"3.4" futures==3.2.0; python_version<"3.2.3" From c053a3419549e782e359dec1b6ad7a51c23417c8 Mon Sep 17 00:00:00 2001 From: Sam Liu Date: Tue, 27 Oct 2020 01:07:08 -0700 Subject: [PATCH 22/31] Revert "Consider using Python 3 style super() without arguments (super-with-arguments)" This reverts commit 44284ea904c13ad89111486fa0be703bc6014483. --- aws_lambda_builders/workflows/custom_make/actions.py | 2 +- aws_lambda_builders/workflows/custom_make/workflow.py | 4 +++- .../workflows/dotnet_clipackage/actions.py | 4 ++-- .../workflows/dotnet_clipackage/workflow.py | 4 +++- aws_lambda_builders/workflows/go_dep/actions.py | 4 ++-- aws_lambda_builders/workflows/go_dep/workflow.py | 4 +++- aws_lambda_builders/workflows/go_modules/workflow.py | 4 +++- aws_lambda_builders/workflows/java_gradle/gradle.py | 2 +- aws_lambda_builders/workflows/java_gradle/workflow.py | 2 +- aws_lambda_builders/workflows/java_maven/actions.py | 4 ++-- aws_lambda_builders/workflows/java_maven/workflow.py | 2 +- aws_lambda_builders/workflows/nodejs_npm/actions.py | 8 ++++---- aws_lambda_builders/workflows/nodejs_npm/workflow.py | 4 +++- aws_lambda_builders/workflows/python_pip/packager.py | 6 +++--- aws_lambda_builders/workflows/python_pip/workflow.py | 4 +++- aws_lambda_builders/workflows/ruby_bundler/actions.py | 4 ++-- aws_lambda_builders/workflows/ruby_bundler/workflow.py | 4 +++- .../testdata/workflows/hello_workflow/write_hello.py | 2 +- tests/unit/test_builder.py | 2 +- 19 files changed, 42 insertions(+), 28 deletions(-) diff --git a/aws_lambda_builders/workflows/custom_make/actions.py b/aws_lambda_builders/workflows/custom_make/actions.py index 74f929332..e16d3e835 100644 --- a/aws_lambda_builders/workflows/custom_make/actions.py +++ b/aws_lambda_builders/workflows/custom_make/actions.py @@ -39,7 +39,7 @@ def __init__(self, artifacts_dir, scratch_dir, manifest_path, osutils, subproces :type subprocess_make aws_lambda_builders.workflows.custom_make.make.SubprocessMake :param subprocess_make: An instance of the Make process wrapper """ - super().__init__() + super(CustomMakeAction, self).__init__() self.artifacts_dir = artifacts_dir self.scratch_dir = scratch_dir self.manifest_path = manifest_path diff --git a/aws_lambda_builders/workflows/custom_make/workflow.py b/aws_lambda_builders/workflows/custom_make/workflow.py index f71e5d160..e1f66e0ba 100644 --- a/aws_lambda_builders/workflows/custom_make/workflow.py +++ b/aws_lambda_builders/workflows/custom_make/workflow.py @@ -24,7 +24,9 @@ class CustomMakeWorkflow(BaseWorkflow): def __init__(self, source_dir, artifacts_dir, scratch_dir, manifest_path, runtime=None, osutils=None, **kwargs): - super().__init__(source_dir, artifacts_dir, scratch_dir, manifest_path, runtime=runtime, **kwargs) + super(CustomMakeWorkflow, self).__init__( + source_dir, artifacts_dir, scratch_dir, manifest_path, runtime=runtime, **kwargs + ) self.os_utils = OSUtils() diff --git a/aws_lambda_builders/workflows/dotnet_clipackage/actions.py b/aws_lambda_builders/workflows/dotnet_clipackage/actions.py index 79ed99b71..0f37382a4 100644 --- a/aws_lambda_builders/workflows/dotnet_clipackage/actions.py +++ b/aws_lambda_builders/workflows/dotnet_clipackage/actions.py @@ -24,7 +24,7 @@ class GlobalToolInstallAction(BaseAction): PURPOSE = Purpose.COMPILE_SOURCE def __init__(self, subprocess_dotnet): - super().__init__() + super(GlobalToolInstallAction, self).__init__() self.subprocess_dotnet = subprocess_dotnet def execute(self): @@ -51,7 +51,7 @@ class RunPackageAction(BaseAction): PURPOSE = Purpose.COMPILE_SOURCE def __init__(self, source_dir, subprocess_dotnet, artifacts_dir, options, mode, os_utils=None): - super().__init__() + super(RunPackageAction, self).__init__() self.source_dir = source_dir self.subprocess_dotnet = subprocess_dotnet self.artifacts_dir = artifacts_dir diff --git a/aws_lambda_builders/workflows/dotnet_clipackage/workflow.py b/aws_lambda_builders/workflows/dotnet_clipackage/workflow.py index 227e67ad9..6756beffc 100644 --- a/aws_lambda_builders/workflows/dotnet_clipackage/workflow.py +++ b/aws_lambda_builders/workflows/dotnet_clipackage/workflow.py @@ -21,7 +21,9 @@ class DotnetCliPackageWorkflow(BaseWorkflow): def __init__(self, source_dir, artifacts_dir, scratch_dir, manifest_path, runtime=None, mode=None, **kwargs): - super().__init__(source_dir, artifacts_dir, scratch_dir, manifest_path, runtime=runtime, mode=mode, **kwargs) + super(DotnetCliPackageWorkflow, self).__init__( + source_dir, artifacts_dir, scratch_dir, manifest_path, runtime=runtime, mode=mode, **kwargs + ) options = kwargs["options"] if "options" in kwargs else {} subprocess_dotnetcli = SubprocessDotnetCLI(os_utils=OSUtils()) diff --git a/aws_lambda_builders/workflows/go_dep/actions.py b/aws_lambda_builders/workflows/go_dep/actions.py index 423afab53..517f0a2aa 100644 --- a/aws_lambda_builders/workflows/go_dep/actions.py +++ b/aws_lambda_builders/workflows/go_dep/actions.py @@ -24,7 +24,7 @@ class DepEnsureAction(BaseAction): PURPOSE = Purpose.RESOLVE_DEPENDENCIES def __init__(self, base_dir, subprocess_dep): - super().__init__() + super(DepEnsureAction, self).__init__() self.base_dir = base_dir self.subprocess_dep = subprocess_dep @@ -47,7 +47,7 @@ class GoBuildAction(BaseAction): PURPOSE = Purpose.COMPILE_SOURCE def __init__(self, base_dir, source_path, output_path, subprocess_go, env=None): - super().__init__() + super(GoBuildAction, self).__init__() self.base_dir = base_dir self.source_path = source_path diff --git a/aws_lambda_builders/workflows/go_dep/workflow.py b/aws_lambda_builders/workflows/go_dep/workflow.py index d1405326e..b357418fa 100644 --- a/aws_lambda_builders/workflows/go_dep/workflow.py +++ b/aws_lambda_builders/workflows/go_dep/workflow.py @@ -29,7 +29,9 @@ class GoDepWorkflow(BaseWorkflow): def __init__(self, source_dir, artifacts_dir, scratch_dir, manifest_path, runtime=None, osutils=None, **kwargs): - super().__init__(source_dir, artifacts_dir, scratch_dir, manifest_path, runtime=runtime, **kwargs) + super(GoDepWorkflow, self).__init__( + source_dir, artifacts_dir, scratch_dir, manifest_path, runtime=runtime, **kwargs + ) options = kwargs["options"] if "options" in kwargs else {} handler = options.get("artifact_executable_name", None) diff --git a/aws_lambda_builders/workflows/go_modules/workflow.py b/aws_lambda_builders/workflows/go_modules/workflow.py index 311c849af..0932e81f5 100644 --- a/aws_lambda_builders/workflows/go_modules/workflow.py +++ b/aws_lambda_builders/workflows/go_modules/workflow.py @@ -19,7 +19,9 @@ def __init__( self, source_dir, artifacts_dir, scratch_dir, manifest_path, runtime=None, osutils=None, mode=None, **kwargs ): - super().__init__(source_dir, artifacts_dir, scratch_dir, manifest_path, runtime=runtime, **kwargs) + super(GoModulesWorkflow, self).__init__( + source_dir, artifacts_dir, scratch_dir, manifest_path, runtime=runtime, **kwargs + ) if osutils is None: osutils = OSUtils() diff --git a/aws_lambda_builders/workflows/java_gradle/gradle.py b/aws_lambda_builders/workflows/java_gradle/gradle.py index 51405466c..ffdf38c4d 100644 --- a/aws_lambda_builders/workflows/java_gradle/gradle.py +++ b/aws_lambda_builders/workflows/java_gradle/gradle.py @@ -17,7 +17,7 @@ def __init__(self, **kwargs): class BuildFileNotFoundError(GradleExecutionError): def __init__(self, build_file_path): - super().__init__(message="Gradle build file not found: %s" % build_file_path) + super(BuildFileNotFoundError, self).__init__(message="Gradle build file not found: %s" % build_file_path) class SubprocessGradle(object): diff --git a/aws_lambda_builders/workflows/java_gradle/workflow.py b/aws_lambda_builders/workflows/java_gradle/workflow.py index 934c0d338..e28c06c94 100644 --- a/aws_lambda_builders/workflows/java_gradle/workflow.py +++ b/aws_lambda_builders/workflows/java_gradle/workflow.py @@ -23,7 +23,7 @@ class JavaGradleWorkflow(BaseWorkflow): INIT_FILE = "lambda-build-init.gradle" def __init__(self, source_dir, artifacts_dir, scratch_dir, manifest_path, **kwargs): - super().__init__(source_dir, artifacts_dir, scratch_dir, manifest_path, **kwargs) + super(JavaGradleWorkflow, self).__init__(source_dir, artifacts_dir, scratch_dir, manifest_path, **kwargs) self.os_utils = OSUtils() self.build_dir = None diff --git a/aws_lambda_builders/workflows/java_maven/actions.py b/aws_lambda_builders/workflows/java_maven/actions.py index 671ff6ad8..8a49181b4 100644 --- a/aws_lambda_builders/workflows/java_maven/actions.py +++ b/aws_lambda_builders/workflows/java_maven/actions.py @@ -27,7 +27,7 @@ class JavaMavenBuildAction(JavaMavenBaseAction, BaseAction): PURPOSE = Purpose.COMPILE_SOURCE def __init__(self, scratch_dir, subprocess_maven): - super().__init__(scratch_dir, subprocess_maven) + super(JavaMavenBuildAction, self).__init__(scratch_dir, subprocess_maven) self.scratch_dir = scratch_dir self.subprocess_maven = subprocess_maven @@ -44,7 +44,7 @@ class JavaMavenCopyDependencyAction(JavaMavenBaseAction, BaseAction): PURPOSE = Purpose.COPY_SOURCE def __init__(self, scratch_dir, subprocess_maven): - super().__init__(scratch_dir, subprocess_maven) + super(JavaMavenCopyDependencyAction, self).__init__(scratch_dir, subprocess_maven) self.scratch_dir = scratch_dir self.subprocess_maven = subprocess_maven diff --git a/aws_lambda_builders/workflows/java_maven/workflow.py b/aws_lambda_builders/workflows/java_maven/workflow.py index 27bbc0ab9..6586ee4f0 100644 --- a/aws_lambda_builders/workflows/java_maven/workflow.py +++ b/aws_lambda_builders/workflows/java_maven/workflow.py @@ -22,7 +22,7 @@ class JavaMavenWorkflow(BaseWorkflow): EXCLUDED_FILES = (".aws-sam", ".git") def __init__(self, source_dir, artifacts_dir, scratch_dir, manifest_path, **kwargs): - super().__init__(source_dir, artifacts_dir, scratch_dir, manifest_path, **kwargs) + super(JavaMavenWorkflow, self).__init__(source_dir, artifacts_dir, scratch_dir, manifest_path, **kwargs) self.os_utils = OSUtils() # Assuming root_dir is the same as source_dir for now diff --git a/aws_lambda_builders/workflows/nodejs_npm/actions.py b/aws_lambda_builders/workflows/nodejs_npm/actions.py index a98a951ab..3432dada1 100644 --- a/aws_lambda_builders/workflows/nodejs_npm/actions.py +++ b/aws_lambda_builders/workflows/nodejs_npm/actions.py @@ -38,7 +38,7 @@ def __init__(self, artifacts_dir, scratch_dir, manifest_path, osutils, subproces :type subprocess_npm: aws_lambda_builders.workflows.nodejs_npm.npm.SubprocessNpm :param subprocess_npm: An instance of the NPM process wrapper """ - super().__init__() + super(NodejsNpmPackAction, self).__init__() self.artifacts_dir = artifacts_dir self.manifest_path = manifest_path self.scratch_dir = scratch_dir @@ -90,7 +90,7 @@ def __init__(self, artifacts_dir, subprocess_npm): :param subprocess_npm: An instance of the NPM process wrapper """ - super().__init__() + super(NodejsNpmInstallAction, self).__init__() self.artifacts_dir = artifacts_dir self.subprocess_npm = subprocess_npm @@ -135,7 +135,7 @@ def __init__(self, artifacts_dir, source_dir, osutils): :param osutils: An instance of OS Utilities for file manipulation """ - super().__init__() + super(NodejsNpmrcCopyAction, self).__init__() self.artifacts_dir = artifacts_dir self.source_dir = source_dir self.osutils = osutils @@ -177,7 +177,7 @@ def __init__(self, artifacts_dir, osutils): :param osutils: An instance of OS Utilities for file manipulation """ - super().__init__() + super(NodejsNpmrcCleanUpAction, self).__init__() self.artifacts_dir = artifacts_dir self.osutils = osutils diff --git a/aws_lambda_builders/workflows/nodejs_npm/workflow.py b/aws_lambda_builders/workflows/nodejs_npm/workflow.py index 491392505..b48ea4430 100644 --- a/aws_lambda_builders/workflows/nodejs_npm/workflow.py +++ b/aws_lambda_builders/workflows/nodejs_npm/workflow.py @@ -24,7 +24,9 @@ class NodejsNpmWorkflow(BaseWorkflow): def __init__(self, source_dir, artifacts_dir, scratch_dir, manifest_path, runtime=None, osutils=None, **kwargs): - super().__init__(source_dir, artifacts_dir, scratch_dir, manifest_path, runtime=runtime, **kwargs) + super(NodejsNpmWorkflow, self).__init__( + source_dir, artifacts_dir, scratch_dir, manifest_path, runtime=runtime, **kwargs + ) if osutils is None: osutils = OSUtils() diff --git a/aws_lambda_builders/workflows/python_pip/packager.py b/aws_lambda_builders/workflows/python_pip/packager.py index 41cdf3c79..87abb7765 100644 --- a/aws_lambda_builders/workflows/python_pip/packager.py +++ b/aws_lambda_builders/workflows/python_pip/packager.py @@ -36,7 +36,7 @@ class InvalidSourceDistributionNameError(PackagerError): class RequirementsFileNotFoundError(PackagerError): def __init__(self, requirements_path): - super().__init__("Requirements file not found: %s" % requirements_path) + super(RequirementsFileNotFoundError, self).__init__("Requirements file not found: %s" % requirements_path) class MissingDependencyError(PackagerError): @@ -50,7 +50,7 @@ class NoSuchPackageError(PackagerError): """Raised when a package name or version could not be found.""" def __init__(self, package_name): - super().__init__("Could not satisfy the requirement: %s" % package_name) + super(NoSuchPackageError, self).__init__("Could not satisfy the requirement: %s" % package_name) class PackageDownloadError(PackagerError): @@ -63,7 +63,7 @@ class UnsupportedPythonVersion(PackagerError): """Generic networking error during a package download.""" def __init__(self, version): - super().__init__("'%s' version of python is not supported" % version) + super(UnsupportedPythonVersion, self).__init__("'%s' version of python is not supported" % version) def get_lambda_abi(runtime): diff --git a/aws_lambda_builders/workflows/python_pip/workflow.py b/aws_lambda_builders/workflows/python_pip/workflow.py index 194953418..f623d03cc 100644 --- a/aws_lambda_builders/workflows/python_pip/workflow.py +++ b/aws_lambda_builders/workflows/python_pip/workflow.py @@ -59,7 +59,9 @@ class PythonPipWorkflow(BaseWorkflow): def __init__(self, source_dir, artifacts_dir, scratch_dir, manifest_path, runtime=None, **kwargs): - super().__init__(source_dir, artifacts_dir, scratch_dir, manifest_path, runtime=runtime, **kwargs) + super(PythonPipWorkflow, self).__init__( + source_dir, artifacts_dir, scratch_dir, manifest_path, runtime=runtime, **kwargs + ) self.actions = [ PythonPipBuildAction(artifacts_dir, scratch_dir, manifest_path, runtime, binaries=self.binaries), diff --git a/aws_lambda_builders/workflows/ruby_bundler/actions.py b/aws_lambda_builders/workflows/ruby_bundler/actions.py index c5d04fb17..dc0b532d0 100644 --- a/aws_lambda_builders/workflows/ruby_bundler/actions.py +++ b/aws_lambda_builders/workflows/ruby_bundler/actions.py @@ -21,7 +21,7 @@ class RubyBundlerInstallAction(BaseAction): PURPOSE = Purpose.RESOLVE_DEPENDENCIES def __init__(self, source_dir, subprocess_bundler): - super().__init__() + super(RubyBundlerInstallAction, self).__init__() self.source_dir = source_dir self.subprocess_bundler = subprocess_bundler @@ -43,7 +43,7 @@ class RubyBundlerVendorAction(BaseAction): PURPOSE = Purpose.RESOLVE_DEPENDENCIES def __init__(self, source_dir, subprocess_bundler): - super().__init__() + super(RubyBundlerVendorAction, self).__init__() self.source_dir = source_dir self.subprocess_bundler = subprocess_bundler diff --git a/aws_lambda_builders/workflows/ruby_bundler/workflow.py b/aws_lambda_builders/workflows/ruby_bundler/workflow.py index 7f85d2239..f57f6cf60 100644 --- a/aws_lambda_builders/workflows/ruby_bundler/workflow.py +++ b/aws_lambda_builders/workflows/ruby_bundler/workflow.py @@ -24,7 +24,9 @@ class RubyBundlerWorkflow(BaseWorkflow): def __init__(self, source_dir, artifacts_dir, scratch_dir, manifest_path, runtime=None, osutils=None, **kwargs): - super().__init__(source_dir, artifacts_dir, scratch_dir, manifest_path, runtime=runtime, **kwargs) + super(RubyBundlerWorkflow, self).__init__( + source_dir, artifacts_dir, scratch_dir, manifest_path, runtime=runtime, **kwargs + ) if osutils is None: osutils = OSUtils() diff --git a/tests/functional/testdata/workflows/hello_workflow/write_hello.py b/tests/functional/testdata/workflows/hello_workflow/write_hello.py index ed39efee7..a2cf94370 100644 --- a/tests/functional/testdata/workflows/hello_workflow/write_hello.py +++ b/tests/functional/testdata/workflows/hello_workflow/write_hello.py @@ -36,6 +36,6 @@ class WriteHelloWorkflow(BaseWorkflow): CAPABILITY = Capability(language="python", dependency_manager="test", application_framework="test") def __init__(self, source_dir, artifacts_dir, *args, **kwargs): - super().__init__(source_dir, artifacts_dir, *args, **kwargs) + super(WriteHelloWorkflow, self).__init__(source_dir, artifacts_dir, *args, **kwargs) self.actions = [WriteHelloAction(artifacts_dir)] diff --git a/tests/unit/test_builder.py b/tests/unit/test_builder.py index 2f2d19456..15ca779a0 100644 --- a/tests/unit/test_builder.py +++ b/tests/unit/test_builder.py @@ -84,7 +84,7 @@ def __init__( executable_search_paths=None, mode=None, ): - super().__init__( + super(MyWorkflow, self).__init__( source_dir, artifacts_dir, scratch_dir, From b51a29143ea1db5a887ed05330b22949b3b6ec16 Mon Sep 17 00:00:00 2001 From: Sam Liu Date: Tue, 27 Oct 2020 01:12:34 -0700 Subject: [PATCH 23/31] Revert "Consider explicitly re-raising using the 'from' keyword (raise-missing-from)" This reverts commit cd7c16e2ace9cd57fa2a34466713805ce3f3e850. --- aws_lambda_builders/workflow.py | 6 +++--- aws_lambda_builders/workflows/custom_make/actions.py | 4 ++-- .../workflows/dotnet_clipackage/actions.py | 6 ++---- aws_lambda_builders/workflows/go_dep/actions.py | 4 ++-- aws_lambda_builders/workflows/go_modules/actions.py | 2 +- aws_lambda_builders/workflows/java_gradle/actions.py | 6 +++--- aws_lambda_builders/workflows/java_maven/actions.py | 6 +++--- aws_lambda_builders/workflows/nodejs_npm/actions.py | 8 ++++---- aws_lambda_builders/workflows/python_pip/actions.py | 4 ++-- aws_lambda_builders/workflows/ruby_bundler/actions.py | 4 ++-- 10 files changed, 24 insertions(+), 26 deletions(-) diff --git a/aws_lambda_builders/workflow.py b/aws_lambda_builders/workflow.py index 65f548c97..42263085b 100644 --- a/aws_lambda_builders/workflow.py +++ b/aws_lambda_builders/workflow.py @@ -52,7 +52,7 @@ def wrapper(self, *args, **kwargs): else binary_checker.binary_path ) except ValueError as ex: - raise WorkflowFailedError(workflow_name=self.NAME, action_name="Resolver", reason=str(ex)) from ex + raise WorkflowFailedError(workflow_name=self.NAME, action_name="Resolver", reason=str(ex)) for executable_path in exec_paths: try: valid_path = binary_checker.validator.validate(executable_path) @@ -273,12 +273,12 @@ def run(self): except ActionFailedError as ex: LOG.debug("%s failed", action_info, exc_info=ex) - raise WorkflowFailedError(workflow_name=self.NAME, action_name=action.NAME, reason=str(ex)) from ex + raise WorkflowFailedError(workflow_name=self.NAME, action_name=action.NAME, reason=str(ex)) except Exception as ex: LOG.debug("%s raised unhandled exception", action_info, exc_info=ex) - raise WorkflowUnknownError(workflow_name=self.NAME, action_name=action.NAME, reason=str(ex)) from ex + raise WorkflowUnknownError(workflow_name=self.NAME, action_name=action.NAME, reason=str(ex)) def __repr__(self): """ diff --git a/aws_lambda_builders/workflows/custom_make/actions.py b/aws_lambda_builders/workflows/custom_make/actions.py index e16d3e835..67579a74a 100644 --- a/aws_lambda_builders/workflows/custom_make/actions.py +++ b/aws_lambda_builders/workflows/custom_make/actions.py @@ -72,7 +72,7 @@ def execute(self): try: self.manifest_check() except MakeFileNotFoundError as ex: - raise ActionFailedError(str(ex)) from ex + raise ActionFailedError(str(ex)) # Create the Artifacts Directory if it doesnt exist. if not self.osutils.exists(self.artifacts_dir): @@ -94,4 +94,4 @@ def execute(self): cwd=self.scratch_dir, ) except MakeExecutionError as ex: - raise ActionFailedError(str(ex)) from ex + raise ActionFailedError(str(ex)) diff --git a/aws_lambda_builders/workflows/dotnet_clipackage/actions.py b/aws_lambda_builders/workflows/dotnet_clipackage/actions.py index 0f37382a4..5ed686ca6 100644 --- a/aws_lambda_builders/workflows/dotnet_clipackage/actions.py +++ b/aws_lambda_builders/workflows/dotnet_clipackage/actions.py @@ -36,9 +36,7 @@ def execute(self): try: self.subprocess_dotnet.run(["tool", "update", "-g", "Amazon.Lambda.Tools", "--ignore-failed-sources"]) except DotnetCLIExecutionError as ex: - raise ActionFailedError( - "Error configuring the Amazon.Lambda.Tools .NET Core Global Tool: " + str(ex) - ) from ex + raise ActionFailedError("Error configuring the Amazon.Lambda.Tools .NET Core Global Tool: " + str(ex)) class RunPackageAction(BaseAction): @@ -85,4 +83,4 @@ def execute(self): self.os_utils.expand_zip(zipfullpath, self.artifacts_dir) except DotnetCLIExecutionError as ex: - raise ActionFailedError(str(ex)) from ex + raise ActionFailedError(str(ex)) diff --git a/aws_lambda_builders/workflows/go_dep/actions.py b/aws_lambda_builders/workflows/go_dep/actions.py index 517f0a2aa..f424e7c0b 100644 --- a/aws_lambda_builders/workflows/go_dep/actions.py +++ b/aws_lambda_builders/workflows/go_dep/actions.py @@ -33,7 +33,7 @@ def execute(self): try: self.subprocess_dep.run(["ensure"], cwd=self.base_dir) except ExecutionError as ex: - raise ActionFailedError(str(ex)) from ex + raise ActionFailedError(str(ex)) class GoBuildAction(BaseAction): @@ -63,4 +63,4 @@ def execute(self): try: self.subprocess_go.run(["build", "-o", self.output_path, self.source_path], cwd=self.source_path, env=env) except ExecutionError as ex: - raise ActionFailedError(str(ex)) from ex + raise ActionFailedError(str(ex)) diff --git a/aws_lambda_builders/workflows/go_modules/actions.py b/aws_lambda_builders/workflows/go_modules/actions.py index 785caaed9..1354a2704 100644 --- a/aws_lambda_builders/workflows/go_modules/actions.py +++ b/aws_lambda_builders/workflows/go_modules/actions.py @@ -21,4 +21,4 @@ def execute(self): try: self.builder.build(self.source_dir, self.output_path) except BuilderError as ex: - raise ActionFailedError(str(ex)) from ex + raise ActionFailedError(str(ex)) diff --git a/aws_lambda_builders/workflows/java_gradle/actions.py b/aws_lambda_builders/workflows/java_gradle/actions.py index cd8844a9c..ddf8ded9c 100644 --- a/aws_lambda_builders/workflows/java_gradle/actions.py +++ b/aws_lambda_builders/workflows/java_gradle/actions.py @@ -38,7 +38,7 @@ def _copy_init_script(self): dst = os.path.join(self.scratch_dir, self.INIT_SCRIPT) return self.os_utils.copy(src, dst) except Exception as ex: - raise ActionFailedError(str(ex)) from ex + raise ActionFailedError(str(ex)) def _build_project(self, init_script_file): try: @@ -52,7 +52,7 @@ def _build_project(self, init_script_file): {self.SCRATCH_DIR_PROPERTY: os.path.abspath(self.scratch_dir)}, ) except GradleExecutionError as ex: - raise ActionFailedError(str(ex)) from ex + raise ActionFailedError(str(ex)) class JavaGradleCopyArtifactsAction(BaseAction): @@ -76,4 +76,4 @@ def _copy_artifacts(self): self.os_utils.makedirs(self.artifacts_dir) self.os_utils.copytree(lambda_build_output, self.artifacts_dir) except Exception as ex: - raise ActionFailedError(str(ex)) from ex + raise ActionFailedError(str(ex)) diff --git a/aws_lambda_builders/workflows/java_maven/actions.py b/aws_lambda_builders/workflows/java_maven/actions.py index 8a49181b4..169459cda 100644 --- a/aws_lambda_builders/workflows/java_maven/actions.py +++ b/aws_lambda_builders/workflows/java_maven/actions.py @@ -35,7 +35,7 @@ def execute(self): try: self.subprocess_maven.build(self.scratch_dir) except MavenExecutionError as ex: - raise ActionFailedError(str(ex)) from ex + raise ActionFailedError(str(ex)) class JavaMavenCopyDependencyAction(JavaMavenBaseAction, BaseAction): @@ -52,7 +52,7 @@ def execute(self): try: self.subprocess_maven.copy_dependency(self.scratch_dir) except MavenExecutionError as ex: - raise ActionFailedError(str(ex)) from ex + raise ActionFailedError(str(ex)) class JavaMavenCopyArtifactsAction(BaseAction): @@ -80,4 +80,4 @@ def _copy_artifacts(self): if self.os_utils.exists(dependency_output): self.os_utils.copytree(dependency_output, os.path.join(self.artifacts_dir, "lib")) except Exception as ex: - raise ActionFailedError(str(ex)) from ex + raise ActionFailedError(str(ex)) diff --git a/aws_lambda_builders/workflows/nodejs_npm/actions.py b/aws_lambda_builders/workflows/nodejs_npm/actions.py index 3432dada1..43259bd8c 100644 --- a/aws_lambda_builders/workflows/nodejs_npm/actions.py +++ b/aws_lambda_builders/workflows/nodejs_npm/actions.py @@ -67,7 +67,7 @@ def execute(self): self.osutils.extract_tarfile(tarfile_path, self.artifacts_dir) except NpmExecutionError as ex: - raise ActionFailedError(str(ex)) from ex + raise ActionFailedError(str(ex)) class NodejsNpmInstallAction(BaseAction): @@ -109,7 +109,7 @@ def execute(self): ) except NpmExecutionError as ex: - raise ActionFailedError(str(ex)) from ex + raise ActionFailedError(str(ex)) class NodejsNpmrcCopyAction(BaseAction): @@ -154,7 +154,7 @@ def execute(self): self.osutils.copy_file(npmrc_path, self.artifacts_dir) except OSError as ex: - raise ActionFailedError(str(ex)) from ex + raise ActionFailedError(str(ex)) class NodejsNpmrcCleanUpAction(BaseAction): @@ -195,4 +195,4 @@ def execute(self): self.osutils.remove_file(npmrc_path) except OSError as ex: - raise ActionFailedError(str(ex)) from ex + raise ActionFailedError(str(ex)) diff --git a/aws_lambda_builders/workflows/python_pip/actions.py b/aws_lambda_builders/workflows/python_pip/actions.py index daa47b83c..f4cd225bd 100644 --- a/aws_lambda_builders/workflows/python_pip/actions.py +++ b/aws_lambda_builders/workflows/python_pip/actions.py @@ -28,7 +28,7 @@ def execute(self): try: pip = SubprocessPip(osutils=os_utils, python_exe=python_path) except MissingPipError as ex: - raise ActionFailedError(str(ex)) from ex + raise ActionFailedError(str(ex)) pip_runner = PipRunner(python_exe=python_path, pip=pip) dependency_builder = DependencyBuilder(osutils=os_utils, pip_runner=pip_runner, runtime=self.runtime) @@ -42,4 +42,4 @@ def execute(self): requirements_path=self.manifest_path, ) except PackagerError as ex: - raise ActionFailedError(str(ex)) from ex + raise ActionFailedError(str(ex)) diff --git a/aws_lambda_builders/workflows/ruby_bundler/actions.py b/aws_lambda_builders/workflows/ruby_bundler/actions.py index dc0b532d0..ffc9ad048 100644 --- a/aws_lambda_builders/workflows/ruby_bundler/actions.py +++ b/aws_lambda_builders/workflows/ruby_bundler/actions.py @@ -30,7 +30,7 @@ def execute(self): LOG.debug("Running bundle install in %s", self.source_dir) self.subprocess_bundler.run(["install", "--without", "development", "test"], cwd=self.source_dir) except BundlerExecutionError as ex: - raise ActionFailedError(str(ex)) from ex + raise ActionFailedError(str(ex)) class RubyBundlerVendorAction(BaseAction): @@ -54,4 +54,4 @@ def execute(self): ["install", "--deployment", "--without", "development", "test"], cwd=self.source_dir ) except BundlerExecutionError as ex: - raise ActionFailedError(str(ex)) from ex + raise ActionFailedError(str(ex)) From 89186de480d95ab6b81bbe5bbe2d3671cfcc1bf8 Mon Sep 17 00:00:00 2001 From: Sam Liu Date: Tue, 27 Oct 2020 01:15:34 -0700 Subject: [PATCH 24/31] Disable rules that affecting Python 2 --- .pylintrc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.pylintrc b/.pylintrc index 49589e8f5..1ad7a46d2 100644 --- a/.pylintrc +++ b/.pylintrc @@ -60,7 +60,8 @@ confidence= # no Warning level messages displayed, use"--disable=all --enable=classes # --disable=W" # R0205,W0107,R1705,R1710,R1719,R1720,R1714 are all disable due to a forced upgrade to support python3.8 -disable=R0201,W0613,I0021,I0020,W1618,W1619,R0902,R0903,W0231,W0611,R0913,W0703,C0330,R0204,I0011,R0904,C0301, R0205,W0107,R1705,R1710,R1719,R1720,R1714 +# R1725,W0707 can be removed when we drop Python 2 support +disable=R0201,W0613,I0021,I0020,W1618,W1619,R0902,R0903,W0231,W0611,R0913,W0703,C0330,R0204,I0011,R0904,C0301, R0205,W0107,R1705,R1710,R1719,R1720,R1714,R1725,W0707 [REPORTS] From 842b95e6450fc208b461cdb27c39befd778b29d8 Mon Sep 17 00:00:00 2001 From: _sam <3804518+aahung@users.noreply.github.com> Date: Wed, 28 Oct 2020 17:06:54 -0700 Subject: [PATCH 25/31] Manage black version using requirement file (#207) * chore: Manage black version in dev.txt * chore: Update appveyor, use black in pip * chore: Add pre-commit-config * chore: Format with black 20.8b1 * chore: Add make pr2.7 for Python 2 that does not run black --- .appveyor.yml | 9 ++------- .pre-commit-config.yaml | 9 +++++++++ Makefile | 3 +++ requirements/dev.txt | 4 ++++ tests/functional/workflows/provided_make/test_utils.py | 6 +++++- tests/unit/test_builder.py | 3 +-- 6 files changed, 24 insertions(+), 10 deletions(-) create mode 100644 .pre-commit-config.yaml diff --git a/.appveyor.yml b/.appveyor.yml index 5e1b18f48..1f3a0023b 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -103,11 +103,6 @@ for: - sh: "sudo unzip -d /opt/gradle /tmp/gradle-*.zip" - sh: "PATH=/opt/gradle/gradle-5.5/bin:$PATH" - # Install black - - sh: "wget -O /tmp/black https://github.com/python/black/releases/download/19.10b0/black" - - sh: "chmod +x /tmp/black" - - sh: "/tmp/black --version" - build_script: - "python -c \"import sys; print(sys.executable)\"" - "LAMBDA_BUILDERS_DEV=1 pip install -e \".[dev]\"" @@ -119,5 +114,5 @@ for: # Runs only in Linux - "LAMBDA_BUILDERS_DEV=1 pytest -vv tests/integration" - # Validate Code was formatted with Black - - "/tmp/black --check setup.py tests aws_lambda_builders" + # Validate Code was formatted with Black, black is only supported in Python 3 + - if [[ $PYTHON_VERSION = "3"* ]]; then black --check setup.py tests aws_lambda_builders; fi diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 000000000..ba9847ef0 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,9 @@ +# black is in dev.txt, so local repo is used here. +repos: +- repo: local + hooks: + - id: black + name: black + entry: black + language: system + types: [python] diff --git a/Makefile b/Makefile index 883aba1b1..30721f517 100644 --- a/Makefile +++ b/Makefile @@ -28,3 +28,6 @@ black-check: # Verifications to run before sending a pull request pr: init dev black-check + +# Verifications to run before sending a pull request, skipping black check because black requires Python 3.6+ +pr2.7: init dev diff --git a/requirements/dev.txt b/requirements/dev.txt index 86f7affde..c4ca79eef 100644 --- a/requirements/dev.txt +++ b/requirements/dev.txt @@ -20,3 +20,7 @@ futures==3.2.0; python_version<"3.2.3" # tempfile backport for < 3.6 backports.tempfile==1.0; python_version<"3.7" + + +# formatter +black==20.8b1; python_version >= '3.6' \ No newline at end of file diff --git a/tests/functional/workflows/provided_make/test_utils.py b/tests/functional/workflows/provided_make/test_utils.py index 103a244ff..ad78e8d44 100644 --- a/tests/functional/workflows/provided_make/test_utils.py +++ b/tests/functional/workflows/provided_make/test_utils.py @@ -30,7 +30,11 @@ def test_popen_can_accept_cwd_and_env(self): env.update({"SOME_ENV": "SOME_VALUE"}) p = self.osutils.popen( - [sys.executable, "cwd.py"], stdout=self.osutils.pipe, stderr=self.osutils.pipe, env=env, cwd=testdata_dir, + [sys.executable, "cwd.py"], + stdout=self.osutils.pipe, + stderr=self.osutils.pipe, + env=env, + cwd=testdata_dir, ) out, err = p.communicate() diff --git a/tests/unit/test_builder.py b/tests/unit/test_builder.py index 15ca779a0..08148158c 100644 --- a/tests/unit/test_builder.py +++ b/tests/unit/test_builder.py @@ -62,8 +62,7 @@ def test_must_not_load_any_workflows(self, get_workflow_mock, importlib_mock): importlib_mock.import_module.assert_not_called() def test_with_real_workflow_class(self): - """Define a real workflow class and try to fetch it. This ensures the workflow registration actually works. - """ + """Define a real workflow class and try to fetch it. This ensures the workflow registration actually works.""" # Declare my test workflow. class MyWorkflow(BaseWorkflow): From 39aa5839afb636b29b29afb5383068a47ea00ec4 Mon Sep 17 00:00:00 2001 From: _sam <3804518+aahung@users.noreply.github.com> Date: Tue, 1 Dec 2020 16:36:47 -0800 Subject: [PATCH 26/31] chore: Remove python patch version in AppVeyor to be more robust (#213) --- .appveyor.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.appveyor.yml b/.appveyor.yml index 1f3a0023b..5a96546ad 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -12,25 +12,25 @@ environment: matrix: - PYTHON: "C:\\Python27-x64" - PYTHON_VERSION: '2.7.18' + PYTHON_VERSION: '2.7' PYTHON_ARCH: '64' LINE_COVERAGE: '91' NEW_FLAKE8: 0 JAVA_HOME: "C:\\Program Files\\Java\\jdk11" - PYTHON: "C:\\Python36-x64" - PYTHON_VERSION: '3.6.10' + PYTHON_VERSION: '3.6' PYTHON_ARCH: '64' LINE_COVERAGE: '91' NEW_FLAKE8: 0 JAVA_HOME: "C:\\Program Files\\Java\\jdk11" - PYTHON: "C:\\Python37-x64" - PYTHON_VERSION: '3.7.7' + PYTHON_VERSION: '3.7' PYTHON_ARCH: '64' LINE_COVERAGE: '91' NEW_FLAKE8: 0 JAVA_HOME: "C:\\Program Files\\Java\\jdk11" - PYTHON: "C:\\Python38-x64" - PYTHON_VERSION: '3.8.2' + PYTHON_VERSION: '3.8' PYTHON_ARCH: '64' LINE_COVERAGE: '72' NEW_FLAKE8: 1 From 6ef145bd0d29dd508b83b62a11908b25335be73b Mon Sep 17 00:00:00 2001 From: _sam <3804518+aahung@users.noreply.github.com> Date: Wed, 2 Dec 2020 16:32:41 -0800 Subject: [PATCH 27/31] chore: Remove biased language (#212) --- .pylintrc | 2 +- aws_lambda_builders/workflows/custom_make/DESIGN.md | 2 +- aws_lambda_builders/workflows/python_pip/packager.py | 12 ++++++------ .../functional/workflows/python_pip/test_packager.py | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/.pylintrc b/.pylintrc index 1ad7a46d2..a17cf8491 100644 --- a/.pylintrc +++ b/.pylintrc @@ -7,7 +7,7 @@ # pygtk.require(). #init-hook= -# Add files or directories to the blacklist. They should be base names, not +# Add files or directories to the ignore list. They should be base names, not # paths. ignore=compat.py, utils.py diff --git a/aws_lambda_builders/workflows/custom_make/DESIGN.md b/aws_lambda_builders/workflows/custom_make/DESIGN.md index 4cf2e9e48..7c4403028 100644 --- a/aws_lambda_builders/workflows/custom_make/DESIGN.md +++ b/aws_lambda_builders/workflows/custom_make/DESIGN.md @@ -63,7 +63,7 @@ It is then the responsibility of the make target to make sure the artifacts are * We only care about certain build targets. so essentially this is a pluggable builder, but nothing beyond that at this point in time. * Which environment variables are usable in this makefile? - * There are a series of whitelisted environment variables that need to be defined and not be overriden within the Makefile to work. Currently that is just `$ARTIFACTS_DIR` + * There are a series of allowlisted environment variables that need to be defined and not be overridden within the Makefile to work. Currently that is just `$ARTIFACTS_DIR` * Can this be used even for runtimes that have builders associated with it? eg: python3.8? * Possibly, some changes would be needed be made to way the corresponding builder is picked up in sam cli. If we changed it such that there is a makefile we pick a makefile builder and if not fall back to the specified language builder. diff --git a/aws_lambda_builders/workflows/python_pip/packager.py b/aws_lambda_builders/workflows/python_pip/packager.py index 87abb7765..17cde15bd 100644 --- a/aws_lambda_builders/workflows/python_pip/packager.py +++ b/aws_lambda_builders/workflows/python_pip/packager.py @@ -157,7 +157,7 @@ class DependencyBuilder(object): "manylinux2010_x86_64", "manylinux2014_x86_64", } - _COMPATIBLE_PACKAGE_WHITELIST = {"sqlalchemy"} + _COMPATIBLE_PACKAGE_ALLOWLIST = {"sqlalchemy"} def __init__(self, osutils, runtime, pip_runner=None): """Initialize a DependencyBuilder. @@ -291,9 +291,9 @@ def _download_dependencies(self, directory, requirements_filename): # Now there is still the case left over where the setup.py has been # made in such a way to be incompatible with python's setup tools, # causing it to lie about its compatibility. To fix this we have a - # manually curated whitelist of packages that will work, despite + # manually curated allowlist of packages that will work, despite # claiming otherwise. - compatible_wheels, incompatible_wheels = self._apply_wheel_whitelist(compatible_wheels, incompatible_wheels) + compatible_wheels, incompatible_wheels = self._apply_wheel_allowlist(compatible_wheels, incompatible_wheels) missing_wheels = deps - compatible_wheels LOG.debug("Final compatible: %s", compatible_wheels) LOG.debug("Final incompatible: %s", incompatible_wheels) @@ -305,7 +305,7 @@ def _download_all_dependencies(self, requirements_filename, directory): # Download dependencies prefering wheel files but falling back to # raw source dependences to get the transitive closure over # the dependency graph. Return the set of all package objects - # which will serve as the master list of dependencies needed to deploy + # which will serve as the primary list of dependencies needed to deploy # successfully. self._pip.download_all_dependencies(requirements_filename, directory) deps = {Package(directory, filename) for filename in self._osutils.get_directory_contents(directory)} @@ -365,11 +365,11 @@ def _is_compatible_wheel_filename(self, filename): # Don't know what we have but it didn't pass compatibility tests. return False - def _apply_wheel_whitelist(self, compatible_wheels, incompatible_wheels): + def _apply_wheel_allowlist(self, compatible_wheels, incompatible_wheels): compatible_wheels = set(compatible_wheels) actual_incompatible_wheels = set() for missing_package in incompatible_wheels: - if missing_package.name in self._COMPATIBLE_PACKAGE_WHITELIST: + if missing_package.name in self._COMPATIBLE_PACKAGE_ALLOWLIST: compatible_wheels.add(missing_package) else: actual_incompatible_wheels.add(missing_package) diff --git a/tests/functional/workflows/python_pip/test_packager.py b/tests/functional/workflows/python_pip/test_packager.py index 03a2c1b8f..8bf727327 100644 --- a/tests/functional/workflows/python_pip/test_packager.py +++ b/tests/functional/workflows/python_pip/test_packager.py @@ -575,7 +575,7 @@ def test_can_replace_incompat_whl(self, tmpdir, osutils, pip_runner): for req in reqs: assert req in installed_packages - def test_whitelist_sqlalchemy(self, tmpdir, osutils, pip_runner): + def test_allowlist_sqlalchemy(self, tmpdir, osutils, pip_runner): reqs = ["sqlalchemy==1.1.18"] pip, runner = pip_runner appdir, builder = self._make_appdir_and_dependency_builder(reqs, tmpdir, runner) From 1a7ac1908ede129acde746634d4d25115ce2406d Mon Sep 17 00:00:00 2001 From: Mehmet Nuri Deveci <5735811+mndeveci@users.noreply.github.com> Date: Thu, 10 Dec 2020 16:05:50 -0800 Subject: [PATCH 28/31] fix: run GlobalToolInstallAction in a lock block and only once (#214) * fix: run GlobalToolInstallAction in a lock block and only once * chore: change field name and update unit tests * chore: black formatting * fix: change tests to use threadpool for py2 * chore: update assert call and change usage of Executor --- .../workflows/dotnet_clipackage/actions.py | 32 +++++++++++++++---- .../dotnet_clipackage/test_actions.py | 18 +++++++++++ 2 files changed, 43 insertions(+), 7 deletions(-) diff --git a/aws_lambda_builders/workflows/dotnet_clipackage/actions.py b/aws_lambda_builders/workflows/dotnet_clipackage/actions.py index 5ed686ca6..de7386d04 100644 --- a/aws_lambda_builders/workflows/dotnet_clipackage/actions.py +++ b/aws_lambda_builders/workflows/dotnet_clipackage/actions.py @@ -2,6 +2,7 @@ Actions for .NET dependency resolution with CLI Package """ +import threading import os import logging @@ -14,6 +15,8 @@ class GlobalToolInstallAction(BaseAction): + __lock = threading.Lock() + __tools_installed = False """ A Lambda Builder Action which installs the Amazon.Lambda.Tools .NET Core Global Tool @@ -28,15 +31,30 @@ def __init__(self, subprocess_dotnet): self.subprocess_dotnet = subprocess_dotnet def execute(self): - try: - LOG.debug("Installing Amazon.Lambda.Tools Global Tool") - self.subprocess_dotnet.run(["tool", "install", "-g", "Amazon.Lambda.Tools", "--ignore-failed-sources"]) - except DotnetCLIExecutionError as ex: - LOG.debug("Error installing probably due to already installed. Attempt to update to latest version.") + # run Amazon.Lambda.Tools update in sync block in case build is triggered in parallel + with GlobalToolInstallAction.__lock: + LOG.debug("Entered synchronized block for updating Amazon.Lambda.Tools") + + # check if Amazon.Lambda.Tools updated recently + if GlobalToolInstallAction.__tools_installed: + LOG.info("Skipping to update Amazon.Lambda.Tools install/update, since it is updated recently") + return + try: - self.subprocess_dotnet.run(["tool", "update", "-g", "Amazon.Lambda.Tools", "--ignore-failed-sources"]) + LOG.debug("Installing Amazon.Lambda.Tools Global Tool") + self.subprocess_dotnet.run(["tool", "install", "-g", "Amazon.Lambda.Tools", "--ignore-failed-sources"]) + GlobalToolInstallAction.__tools_installed = True except DotnetCLIExecutionError as ex: - raise ActionFailedError("Error configuring the Amazon.Lambda.Tools .NET Core Global Tool: " + str(ex)) + LOG.debug("Error installing probably due to already installed. Attempt to update to latest version.") + try: + self.subprocess_dotnet.run( + ["tool", "update", "-g", "Amazon.Lambda.Tools", "--ignore-failed-sources"] + ) + GlobalToolInstallAction.__tools_installed = True + except DotnetCLIExecutionError as ex: + raise ActionFailedError( + "Error configuring the Amazon.Lambda.Tools .NET Core Global Tool: " + str(ex) + ) class RunPackageAction(BaseAction): diff --git a/tests/unit/workflows/dotnet_clipackage/test_actions.py b/tests/unit/workflows/dotnet_clipackage/test_actions.py index 8b7688661..1df2694a3 100644 --- a/tests/unit/workflows/dotnet_clipackage/test_actions.py +++ b/tests/unit/workflows/dotnet_clipackage/test_actions.py @@ -1,4 +1,6 @@ from unittest import TestCase + +from concurrent.futures import ThreadPoolExecutor from mock import patch import os import platform @@ -8,6 +10,7 @@ from aws_lambda_builders.workflows.dotnet_clipackage.actions import GlobalToolInstallAction, RunPackageAction +@patch.object(GlobalToolInstallAction, "_GlobalToolInstallAction__tools_installed", False) class TestGlobalToolInstallAction(TestCase): @patch("aws_lambda_builders.workflows.dotnet_clipackage.dotnetcli.SubprocessDotnetCLI") def setUp(self, MockSubprocessDotnetCLI): @@ -42,6 +45,21 @@ def test_global_tool_update_failed(self): action = GlobalToolInstallAction(self.subprocess_dotnet) self.assertRaises(ActionFailedError, action.execute) + def test_global_tool_parallel(self): + actions = [ + GlobalToolInstallAction(self.subprocess_dotnet), + GlobalToolInstallAction(self.subprocess_dotnet), + GlobalToolInstallAction(self.subprocess_dotnet), + ] + + with ThreadPoolExecutor() as executor: + for action in actions: + executor.submit(action.execute) + + self.subprocess_dotnet.run.assert_called_once_with( + ["tool", "install", "-g", "Amazon.Lambda.Tools", "--ignore-failed-sources"] + ) + class TestRunPackageAction(TestCase): @patch("aws_lambda_builders.workflows.dotnet_clipackage.dotnetcli.SubprocessDotnetCLI") From bc2a0fef134c9b41043e54068a196158d69e2766 Mon Sep 17 00:00:00 2001 From: Mehmet Nuri Deveci <5735811+mndeveci@users.noreply.github.com> Date: Tue, 5 Jan 2021 14:30:04 -0800 Subject: [PATCH 29/31] chore: bump version to 1.2.0 (#218) --- aws_lambda_builders/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aws_lambda_builders/__init__.py b/aws_lambda_builders/__init__.py index 50f740c9d..32b058c3a 100644 --- a/aws_lambda_builders/__init__.py +++ b/aws_lambda_builders/__init__.py @@ -1,5 +1,5 @@ """ AWS Lambda Builder Library """ -__version__ = "1.1.0" +__version__ = "1.2.0" RPC_PROTOCOL_VERSION = "0.3" From 33179b7b053d1aa8c5114a103ef5880c9844b63b Mon Sep 17 00:00:00 2001 From: Cosh_ Date: Mon, 22 Feb 2021 15:17:40 -0800 Subject: [PATCH 30/31] fix: Python Workflow with Incorrect Environ (#223) * Added original_environ * Added Missing Return * Added Missing env in pip_import_string * Reformatted with Black * Added refreshenv to Windows jobs * Updated Default Go Installation Directory * Added GOROOT * Removed refreshenv * Updated PATH * Pinning down golang version * Updated original_environ to only Patch on Linux * Updated Check from Linux to PyInstaller Only * Added Comment for PyInstaller Check --- .appveyor.yml | 2 +- .../workflows/python_pip/compat.py | 2 +- .../workflows/python_pip/packager.py | 6 ++++-- .../workflows/python_pip/utils.py | 17 +++++++++++++++++ .../workflows/python_pip/validator.py | 5 ++++- 5 files changed, 27 insertions(+), 5 deletions(-) diff --git a/.appveyor.yml b/.appveyor.yml index 5a96546ad..808e7951a 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -60,7 +60,7 @@ for: # setup go - rmdir c:\go /s /q - - "choco install golang" + - "choco install golang --version 1.15.7" - "choco install bzr" - "choco install dep" - setx PATH "C:\go\bin;C:\gopath\bin;C:\Program Files (x86)\Bazaar\;C:\Program Files\Mercurial;%PATH%;" diff --git a/aws_lambda_builders/workflows/python_pip/compat.py b/aws_lambda_builders/workflows/python_pip/compat.py index 51389b7d0..9e83494e4 100644 --- a/aws_lambda_builders/workflows/python_pip/compat.py +++ b/aws_lambda_builders/workflows/python_pip/compat.py @@ -7,7 +7,7 @@ def pip_import_string(python_exe): os_utils = OSUtils() cmd = [python_exe, "-c", "import pip; print(pip.__version__)"] - p = os_utils.popen(cmd, stdout=os_utils.pipe, stderr=os_utils.pipe) + p = os_utils.popen(cmd, stdout=os_utils.pipe, stderr=os_utils.pipe, env=os_utils.original_environ()) stdout, stderr = p.communicate() if not p.returncode == 0: raise MissingPipError(python_path=python_exe) diff --git a/aws_lambda_builders/workflows/python_pip/packager.py b/aws_lambda_builders/workflows/python_pip/packager.py index 17cde15bd..241b49630 100644 --- a/aws_lambda_builders/workflows/python_pip/packager.py +++ b/aws_lambda_builders/workflows/python_pip/packager.py @@ -494,7 +494,9 @@ def _generate_egg_info(self, package_dir): cmd = [sys.executable, "-c", script, "--no-user-cfg", "egg_info", "--egg-base", "egg-info"] egg_info_dir = self._osutils.joinpath(package_dir, "egg-info") self._osutils.makedirs(egg_info_dir) - p = subprocess.Popen(cmd, cwd=package_dir, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + p = subprocess.Popen( + cmd, cwd=package_dir, stdout=subprocess.PIPE, stderr=subprocess.PIPE, env=self._osutils.original_environ() + ) p.communicate() info_contents = self._osutils.get_directory_contents(egg_info_dir) pkg_info_path = self._osutils.joinpath(egg_info_dir, info_contents[0], "PKG-INFO") @@ -535,7 +537,7 @@ def __init__(self, osutils=None, python_exe=None, import_string=None): def main(self, args, env_vars=None, shim=None): if env_vars is None: - env_vars = self._osutils.environ() + env_vars = self._osutils.original_environ() if shim is None: shim = "" run_pip = ("import sys; %s; sys.exit(main(%s))") % (self._import_string, args) diff --git a/aws_lambda_builders/workflows/python_pip/utils.py b/aws_lambda_builders/workflows/python_pip/utils.py index 6c5afc73a..eab58bda4 100644 --- a/aws_lambda_builders/workflows/python_pip/utils.py +++ b/aws_lambda_builders/workflows/python_pip/utils.py @@ -10,12 +10,29 @@ import shutil import tarfile import subprocess +import sys class OSUtils(object): def environ(self): return os.environ + def original_environ(self): + # https://pyinstaller.readthedocs.io/en/stable/runtime-information.html#ld-library-path-libpath-considerations + env = dict(os.environ) + # Check whether running as a PyInstaller binary + if getattr(sys, "frozen", False) and hasattr(sys, "_MEIPASS"): + lp_key = "LD_LIBRARY_PATH" + original_lp = env.get(lp_key + "_ORIG") + if original_lp is not None: + env[lp_key] = original_lp + else: + # This happens when LD_LIBRARY_PATH was not set. + # Remove the env var as a last resort: + env.pop(lp_key, None) + + return env + def file_exists(self, filename): return os.path.isfile(filename) diff --git a/aws_lambda_builders/workflows/python_pip/validator.py b/aws_lambda_builders/workflows/python_pip/validator.py index f0a1c06b1..0032181a1 100644 --- a/aws_lambda_builders/workflows/python_pip/validator.py +++ b/aws_lambda_builders/workflows/python_pip/validator.py @@ -7,6 +7,7 @@ import subprocess from aws_lambda_builders.exceptions import MisMatchRuntimeError +from .utils import OSUtils LOG = logging.getLogger(__name__) @@ -39,7 +40,9 @@ def validate(self, runtime_path): cmd = self._validate_python_cmd(runtime_path) - p = subprocess.Popen(cmd, cwd=os.getcwd(), stdout=subprocess.PIPE, stderr=subprocess.PIPE) + p = subprocess.Popen( + cmd, cwd=os.getcwd(), stdout=subprocess.PIPE, stderr=subprocess.PIPE, env=OSUtils().original_environ() + ) p.communicate() if p.returncode != 0: raise MisMatchRuntimeError(language=self.language, required_runtime=self.runtime, runtime_path=runtime_path) From 692fd7cd8bf6bda5715bb13bcb90daa2fd56f5ae Mon Sep 17 00:00:00 2001 From: Mehmet Nuri Deveci <5735811+mndeveci@users.noreply.github.com> Date: Thu, 25 Feb 2021 09:14:14 -0800 Subject: [PATCH 31/31] chore: bump lambda builders version to 1.3.0 (#225) --- aws_lambda_builders/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aws_lambda_builders/__init__.py b/aws_lambda_builders/__init__.py index 32b058c3a..27fb27380 100644 --- a/aws_lambda_builders/__init__.py +++ b/aws_lambda_builders/__init__.py @@ -1,5 +1,5 @@ """ AWS Lambda Builder Library """ -__version__ = "1.2.0" +__version__ = "1.3.0" RPC_PROTOCOL_VERSION = "0.3"