diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index f74d9bd..943987c 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -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 @@ -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 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 148869f..e3b3e61 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -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: diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index fd62019..07b3bde 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -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 @@ -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 diff --git a/bc_jsonpath_ng/__version__.py b/bc_jsonpath_ng/__version__.py index 424ebc4..e4adfb8 100644 --- a/bc_jsonpath_ng/__version__.py +++ b/bc_jsonpath_ng/__version__.py @@ -1 +1 @@ -__version__ = "1.5.9" +__version__ = "1.6.0" diff --git a/bc_jsonpath_ng/ext/filter.py b/bc_jsonpath_ng/ext/filter.py index 7f2c5ee..22a0f57 100644 --- a/bc_jsonpath_ng/ext/filter.py +++ b/bc_jsonpath_ng/ext/filter.py @@ -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: diff --git a/bc_jsonpath_ng/ext/iterable.py b/bc_jsonpath_ng/ext/iterable.py index ae2b200..d8b51bb 100644 --- a/bc_jsonpath_ng/ext/iterable.py +++ b/bc_jsonpath_ng/ext/iterable.py @@ -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 diff --git a/bc_jsonpath_ng/ext/parser.py b/bc_jsonpath_ng/ext/parser.py index 0a05530..0422579 100644 --- a/bc_jsonpath_ng/ext/parser.py +++ b/bc_jsonpath_ng/ext/parser.py @@ -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 @@ -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: diff --git a/bc_jsonpath_ng/lexer.py b/bc_jsonpath_ng/lexer.py index db55bf5..b0b3b6f 100644 --- a/bc_jsonpath_ng/lexer.py +++ b/bc_jsonpath_ng/lexer.py @@ -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 @@ -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 @@ -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 @@ -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]} " ) diff --git a/bc_jsonpath_ng/parser.py b/bc_jsonpath_ng/parser.py index bdd1d19..9c2d50f 100644 --- a/bc_jsonpath_ng/parser.py +++ b/bc_jsonpath_ng/parser.py @@ -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__) diff --git a/pyproject.toml b/pyproject.toml index 00562c2..54d9a06 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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" diff --git a/setup.py b/setup.py index 00c83c8..4d71207 100644 --- a/setup.py +++ b/setup.py @@ -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 " @@ -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", diff --git a/tests/test_jsonpath.py b/tests/test_jsonpath.py index d2f9c1f..6e8ae4a 100644 --- a/tests/test_jsonpath.py +++ b/tests/test_jsonpath.py @@ -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() @@ -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") )