Filtering fails when using Python API #35

Closed
opened 2025-12-16 01:18:41 +01:00 by maciek · 3 comments
Contributor

When using Python API, following snippet:

project = potodo.merge_and_scan_paths(
    [clone_path],
    pot_path=Path(clones_dir, 'cpython/Doc/build/gettext'),
    merge_path=path_for_merge,
    api_url='',
)
completion = project.completion
project.filter(
    filters=Filters(False, True, 0, 100, False, False),
    exclude=['**/*', '!bugs.po', '!tutorial/', '!library/functions.po'],
)
core_completion = project.completion

Fails with:

Traceback (most recent call last):
  File "/home/runner/work/dashboard/dashboard/completion.py", line 46, in get_completion
    project.filter(
    ~~~~~~~~~~~~~~^
        filters=Filters(False, True, 0, 100, False, False),
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        exclude=['**/*', '!bugs.po', '!tutorial/', '!library/functions.po'],
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "/opt/hostedtoolcache/Python/3.14.0/x64/lib/python3.14/site-packages/potodo/po_file.py", line 199, in filter
    directory.filter(filters, exclude)
    ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^
  File "/opt/hostedtoolcache/Python/3.14.0/x64/lib/python3.14/site-packages/potodo/po_file.py", line 281, in filter
    if self._select(file, filters):
       ~~~~~~~~~~~~^^^^^^^^^^^^^^^
  File "/opt/hostedtoolcache/Python/3.14.0/x64/lib/python3.14/site-packages/potodo/po_file.py", line 247, in _select
    if self.ignore_matcher(str(po_file.path)):
       ~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^
  File "/opt/hostedtoolcache/Python/3.14.0/x64/lib/python3.14/site-packages/potodo/po_file.py", line 240, in <lambda>
    return lambda file_path: handle_negation(file_path, rules)
                             ~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^
  File "/opt/hostedtoolcache/Python/3.14.0/x64/lib/python3.14/site-packages/gitignore_parser.py", line 12, in handle_negation
    if rule.match(file_path):
       ~~~~~~~~~~^^^^^^^^^^^
  File "/opt/hostedtoolcache/Python/3.14.0/x64/lib/python3.14/site-packages/gitignore_parser.py", line 133, in match
    rel_path = _normalize_path(abs_path).relative_to(self.base_path).as_posix()
               ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^
  File "/opt/hostedtoolcache/Python/3.14.0/x64/lib/python3.14/pathlib/__init__.py", line 495, in relative_to
    raise ValueError(f"{str(self)!r} is not in the subpath of {str(other)!r}")
ValueError: '/home/runner/work/dashboard/dashboard/clones/rebased_translations/Abdur-rahmaanJ/python-docs-ar/whatsnew/2.3.po' is not in the subpath of 'clones/rebased_translations/Abdur-rahmaanJ/python-docs-ar'
When using Python API, following snippet: ```python project = potodo.merge_and_scan_paths( [clone_path], pot_path=Path(clones_dir, 'cpython/Doc/build/gettext'), merge_path=path_for_merge, api_url='', ) completion = project.completion project.filter( filters=Filters(False, True, 0, 100, False, False), exclude=['**/*', '!bugs.po', '!tutorial/', '!library/functions.po'], ) core_completion = project.completion ``` [Fails](https://github.com/python-docs-translations/dashboard/actions/runs/19793610777/job/56710731283) with: ```python Traceback (most recent call last): File "/home/runner/work/dashboard/dashboard/completion.py", line 46, in get_completion project.filter( ~~~~~~~~~~~~~~^ filters=Filters(False, True, 0, 100, False, False), ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ exclude=['**/*', '!bugs.po', '!tutorial/', '!library/functions.po'], ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ) ^ File "/opt/hostedtoolcache/Python/3.14.0/x64/lib/python3.14/site-packages/potodo/po_file.py", line 199, in filter directory.filter(filters, exclude) ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^ File "/opt/hostedtoolcache/Python/3.14.0/x64/lib/python3.14/site-packages/potodo/po_file.py", line 281, in filter if self._select(file, filters): ~~~~~~~~~~~~^^^^^^^^^^^^^^^ File "/opt/hostedtoolcache/Python/3.14.0/x64/lib/python3.14/site-packages/potodo/po_file.py", line 247, in _select if self.ignore_matcher(str(po_file.path)): ~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^ File "/opt/hostedtoolcache/Python/3.14.0/x64/lib/python3.14/site-packages/potodo/po_file.py", line 240, in <lambda> return lambda file_path: handle_negation(file_path, rules) ~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^ File "/opt/hostedtoolcache/Python/3.14.0/x64/lib/python3.14/site-packages/gitignore_parser.py", line 12, in handle_negation if rule.match(file_path): ~~~~~~~~~~^^^^^^^^^^^ File "/opt/hostedtoolcache/Python/3.14.0/x64/lib/python3.14/site-packages/gitignore_parser.py", line 133, in match rel_path = _normalize_path(abs_path).relative_to(self.base_path).as_posix() ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^ File "/opt/hostedtoolcache/Python/3.14.0/x64/lib/python3.14/pathlib/__init__.py", line 495, in relative_to raise ValueError(f"{str(self)!r} is not in the subpath of {str(other)!r}") ValueError: '/home/runner/work/dashboard/dashboard/clones/rebased_translations/Abdur-rahmaanJ/python-docs-ar/whatsnew/2.3.po' is not in the subpath of 'clones/rebased_translations/Abdur-rahmaanJ/python-docs-ar' ```
Author
Contributor

Hm, I wonder if I shouldn't file a bug in https://github.com/mherrmann/gitignore_parser

Hm, I wonder if I shouldn't file a bug in https://github.com/mherrmann/gitignore_parser
Owner

It would need to be reproduced with gitignore_parser only, but yes maybe.

It would need to be reproduced with gitignore_parser only, but yes maybe.
Author
Contributor

It's enough to provide merge_path as an absolute path. Therefore closing this.

It's enough to provide `merge_path` as an absolute path. Therefore closing this.
Sign in to join this conversation.
No labels
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
AFPy/potodo#35
No description provided.