-
-
Notifications
You must be signed in to change notification settings - Fork 228
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
feat: add support for regular expressions #239
feat: add support for regular expressions #239
Conversation
Hi @lyz-code
If you can make it optional by having a flag passed to DeepSearch, that would be great. Otherwise I will take care of it when I have a chance! |
Hi @seperman, I'm not sure about adding the flag, I feel that as the previous behaviour is included in the regular expression implementation, and that it's the default of Regarding the use of re.compile, I didn't know you could improve the performance, and after reading about it (1, 2, and 3) I don't know if those performance improvements affect this use case. The official docs say that:
Which I don't really understand xD , it looks contradictory to me. Correct me if I'm wrong, but to take advantage of the compiling, we would need to pass the compiled object to the different methods, if so, do we want that? I'm not opposing on doing the changes, I just want to understand them better. Whatever we decide in the end, I can do the implementation |
…orted Until [#239](seperman/deepdiff#239) is merged, the official library doesn't support searching for regular expressions. You can use [my fork](https://github.com/lyz-code/deepdiff) instead. feat(python_snippets#Install a python dependency from a git repository): explain how to install dependencies from git repositories With [pip you can](https://stackoverflow.com/questions/16584552/how-to-state-in-requirements-txt-a-direct-github-source): ```bash pip install git+git://github.com/path/to/repository@master ``` If you want [to hard code it in your `setup.py`](https://stackoverflow.com/questions/32688688/how-to-write-setup-py-to-include-a-git-repository-as-a-dependency/54794506#54794506), you need to: ```python install_requires = [ 'some-pkg @ git+ssh://[email protected]/someorgname/[email protected]#egg=some-pkg', ] ``` feat(python#How to write good documentation): add interesting links on how to write good documentation I would like to refactor [divio's](https://documentation.divio.com/introduction/) and [Vue's](https://v3.vuejs.org/guide/contributing/writing-guide.html#principles) guidelines and apply it to my projects. feat(sqlite#regexp): explain how to configure sqlite to be able to use the REGEXP operator It's not enabled by default. feat(sqlite3#regexp): explain how to implement the REGEXP operator with Python
Hi @seperman any thoughts on what I've said? |
Hey @lyz-code sorry I didn't see the comments here. Let me check. |
Ok so regarding regex, generally it shouldn't be on by default. For example, stackoverflow.com homepage was brought down by a regex a few year ago: https://stackstatus.net/post/147710624694/outage-postmortem-july-20-2016 |
deepdiff/search.py
Outdated
@@ -205,7 +205,7 @@ def __search_dict(self, | |||
|
|||
str_item = str(item) | |||
if (self.match_string and str_item == new_parent_cased) or\ | |||
(not self.match_string and str_item in new_parent_cased): | |||
(not self.match_string and re.search(str_item, new_parent_cased)): |
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.
Since the regex will be running on objects repeatedly, it is going to be better to compile it beforehand and use it here. For example you could take a look at how convert_item_or_items_into_compiled_regexes_else_none
is used for exactly the same purpose when the user passes exclude_regex_paths
:
Line 177 in 5b66b96
self.exclude_regex_paths = convert_item_or_items_into_compiled_regexes_else_none(exclude_regex_paths) |
Line 389 in 5b66b96
[exclude_regex_path.search(level.path()) for exclude_regex_path in self.exclude_regex_paths]): |
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.
Thanks for implementing the changes!
Hi @lyz-code |
Great! thanks :) |
[Boto3](https://boto3.amazonaws.com/v1/documentation/api/latest/index.html) is the AWS SDK for Python to create, configure, and manage AWS services, such as Amazon Elastic Compute Cloud (Amazon EC2) and Amazon Simple Storage Service (Amazon S3). The SDK provides an object-oriented API as well as low-level access to AWS services. For [testing](boto3.md#testing), try to use [moto](boto3.md#moto), using the [Botocore's stubber](https://botocore.amazonaws.com/v1/documentation/api/latest/reference/stubber.html) as fallback option. perf(deepdiff): remove advice to use my fork instead The original one has already merged my [PR](seperman/deepdiff#239) `\\ ٩( ᐛ )و //`. Beware though as the `regexp` are not enabled by default (against my will). You need to use the `use_regexp=True` as an argument to `grep` or `DeepSearch`. feat(factoryboy#Word from Enum choices): explain how to use `Enum` with factoryboy. feat(faker.md#Create a random choice from an Enum): explain how to select a random choice from `Enum` objects [pydantic](pydantic.md) uses `Enum` objects to define [the choices of fields](https://pydantic-docs.helpmanual.io/usage/types/#enums-and-choices), so we need them to create the factories of those objects. feat(pydantic#Update entity attributes with a dictionary): explain how to update entity attributes with a dictionary You can create a new object with the new data using the `update` argument of the `copy` entity method. style(pytest): change list marker from dash to asterisk fix(python_snippets#Install a python dependency from a git repository): add warning about the method to use direct dependencies Last time I used this solution, when I added the library on a `setup.py` the direct dependencies weren't installed :S fix(flakehell): update the git repository The existent repository has been archived in favor of [this one](https://github.com/flakehell/flakehell) feat(writing#im-good-or-im-well): Explain when to use I'm good or I'm well Use I'm well when referring to being ill, use I'm good for the rest.
Closes #238