Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

drop Python 3.7 and update pre-commit hooks #42

Merged
merged 1 commit into from
Nov 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,17 @@ name: PR
on:
pull_request:

permissions: read-all
permissions:
contents: read

env:
MIN_PYTHON_VERSION: "3.7"
MIN_PYTHON_VERSION: "3.8"

jobs:
pre-commit:
uses: bridgecrewio/gha-reusable-workflows/.github/workflows/pre-commit.yaml@main
with:
python-version: "3.8"

tests:
needs: pre-commit
Expand All @@ -19,7 +22,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12"]
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
fail-fast: false
steps:
- uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0
Expand Down
5 changes: 3 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ on:
- ".pre-commit-config.yaml"
- ".github/**"

permissions: read-all
permissions:
contents: read

env:
MIN_PYTHON_VERSION: "3.7"
MIN_PYTHON_VERSION: "3.8"

jobs:
tests:
Expand Down
8 changes: 4 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
rev: v4.5.0
hooks:
- id: check-json
- id: check-toml
Expand All @@ -11,16 +11,16 @@ repos:
args: ["--django"]
- id: trailing-whitespace
- repo: https://github.com/psf/black
rev: 22.12.0
rev: 23.11.0
hooks:
- id: black
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.0.242
rev: v0.1.6
hooks:
- id: ruff
args:
- --fix
- repo: https://github.com/rhysd/actionlint
rev: v1.6.23
rev: v1.6.26
hooks:
- id: actionlint-docker
2 changes: 1 addition & 1 deletion bc_jsonpath_ng/__version__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "1.5.9"
__version__ = "1.6.0"
2 changes: 1 addition & 1 deletion bc_jsonpath_ng/ext/filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def find(self, datum):
]

def update(self, data, val):
if type(data) is list:
if isinstance(data, list):
for index, item in enumerate(data):
should_update = len(self.expressions) == len(list(filter(lambda x: x.find(item), self.expressions)))
if should_update:
Expand Down
2 changes: 1 addition & 1 deletion bc_jsonpath_ng/ext/iterable.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def find(self, datum):
if isinstance(datum.value, dict) and self.expressions:
return datum

if isinstance(datum.value, dict) or isinstance(datum.value, list):
if isinstance(datum.value, (dict, list)):
key = functools.cmp_to_key(self._compare) if self.expressions else None
return [DatumInContext.wrap(sorted(datum.value, key=key))]
return datum
Expand Down
6 changes: 2 additions & 4 deletions bc_jsonpath_ng/ext/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class ExtendedJsonPathLexer(lexer.JsonPathLexer):
"""Custom LALR-lexer for JsonPath"""

literals = [*lexer.JsonPathLexer.literals, "?", "@", "+", "*", "/", "-", "!"]
tokens = ["BOOL", *parser.JsonPathLexer.tokens] + ["FILTER_OP", "SORT_DIRECTION", "FLOAT"]
tokens = ["BOOL", *parser.JsonPathLexer.tokens, "FILTER_OP", "SORT_DIRECTION", "FLOAT"]

t_FILTER_OP = r"=~|==?|<=|>=|!=|<|>" # noqa: N815

Expand Down Expand Up @@ -173,9 +173,7 @@ def p_jsonpath_negate(self, p):
"jsonpath : '!' expressions"
p[0] = _filter.Negate(p[2])

precedence = [("left", "+", "-"), ("left", "*", "/"), *parser.JsonPathParser.precedence] + [
("nonassoc", "ID"),
]
precedence = [("left", "+", "-"), ("left", "*", "/"), *parser.JsonPathParser.precedence, ("nonassoc", "ID")]


def parse(path: str, debug: bool = False) -> JSONPath:
Expand Down
12 changes: 4 additions & 8 deletions bc_jsonpath_ng/lexer.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,7 @@ def t_singlequote_end(self, t):

def t_singlequote_error(self, t):
raise JsonPathLexerError(
"Error on line %s, col %s while lexing singlequoted field: Unexpected character: %s "
% (t.lexer.lineno, t.lexpos - t.lexer.latest_newline, t.value[0])
f"Error on line {t.lexer.lineno}, col {t.lexpos - t.lexer.latest_newline} while lexing singlequoted field: Unexpected character: {t.value[0]} "
)

# Double-quoted strings
Expand Down Expand Up @@ -132,8 +131,7 @@ def t_doublequote_end(self, t):

def t_doublequote_error(self, t):
raise JsonPathLexerError(
"Error on line %s, col %s while lexing doublequoted field: Unexpected character: %s "
% (t.lexer.lineno, t.lexpos - t.lexer.latest_newline, t.value[0])
f"Error on line {t.lexer.lineno}, col {t.lexpos - t.lexer.latest_newline} while lexing doublequoted field: Unexpected character: {t.value[0]} "
)

# Back-quoted "magic" operators
Expand Down Expand Up @@ -163,8 +161,7 @@ def t_backquote_end(self, t):

def t_backquote_error(self, t):
raise JsonPathLexerError(
"Error on line %s, col %s while lexing backquoted operator: Unexpected character: %s "
% (t.lexer.lineno, t.lexpos - t.lexer.latest_newline, t.value[0])
f"Error on line {t.lexer.lineno}, col {t.lexpos - t.lexer.latest_newline} while lexing backquoted operator: Unexpected character: {t.value[0]} "
)

# Counting lines, handling errors
Expand All @@ -175,8 +172,7 @@ def t_newline(self, t):

def t_error(self, t):
raise JsonPathLexerError(
"Error on line %s, col %s: Unexpected character: %s "
% (t.lexer.lineno, t.lexpos - t.lexer.latest_newline, t.value[0])
f"Error on line {t.lexer.lineno}, col {t.lexpos - t.lexer.latest_newline}: Unexpected character: {t.value[0]} "
)


Expand Down
1 change: 0 additions & 1 deletion bc_jsonpath_ng/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ def parse(self, string: str, lexer: JsonPathLexer | None = None) -> JSONPath:
return self.parse_token_stream(lexer.tokenize(string))

def parse_token_stream(self, token_iterator, start_symbol: str = "jsonpath"):

# Since PLY has some crufty aspects and dumps files, we try to keep them local
# However, we need to derive the name of the output Python file :-/
output_directory = os.path.dirname(__file__)
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ select = [
exclude = [
"tests" # exclude for now
]
ignore = ["ARG002", "E501"]
ignore = ["ARG002", "E501", "RUF012"]
per-file-ignores = { "tests/**/*" = ["S101"] }

target-version = "py37"
3 changes: 1 addition & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def get_version():
setuptools.setup(
name="bc-jsonpath-ng",
version=get_version(),
python_requires=">=3.7",
python_requires=">=3.8",
description=(
"A final implementation of JSONPath for Python that aims to be "
"standard compliant, including arithmetic and binary comparison "
Expand Down Expand Up @@ -46,7 +46,6 @@ def get_version():
"Operating System :: OS Independent",
"Programming Language :: Python",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
Expand Down
2 changes: 0 additions & 2 deletions tests/test_jsonpath.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ def setup_class(cls):
logging.basicConfig()

def test_DatumInContext_init(self): # noqa: N802

test_datum1 = DatumInContext(3)
assert test_datum1.path == This()
assert test_datum1.full_path == This()
Expand All @@ -39,7 +38,6 @@ def test_DatumInContext_init(self): # noqa: N802
assert test_datum3.full_path == Fields("baz").child(Fields("foo"))

def test_DatumInContext_in_context(self):

assert DatumInContext(3).in_context(path=Fields("foo"), context=DatumInContext("whatever")) == DatumInContext(
3, path=Fields("foo"), context=DatumInContext("whatever")
)
Expand Down