sqlalchemy / alembic

A database migrations tool for SQLAlchemy.
MIT License
2.76k stars 241 forks source link

fix alembic.util.messaging.msg to properly wrap at terminal width #1385

Closed saifelse closed 8 months ago

saifelse commented 9 months ago

Description

Instead of applying indent manually after using textwrap, simply use the textwrap.wrap's initial_indent / subsequent_indent so that it is accounted for when wrapping to width.

Otherwise, each line will actually exceed the terminal width by two characters, since we were prepending two spaces.

Fixes: #1384

Manual Testing

Running the repro in #1384 now produces the expected output:

In a fairly narrow terminal window (e.g. 64 columns wide), run:

python -c 'from alembic.util.messaging import msg; msg("A" * 500)'

Output:

  AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
  AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
  AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
  AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
  AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
  AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
  AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
  AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
  AAAA

🎉

Checklist

This pull request is:

Have a nice day!

CaselIT commented 9 months ago

Thanks, could you add a changelog file too?

See https://github.com/sqlalchemy/alembic/tree/3452979f0d1fcd42f0a8311642f6ee4e70d6f95c/docs/build/unreleased for examples

sqla-tester commented 9 months ago

New Gerrit review created for change 3ce8e83c725373a7a73ca933ca13b98dbad63b8f: https://gerrit.sqlalchemy.org/c/sqlalchemy/alembic/+/5082

sqla-tester commented 9 months ago

Patchset ff59fa59861487cee1943090acc970d9a64f7e96 added to existing Gerrit review https://gerrit.sqlalchemy.org/c/sqlalchemy/alembic/+/5082

saifelse commented 9 months ago

Thanks, could you add a changelog file too?

See https://github.com/sqlalchemy/alembic/tree/3452979f0d1fcd42f0a8311642f6ee4e70d6f95c/docs/build/unreleased for examples

Done!

sqla-tester commented 8 months ago

Michael Bayer (zzzeek) wrote:

thank you!

View this in Gerrit at https://gerrit.sqlalchemy.org/c/sqlalchemy/alembic/+/5082

sqla-tester commented 8 months ago

Gerrit review https://gerrit.sqlalchemy.org/c/sqlalchemy/alembic/+/5082 has been merged. Congratulations! :)