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

Re complile fail mentioning "ps_d" when using --gitignore #240

Closed
tolomea opened this issue Aug 31, 2022 · 11 comments · Fixed by #241
Closed

Re complile fail mentioning "ps_d" when using --gitignore #240

tolomea opened this issue Aug 31, 2022 · 11 comments · Fixed by #241
Assignees
Labels
bug Something isn't working changelog Changes should be written to the changelog file.

Comments

@tolomea
Copy link

tolomea commented Aug 31, 2022

We've recently started getting the below failure.

Traceback (most recent call last):
  File "/home/gordon/.cache/pre-commit/repotvgski9p/py_env-python3/bin/unimport", line 8, in <module>
    sys.exit(main())
  File "/home/gordon/.cache/pre-commit/repotvgski9p/py_env-python3/lib/python3.10/site-packages/unimport/main.py", line 26, in main
    for path in config.get_paths():
  File "/home/gordon/.cache/pre-commit/repotvgski9p/py_env-python3/lib/python3.10/site-packages/unimport/config.py", line 72, in get_paths
    yield from utils.list_paths(
  File "/home/gordon/.cache/pre-commit/repotvgski9p/py_env-python3/lib/python3.10/site-packages/unimport/utils.py", line 117, in list_paths
    include_regex, exclude_regex = re.compile(include), re.compile(exclude)
  File "/usr/lib/python3.10/re.py", line 251, in compile
    return _compile(pattern, flags)
  File "/usr/lib/python3.10/re.py", line 303, in _compile
    p = sre_compile.compile(pattern, flags)
  File "/usr/lib/python3.10/sre_compile.py", line 764, in compile
    p = sre_parse.parse(p, flags)
  File "/usr/lib/python3.10/sre_parse.py", line 950, in parse
    p = _parse_sub(source, state, flags & SRE_FLAG_VERBOSE, 0)
  File "/usr/lib/python3.10/sre_parse.py", line 443, in _parse_sub
    itemsappend(_parse(source, state, verbose, nested + 1,
  File "/usr/lib/python3.10/sre_parse.py", line 836, in _parse
    p = _parse_sub(source, state, sub_verbose, nested + 1)
  File "/usr/lib/python3.10/sre_parse.py", line 443, in _parse_sub
    itemsappend(_parse(source, state, verbose, nested + 1,
  File "/usr/lib/python3.10/sre_parse.py", line 833, in _parse
    raise source.error(err.msg, len(name) + 1) from None
re.error: redefinition of group name 'ps_d' as group 2; was group 1 at position 72

We're running with py3.10.4, and this bit of precommit

-   repo: https://github.com/hakancelik96/unimport
    rev: 0.11.1
    hooks:
    -   id: unimport
        args: [--remove, --include-star-import, --ignore-init, --gitignore]

It looks like this was caused by our use of --gitignore and the recent (10 hours ago at the time of writing) release of pathspec 0.10.0.

Digging into it I'm seeing that it's taken every line from our .gitignore and wrapped it, so /prof has become ^prof(?:(?P<ps_d>/).*)?$ that seems to come from GitWildMatchPattern

@tolomea tolomea changed the title RE fail Re complile fail mentioning "ps_d" when using --gitignore Aug 31, 2022
@tolomea
Copy link
Author

tolomea commented Aug 31, 2022

for now we are working around it like this

-   repo: https://github.com/hakancelik96/unimport
    rev: 0.11.1
    hooks:
    -   id: unimport
        args: [--remove, --include-star-import, --ignore-init, --gitignore]
        additional_dependencies: ["pathspec==0.9.0"]

@hakancelikdev
Copy link
Owner

Thank you for opening the Issue I did a few tests, and I solved the problem, but I can't decide yet, the gitignore flag works more correctly in pathspec 0.10.0 and later,

Should I continue to support all versions 0.5.0 and above, or should I support versions 0.10.0 and above?

My idea is to support 0.10.0 and above versions because as I said, unimport will work more correctly if it uses these versions.

@hakancelikdev
Copy link
Owner

Does anyone want to share their opinion?

@hakancelikdev hakancelikdev self-assigned this Sep 4, 2022
@hakancelikdev hakancelikdev added bug Something isn't working changelog Changes should be written to the changelog file. labels Sep 4, 2022
@hakancelikdev
Copy link
Owner

It seems that Pathspec has stopped supporting Python 3.6, I can only use the 0.10.0 version and above for Python 3.7 and above.

@tolomea
Copy link
Author

tolomea commented Sep 4, 2022 via email

@hakancelikdev
Copy link
Owner

Yes, I know but I want to support it as much as possible.

@hakancelikdev
Copy link
Owner

It seems unnecessary effort to support 3.6 and windows. https://pypistats.org/packages/unimport

@hakancelikdev
Copy link
Owner

hakancelikdev commented Sep 4, 2022

@tolomea can you try version 0.11.3?

@tolomea
Copy link
Author

tolomea commented Sep 5, 2022 via email

@hakancelikdev
Copy link
Owner

Yes, I noticed and fixed this bug right away, can you try version 0.11.3? @tolomea

@tolomea
Copy link
Author

tolomea commented Oct 11, 2022 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working changelog Changes should be written to the changelog file.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants