Skip to content

Commit

Permalink
Update xoto3.lam.finalize for Python >3.7 (#31)
Browse files Browse the repository at this point in the history
* Python-agnostic finalize hook implementation based on awslambdaric version

* 1.16.1
  • Loading branch information
xaviergmail authored Aug 23, 2022
1 parent 938f2a5 commit 6d33afc
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 11 deletions.
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
### 1.16.1

- Fix xoto3.lam.finalize for Python > 3.7

## 1.16.0

- `write_item` single item write helper for the `write_versioned`
Expand Down
7 changes: 3 additions & 4 deletions scripts/pylint_pipenv_score_limit.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
#!/usr/bin/env python
import argparse
import os
import sys
import subprocess

from pylint import lint
import sys

from pipenv_utils import get_pythonpath_for_pipfile_dir_and_venv
from pylint import lint


def module_passes_lint_score_limit(path, limit, other_args=()) -> bool:
run = lint.Run([path, *other_args], do_exit=False)
score = run.linter.stats.get("global_note", -1.0)
score = run.linter.stats.global_note

if score < limit:
print(f"Score for {path} was {score:.03f}; less than limit {limit}")
Expand Down
2 changes: 1 addition & 1 deletion xoto3/__about__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""xoto3"""
__version__ = "1.16.0"
__version__ = "1.16.1"
__author__ = "Peter Gaultney"
__author_email__ = "[email protected]"
31 changes: 25 additions & 6 deletions xoto3/lam/finalize.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
"""By importing this module, you request an attempt to set up an empty
array of post-runtime hooks for your Lambda."""
import typing as ty
import sys
import typing as ty
from logging import getLogger

from xoto3.utils.env import is_aws_env


logger = getLogger(__name__)

_POST_INVOCATION_RESULT_THUNKS = list()
Expand Down Expand Up @@ -44,9 +43,7 @@ def _noop(*_args, **_kwargs):
pass


def __py37_finalize_hook():
import bootstrap as aws_lambda_bootstrap # pylint: disable=import-outside-toplevel

def __install_post_invocation_hooks(aws_lambda_bootstrap):
aws_lambda_bootstrap.LambdaRuntimeClient.post_invocation_result = _run_thunks_before_function(
_POST_INVOCATION_RESULT_THUNKS
)(aws_lambda_bootstrap.LambdaRuntimeClient.post_invocation_result)
Expand All @@ -67,8 +64,30 @@ def __setup_lambda_finalize_hook():
return

try:
aws_lambda_bootstrap = None
if sys.version_info[0] == 3 and sys.version_info[1] == 7:
__py37_finalize_hook()
import bootstrap as _aws_lambda_bootstrap # pylint: disable=import-outside-toplevel,import-error

aws_lambda_bootstrap = _aws_lambda_bootstrap
else:
try:
from awslambdaric import __version__ # pylint: disable=import-outside-toplevel

if __version__.split(".")[0] == "2":
import awslambdaric.bootstrap as _aws_lambda_bootstrap # pylint: disable=import-outside-toplevel,import-error

aws_lambda_bootstrap = _aws_lambda_bootstrap
else:
logger.error(
f"Unimplemented for version of AWS Lambda Runtime Interface Client: {__version__}"
)
except ImportError:
logger.error(
"Failed to import awslambdaric. A new implementation might be needed for this runtime."
)

if aws_lambda_bootstrap is not None:
__install_post_invocation_hooks(aws_lambda_bootstrap)
else:
logger.error(
f"No Python-version-compatible Lambda Runtime hook implementation is available for {sys.version_info}"
Expand Down

0 comments on commit 6d33afc

Please sign in to comment.