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

Add ability to select path segments with user defined match; follow on to PRs #146 & #177 #182

Open
wants to merge 23 commits into
base: master
Choose a base branch
from

Conversation

AlainLich
Copy link

Hi,
following the approach in previous PRs, this allows to use user defined match.
An example is shown below, more in the README.rst and the tests.

Remarks:

Examples of code

class Anagram():
                def __init__(self, s):
                    self.ref = "".join(sorted(s))

                def match(self, st):
                    retval = True if "".join(sorted(st)) == self.ref else None
                    return retval

dpath.search(mydict, ['**', Anagram("bella")

Same example not requiring duck typing, appropriate for Pypy (at this time) and older Pythons

class Anagram(DP.types.Basic_StringMatcher):
        def __init__(self, s):
                   self.ref = "".join(sorted(s))

       def match(self, st):
                   retval = True if "".join(sorted(st)) == self.ref else None
                   return retval

dpath.search(mydict, ['**', Anagram("bella")

AlainLich and others added 21 commits December 9, 2022 21:59
Recovered 1) tests/test_path_ext_py from PR submission
2) some github workflows used to validate PR submission
    Follow-up PR: "Add ability to select path segments using Python re regexprs" dpath-maintainers#146
 	          on June 1, 2021

    Includes:
            - integration of extension on dpath-python
            - improvement of tests (under nose2, with scripts test/noseRunner to control code options)
            - improvement of documentation in README.rst

    Baseline for integration:
            commit ea64635 (tag: v2.1.1, origin/master, origin/HEAD, master, AL-master4merge)
            Merge: 702b5dd 38007df
            Author: moomoohk <moomoohk2@gmail.com>
            Date:   Wed Nov 30 17:16:05 2022 +0200

    Note: at this time, no test wrt. Github.Actions has been made (yet)
Resolved conflicts:
	dpath/segments.py
	dpath/version.py

Testing to be redone!
        - tests improved and running locally
	- documentation updated

Follow-up PR: "Add ability to select path segments using Python re regexprs" dpath-maintainers#146
              on June 1, 2021

Baseline for merge:
    commit 45b3488 (tag: v2.1.2, origin/master, origin/HEAD, master)
    Author: moomoohk <2220203+moomoohk@users.noreply.github.com>
    Date:   Mon Dec 5 09:52:05 2022 +0200
…on enhancements

1) suppress dependency on mock now integrated as unittest.mock
2) avoids warnings concerning invalid escape sequences: either use raw strings or
   use double backslash: testing both
3) detailed the issue of such escape sequences in re.regexp in README.rst,
   giving example of both techniques

No change in .yml: rerunning should resolve identified issues
…path for pypy

    - Improved Github actions (clean up, test under pypy3)
    - formatting in accordance with Flake8, deal with errors diagnosed by Flake but
	accepted by python3
    - moved test tools to dir test-utils
    - tox.ini, flake.ini: avoid spurious diagnostics
…ing StringMatcher capability:

     1) supports extension by re.regex (re.Pattern.match)
     2) supports duck typed Duck_StringMatcher derived classes which permit user defined pattern matcher
     3) included tests and documenation
     4) dealt with Flake8 diagnostics

    Also found a random rare error in test_segments.test_view, left Pdb obtained information in the source
    file (see bottom of tests/test_segments.py). This corresponds with an unrealistic situation random
    generated by hypothesis, not easily reproducible for lack of random seed.
…hon's re

- uses duck typing
- provides base class for deriving matchers, usefull when duck typing not available
- extends tests

Depends on recent Python developments
  - https://peps.python.org/pep-0604/#isinstance-and-issubclass
  - https://bugs.python.org/issue44529
  - requires PEP-0544 features
Puts development in synch with latest master from origin and maintainer's repo
 Restructured as requested, strictly required mods
    - flake8 compliant
    - nose2 tested
    - tox tested for Python3.11 and Pypy3.9
    - improved some tests (require verification of result...)
    - documentation README.rst synchronized

  Still TBD:
    - check of .github/workflows

  Test environment:
       - Running on ARM-64
          Linux version 5.15.49-linuxkit (root@buildkitsandbox)
           (gcc (Alpine 10.2.1_pre1) 10.2.1 20201203, GNU ld (GNU Binutils) 2.35.2)
           dpath-maintainers#1 SMP PREEMPT Tue Sep 13 07:51:32 UTC 2022
       - Python 3.11.2
       - pypy3 --version : Python 3.9.16 (7.3.11+dfsg-2, Feb 06 2023, 17:14:22)
                           [PyPy 7.3.11 with GCC 12.2.0]
  - new file:   .github/workflows/python3Test.yml
  - remove this for PR
- f-strings support = for self-documenting expression
  introduced with Python 3.8
  - includes only required changes for feature, as suggested in @moomoohk
    comment on April 5th
  - test improvements
  - tested on python3.8,...,3.11 and pypy3.7 & 3.9
  - simplified code by using tuples with isinstance
  - reduced dependencies on Python versions, still supporting 3.7 with workaround
  - based on latest maintainer's version and on branch AL-PR-restructRQT which strives
    at matching maintainer's expectations for the (more limited) extension to re.regexp matching
  - tested locally (debian container running on ARM), not yet in github workflows
  - documentation improvements
  - test improvements

  - workflow python3Test.yml for testing only, remove before PR
Add support for generalized segment matching in paths

      - simplified code by using tuples with isinstance
      - reduced dependencies on Python versions, still supporting 3.7 with workaround
      - based on latest maintainer's version and on branch AL-PR-restructRQT which strives
        at matching maintainer's expectations for the (more limited) extension to re.regexp matching
      - tested locally (debian container running on ARM), not yet in github workflows
      - documentation improvements
      - test improvements

      - workflow python3Test.yml for testing only, remove before PR
@AlainLich
Copy link
Author

Hi,
this simplifies and cleans up the generalized version that allows for user defined segment matching. It is built over the latest developper commit ( Merge: 2eae6c1 995b7d9, Date: Sat Mar 25 21:07:41 2023 +0300). Tested on Pypy-3.7,-3.9 and several Pythons.

I have 2 PRs:

Tests in workflows:

I hope this is as expected, also I found that much cleanup/simplification was required from December/January versions.
Regards
Alain

- includes maintainer requests and changes (in other branch/PR)
- improved tests and documentation
- tox allows testing with ALLOW_REGEX on and off (used in workflow python3Test.yml)
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.

2 participants