Skip to content

Commit acc3b83

Browse files
committed
improv: make jmespath an official project dep
1 parent 1d21135 commit acc3b83

File tree

3 files changed

+14
-23
lines changed

3 files changed

+14
-23
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,15 @@
1-
import json
21
import logging
32
from typing import Dict
43

54
import fastjsonschema
5+
import jmespath
6+
from jmespath.exceptions import LexerError
67

78
from .exceptions import InvalidEnvelopeExpressionError, InvalidSchemaError, SchemaValidationError
9+
from .jmespath_functions import PowertoolsJson
810

911
logger = logging.getLogger(__name__)
1012

11-
try:
12-
import jmespath
13-
14-
class PowertoolsJson(jmespath.functions.Functions):
15-
@jmespath.functions.signature({"types": ["string"]})
16-
def _func_powertools_json(self, value):
17-
return json.loads(value)
18-
19-
20-
except ModuleNotFoundError:
21-
jmespath = None
22-
2313

2414
def validate_data_against_schema(data: Dict, schema: Dict):
2515
try:
@@ -32,14 +22,11 @@ def validate_data_against_schema(data: Dict, schema: Dict):
3222

3323

3424
def unwrap_event_from_envelope(data: Dict, envelope: str, jmespath_options: Dict):
35-
if not jmespath:
36-
raise ModuleNotFoundError("This feature require aws-lambda-powertools[jmespath] extra package")
37-
3825
if not jmespath_options:
3926
jmespath_options = {"custom_functions": PowertoolsJson()}
4027

4128
try:
4229
logger.debug(f"Envelope detected: {envelope}. JMESPath options: {jmespath_options}")
4330
return jmespath.search(envelope, data, options=jmespath.Options(**jmespath_options))
44-
except jmespath.exceptions.LexerError as e:
31+
except LexerError as e:
4532
raise InvalidEnvelopeExpressionError(e)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import json
2+
3+
import jmespath
4+
5+
6+
class PowertoolsJson(jmespath.functions.Functions):
7+
@jmespath.functions.signature({"types": ["string"]})
8+
def _func_powertools_json(self, value):
9+
return json.loads(value)

pyproject.toml

+1-6
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,7 @@ python = "^3.6"
2222
aws-xray-sdk = "^2.5.0"
2323
fastjsonschema = "^2.14.5"
2424
boto3 = "^1.12"
25-
26-
# optional dependency to allow envelope feature in validator utility
27-
jmespath = {version = "^0.10.0", optional = true }
28-
29-
[tool.poetry.extras]
30-
jmespath = ["jmespath"]
25+
jmespath = "^0.10.0"
3126

3227
[tool.poetry.dev-dependencies]
3328
coverage = {extras = ["toml"], version = "^5.0.3"}

0 commit comments

Comments
 (0)