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

feat: add support for regular expressions #239

Merged
merged 2 commits into from
Apr 16, 2021

Conversation

lyz-code
Copy link
Contributor

@lyz-code lyz-code commented Apr 6, 2021

Closes #238

@seperman
Copy link
Owner

seperman commented Apr 7, 2021

Hi @lyz-code
This is great! Thanks for the PR.

  1. Do you think we should make regex search the only option or it should be optional? For example most IDE's let you choose if you want to search using regex or not. I think we should give that option to the user, no?
  2. The only other comment I have is that re.search can become faster if we use re.compile.

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!
Thanks again!

@lyz-code
Copy link
Contributor Author

lyz-code commented Apr 7, 2021

Hi @seperman,
Thanks for the quick answer :)

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 grep, I wouldn't personally add it. What use case or advantages do you have in mind? I may be missing them.

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:

The compiled versions of the most recent patterns passed to re.compile() and the module-level matching functions are cached, so programs that use only a few regular expressions at a time needn’t worry about compiling regular expressions.

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

lyz-code added a commit to lyz-code/blue-book that referenced this pull request Apr 7, 2021
…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
@lyz-code
Copy link
Contributor Author

Hi @seperman any thoughts on what I've said?

@seperman
Copy link
Owner

seperman commented Apr 13, 2021

Hey @lyz-code sorry I didn't see the comments here. Let me check.

@seperman
Copy link
Owner

seperman commented Apr 13, 2021

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
Also sometimes one may be looking for strings that have different meaning in regex. For example let's say one is looking for .* in a dataset. But they are literally just searching for that string not the regex meaning of the string.

@@ -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)):
Copy link
Owner

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:

self.exclude_regex_paths = convert_item_or_items_into_compiled_regexes_else_none(exclude_regex_paths)

[exclude_regex_path.search(level.path()) for exclude_regex_path in self.exclude_regex_paths]):

@lyz-code
Copy link
Contributor Author

Hey @seperman, I've implemented the suggested changes in baab716

@seperman seperman changed the base branch from master to dev April 16, 2021 17:24
Copy link
Owner

@seperman seperman left a 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!

@seperman seperman merged commit 4e3b121 into seperman:dev Apr 16, 2021
@seperman
Copy link
Owner

Hi @lyz-code
This feature is released. Thanks for contributing! https://zepworks.com/deepdiff/current/#what-is-new

@lyz-code
Copy link
Contributor Author

Great! thanks :)

lyz-code added a commit to lyz-code/blue-book that referenced this pull request Apr 19, 2021
[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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support searching with regular expressions
2 participants