-
Notifications
You must be signed in to change notification settings - Fork 11
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
Draft: Feat/glom like key searching #44
Open
mkrd
wants to merge
13
commits into
main
Choose a base branch
from
feat/glom-like-key-searching
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
0a49406
add glom like searching
c83342c
reformat imports
e75f8eb
fix type hinting
66a6a41
add tests
325d3c7
rename Searcher -> KeySearcher
e856f71
add partial write
0a105d9
fix print compatibility
a1c544b
renaming
21b8a9f
add negative test
456aef2
add dataclass for searching
4d0c4b8
add Index dataclass
f53b456
use tabs
mkrd d5499a0
revert docstring indent
mkrd File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import dataclasses | ||
|
||
|
||
@dataclasses.dataclass(frozen=True) | ||
class SearchResult: | ||
start_byte: int | ||
end_byte: int | ||
found: bool | ||
|
||
|
||
@dataclasses.dataclass(frozen=True) | ||
class Index: | ||
key: str | ||
key_start: int | ||
key_end: int | ||
indent_level: int | ||
indent_with: str | ||
value_hash: str | ||
old_value_end: int |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import hashlib | ||
|
||
from dictdatabase import utils | ||
from dictdatabase.dataclasses import Index | ||
|
||
|
||
def create_index(all_file_bytes: bytes, key: str, start, end) -> Index: | ||
""" | ||
It takes a JSON file, a key, and a start and end position, and returns a tuple of information about the key and its | ||
value | ||
|
||
Args: | ||
all_file_bytes (bytes): The entire file as a byte string. | ||
key (str): The key of the value we're indexing. | ||
start: the start of the value in the file | ||
end: the end of the value in the file | ||
|
||
Returns: | ||
The key, start, end, indent_level, indent_with, value_hash, end | ||
""" | ||
key_start, key_end = utils.find_outermost_key_in_json_bytes(all_file_bytes, key) | ||
indent_level, indent_with = utils.detect_indentation_in_json_bytes( | ||
all_file_bytes, key_start | ||
) | ||
value_bytes = all_file_bytes[start:end] | ||
value_hash = hashlib.sha256(value_bytes).hexdigest() | ||
return Index(key, start, end, indent_level, indent_with, value_hash, end) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@UmbrellaMalware let's stick with tabs so the diff looks clean
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pep8 says spaces are preferred
This can become a problem if someone else wants to propose changes to the project
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes I know. I personally prefer tabs, and think they are faster to work with. But if this project becomes bigger, I agree that it should adhere to most python community standards. But I'd like to keep the merge clean, the indentation and formatting stuff should be part of a separate issue/MR