Skip to content

Commit

Permalink
Merge pull request #3 from iterative/create-pull-request/patch
Browse files Browse the repository at this point in the history
update template
  • Loading branch information
efiop authored Jan 31, 2023
2 parents f22402d + 9e6c5d9 commit 8c599df
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 64 deletions.
2 changes: 1 addition & 1 deletion .cruft.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"template": "https://github.com/iterative/py-template",
"commit": "75abeda8b405100ca48820bb33191a85de9f446f",
"commit": "b003476266a25fc6bc648aecdbe6c8ed82009236",
"checkout": null,
"context": {
"cookiecutter": {
Expand Down
13 changes: 6 additions & 7 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ default_language_version:
python: python3
repos:
- repo: https://github.com/psf/black
rev: 22.10.0
rev: 22.12.0
hooks:
- id: black
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.3.0
rev: v4.4.0
hooks:
- id: check-added-large-files
- id: check-case-conflict
Expand All @@ -29,21 +29,20 @@ repos:
- id: codespell
additional_dependencies: ["tomli"]
- repo: https://github.com/asottile/pyupgrade
rev: v3.2.2
rev: v3.3.1
hooks:
- id: pyupgrade
args: [--py38-plus]
- repo: https://github.com/PyCQA/isort
rev: 5.10.1
rev: 5.12.0
hooks:
- id: isort
- repo: https://github.com/pycqa/flake8
rev: 5.0.4
rev: 6.0.0
hooks:
- id: flake8
additional_dependencies:
- flake8-broken-line==0.6.0
- flake8-bugbear==22.10.27
- flake8-bugbear==23.1.20
- flake8-comprehensions==3.10.1
- flake8-debugger==4.1.2
- flake8-string-format==0.3.0
Expand Down
7 changes: 5 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ build-backend = "setuptools.build_meta"
[tool.setuptools_scm]

[tool.black]
line-length = 79
line-length = 88
include = '\.pyi?$'
exclude = '''
/(
Expand All @@ -25,7 +25,7 @@ exclude = '''
[tool.isort]
profile = "black"
known_first_party = ["sqltrie"]
line_length = 79
line_length = 88

[tool.pytest.ini_options]
addopts = "-ra"
Expand Down Expand Up @@ -64,6 +64,9 @@ warn_redundant_casts = true
warn_unreachable = true
files = ["src", "tests"]

[tool.pylint.format]
max-line-length = 88

[tool.pylint.master]
load-plugins = ["pylint_pytest"]

Expand Down
14 changes: 9 additions & 5 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,16 @@ pyinstaller40 =

[flake8]
ignore=
E203, # Whitespace before ':'
E266, # Too many leading '#' for block comment
W503, # Line break occurred before a binary operator
P1, # unindexed parameters in the str.format, see:
# Whitespace before ':'
E203
# Too many leading '#' for block comment
E266
# Line break occurred before a binary operator
W503
# unindexed parameters in the str.format, see:
# https://pypi.org/project/flake8-string-format/
max_line_length = 79
P1
max_line_length = 88
max-complexity = 15
select = B,C,E,F,W,T4,B902,T,P
show_source = true
Expand Down
4 changes: 1 addition & 3 deletions src/sqltrie/__pyinstaller/hook-sqltrie.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
# pylint: disable=invalid-name
from PyInstaller.utils.hooks import ( # pylint: disable=import-error
collect_data_files,
)
from PyInstaller.utils.hooks import collect_data_files # pylint: disable=import-error

datas = collect_data_files("sqltrie")
8 changes: 2 additions & 6 deletions src/sqltrie/pygtrie.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,6 @@ def diff(self, old, new, with_unchanged=False):
elif not with_unchanged:
continue

old_node = (
TrieNode(key[len(old) :], old_entry) if old_entry else None
)
new_node = (
TrieNode(key[len(new) :], new_entry) if new_entry else None
)
old_node = TrieNode(key[len(old) :], old_entry) if old_entry else None
new_node = TrieNode(key[len(new) :], new_entry) if new_entry else None
yield Change(typ, old_node, new_node)
8 changes: 2 additions & 6 deletions src/sqltrie/serialized.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,17 +83,13 @@ def items(self, *args, **kwargs):
def ls(self, key, with_values=False):
entries = self._trie.ls(key, with_values=with_values)
if with_values:
yield from (
(ekey, self._load(ekey, evalue)) for ekey, evalue in entries
)
yield from ((ekey, self._load(ekey, evalue)) for ekey, evalue in entries)
else:
yield from entries

def traverse(self, node_factory, prefix=None):
def _node_factory_wrapper(path_conv, path, children, value):
return node_factory(
path_conv, path, children, self._load(path, value)
)
return node_factory(path_conv, path, children, self._load(path, value))

return self._trie.traverse(_node_factory_wrapper, prefix=prefix)

Expand Down
33 changes: 7 additions & 26 deletions src/sqltrie/sqlite/sqlite.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,7 @@
from typing import Iterator, Optional, Union
from uuid import uuid4

from ..trie import (
AbstractTrie,
Change,
ShortKeyError,
TrieKey,
TrieNode,
TrieStep,
)
from ..trie import AbstractTrie, Change, ShortKeyError, TrieKey, TrieNode, TrieStep

# NOTE: seems like "named" doesn't work without changing this global var,
# so unfortunately we have to stick with qmark.
Expand Down Expand Up @@ -103,7 +96,6 @@ def _create_node(self, key):
INSERT OR IGNORE
INTO nodes (pid, name)
VALUES (?, ?)
RETURNING id
""",
(pid, name),
)
Expand All @@ -118,9 +110,7 @@ def _traverse(self, key):
STEPS_SQL.format(path="/".join(key), root=self._root_id)
)

return self._conn.execute( # nosec
f"SELECT * FROM {STEPS_TABLE}"
).fetchall()
return self._conn.execute(f"SELECT * FROM {STEPS_TABLE}").fetchall() # nosec

def _get_node(self, key):
if not key:
Expand Down Expand Up @@ -195,9 +185,7 @@ def __delitem__(self, key):
)

def __len__(self):
self._conn.executescript(
ITEMS_SQL.format(root=self._root_id, shallow=False)
)
self._conn.executescript(ITEMS_SQL.format(root=self._root_id, shallow=False))
return self._conn.execute( # nosec
f"""
SELECT COUNT(*) AS count FROM {ITEMS_TABLE}
Expand Down Expand Up @@ -252,9 +240,7 @@ def items(self, prefix=None, shallow=False):
self._conn.executescript(ITEMS_SQL.format(root=pid, shallow=shallow))
rows = self._conn.execute(f"SELECT * FROM {ITEMS_TABLE}") # nosec

yield from (
((*prefix, *row["path"].split("/")), row["value"]) for row in rows
)
yield from (((*prefix, *row["path"].split("/")), row["value"]) for row in rows)

def clear(self):
self._conn.execute("DELETE FROM nodes")
Expand All @@ -271,8 +257,7 @@ def ls(
) -> Iterator[Union[TrieKey, TrieNode]]:
if with_values:
yield from ( # type: ignore
((*key, row["name"]), row["value"])
for row in self._get_children(key)
((*key, row["name"]), row["value"]) for row in self._get_children(key)
)
else:
yield from ( # type: ignore
Expand All @@ -284,12 +269,8 @@ def traverse(self, node_factory, prefix=None):
row = self._get_node(prefix)
value = row["value"]

children_keys = (
(*key, row["name"]) for row in self._get_children(key)
)
children = (
self.traverse(node_factory, child) for child in children_keys
)
children_keys = ((*key, row["name"]) for row in self._get_children(key))
children = (self.traverse(node_factory, child) for child in children_keys)

return node_factory(None, key, children, value)

Expand Down
9 changes: 1 addition & 8 deletions tests/test_sqltrie.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,7 @@

import pytest

from sqltrie import (
UNCHANGED,
Change,
PyGTrie,
ShortKeyError,
SQLiteTrie,
TrieNode,
)
from sqltrie import UNCHANGED, Change, PyGTrie, ShortKeyError, SQLiteTrie, TrieNode


@pytest.mark.parametrize("cls", [SQLiteTrie, PyGTrie])
Expand Down

0 comments on commit 8c599df

Please sign in to comment.