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

Prevent wrapping file locations containing white space #1120

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

Conversation

tomasr8
Copy link
Member

@tomasr8 tomasr8 commented Aug 18, 2024

Closes #1078
Depends on #1105 (To see only the changes in this PR, look at the last two commits)

Since #1105 wraps file names containing white space in special unicode markers, we look out for them when
wrapping comments.

The fix overrides the _split method of TextWrapper where we manually generate the indivisible chunks, taking into
account enclosed file names.

I test the the wrapping behavior with gettext 0.22.5 (which includes the enclosing logic) to make sure it's consistent

@tomasr8
Copy link
Member Author

tomasr8 commented Aug 18, 2024

Interesting, calling super() inside a list comprehension does not work on python 3.9..

Copy link

codecov bot commented Aug 18, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 91.29%. Comparing base (0005c85) to head (89602b4).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1120      +/-   ##
==========================================
+ Coverage   91.27%   91.29%   +0.02%     
==========================================
  Files          27       27              
  Lines        4619     4630      +11     
==========================================
+ Hits         4216     4227      +11     
  Misses        403      403              
Flag Coverage Δ
macos-12-3.10 90.06% <100.00%> (+0.02%) ⬆️
macos-12-3.11 90.00% <100.00%> (+0.02%) ⬆️
macos-12-3.12 90.21% <100.00%> (+0.02%) ⬆️
macos-12-3.13-dev 89.74% <100.00%> (+0.02%) ⬆️
macos-12-3.8 89.99% <100.00%> (+0.02%) ⬆️
macos-12-3.9 89.99% <100.00%> (+0.02%) ⬆️
macos-12-pypy3.10 90.06% <100.00%> (+0.02%) ⬆️
ubuntu-22.04-3.10 90.08% <100.00%> (+0.02%) ⬆️
ubuntu-22.04-3.11 90.02% <100.00%> (+0.02%) ⬆️
ubuntu-22.04-3.12 90.23% <100.00%> (+0.02%) ⬆️
ubuntu-22.04-3.13-dev 89.76% <100.00%> (+0.02%) ⬆️
ubuntu-22.04-3.8 90.01% <100.00%> (+0.02%) ⬆️
ubuntu-22.04-3.9 90.01% <100.00%> (+0.02%) ⬆️
ubuntu-22.04-pypy3.10 90.08% <100.00%> (+0.02%) ⬆️
windows-2022-3.10 90.20% <100.00%> (+0.02%) ⬆️
windows-2022-3.11 90.14% <100.00%> (+0.02%) ⬆️
windows-2022-3.12 90.35% <100.00%> (+0.02%) ⬆️
windows-2022-3.13-dev 89.88% <100.00%> (+0.02%) ⬆️
windows-2022-3.8 90.13% <100.00%> (+0.02%) ⬆️
windows-2022-3.9 90.13% <100.00%> (+0.02%) ⬆️
windows-2022-pypy3.10 90.20% <100.00%> (+0.02%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@tomasr8 tomasr8 changed the title Prevent wrapping file locations containing white sapce Prevent wrapping file locations containing white space Aug 18, 2024
@akx
Copy link
Member

akx commented Sep 4, 2024

@tomasr8 Can you rebase now that #1105 was merged? Thanks!

@tomasr8
Copy link
Member Author

tomasr8 commented Sep 4, 2024

@tomasr8 Can you rebase now that #1105 was merged? Thanks!

Done ;)

chunks = [[c] if c.startswith(enclosed_filename_start) else super_._split(c) for c in chunks]
chunks = [c for c in chain.from_iterable(chunks) if c]
return chunks


def wraptext(text: str, width: int = 70, initial_indent: str = '', subsequent_indent: str = '') -> list[str]:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The documentation of wraptext() should be updated to reflect the new behaviour (it says "This version does not wrap lines on hyphens in words.")

Copy link
Member

@akx akx Oct 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, a little perf thing – maybe for this PR, maybe for a subsequent one: wraptext() is called repeatedly in pofile.py – it would be more efficient to construct two different TextWrappers in advance and call wrap() on them.

I think babel.util.wraptext() should probably be deprecated then.

I can whip up a PR to do that... #1140

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The documentation of wraptext() should be updated to reflect the new behaviour (it says "This version does not wrap lines on hyphens in words.")

This version doesn't wrap lines on hyphens either, unless I misunderstood your comment? Did you mean that we should add a comment about filenames containing spaces?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I meant adding a comment about the new filenames-with-spaces behavior.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment added!

@tomasr8
Copy link
Member Author

tomasr8 commented Nov 10, 2024

Rebased and fixed the tests caused by missing break_long_words=False in TextWrapper

@tomasr8 tomasr8 requested a review from akx November 14, 2024 23:24
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.

Long path with space lead to wrong PO file.
2 participants