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 3 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.28%. Comparing base (f91754b) to head (6c21d2f).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1120      +/-   ##
==========================================
+ Coverage   91.26%   91.28%   +0.02%     
==========================================
  Files          27       27              
  Lines        4602     4613      +11     
==========================================
+ Hits         4200     4211      +11     
  Misses        402      402              
Flag Coverage Δ
macos-12-3.10 90.09% <100.00%> (+0.02%) ⬆️
macos-12-3.11 90.02% <100.00%> (+0.02%) ⬆️
macos-12-3.12 90.20% <100.00%> (+0.02%) ⬆️
macos-12-3.13-dev 89.72% <100.00%> (+0.02%) ⬆️
macos-12-3.8 90.02% <100.00%> (+0.02%) ⬆️
macos-12-3.9 90.02% <100.00%> (+0.02%) ⬆️
macos-12-pypy3.10 90.09% <100.00%> (+0.02%) ⬆️
ubuntu-22.04-3.10 90.11% <100.00%> (+0.02%) ⬆️
ubuntu-22.04-3.11 90.04% <100.00%> (+0.02%) ⬆️
ubuntu-22.04-3.12 90.22% <100.00%> (+0.02%) ⬆️
ubuntu-22.04-3.13-dev 89.74% <100.00%> (+0.02%) ⬆️
ubuntu-22.04-3.8 90.04% <100.00%> (+0.02%) ⬆️
ubuntu-22.04-3.9 90.04% <100.00%> (+0.02%) ⬆️
ubuntu-22.04-pypy3.10 90.11% <100.00%> (+0.02%) ⬆️
windows-2022-3.10 90.23% <100.00%> (+0.02%) ⬆️
windows-2022-3.11 90.16% <100.00%> (+0.02%) ⬆️
windows-2022-3.12 90.34% <100.00%> (+0.02%) ⬆️
windows-2022-3.13-dev 89.86% <100.00%> (+0.02%) ⬆️
windows-2022-3.8 90.16% <100.00%> (+0.02%) ⬆️
windows-2022-3.9 90.16% <100.00%> (+0.02%) ⬆️
windows-2022-pypy3.10 90.23% <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!

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