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/__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" 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) 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",