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

Add dedent that sets line endings #49291

Merged
merged 4 commits into from Aug 27, 2018

Conversation

Projects
None yet
4 participants
@dwoz
Contributor

dwoz commented Aug 23, 2018

What does this PR do?

Add dedent helper that sets line endings

Tests written?

No

Commits signed with GPG?

Yes

@dwoz dwoz requested review from twangboy and terminalmage Aug 23, 2018

@dwoz

This comment has been minimized.

Contributor

dwoz commented Aug 23, 2018

@dwoz dwoz changed the title from Add dedent that sets line endings to [WIP] Add dedent that sets line endings Aug 23, 2018

dwoz added some commits Aug 22, 2018

@dwoz

This comment has been minimized.

Contributor

dwoz commented Aug 24, 2018

The dedent method was not preserving trailing newlines. I also found an issue with passing it bytes on python 3. Testing the fix now.

Re-factor dedent to fix warts
- textwarp.dedent does not support bytes on py3
- make sure to preserve trailing newlines

@dwoz dwoz force-pushed the dwoz:dedent branch from 497c833 to 6abc2da Aug 24, 2018

@dwoz dwoz changed the title from [WIP] Add dedent that sets line endings to Add dedent that sets line endings Aug 24, 2018

@dwoz

This comment has been minimized.

Contributor

dwoz commented Aug 26, 2018

@terminalmage Does this one look good to you?

linesep = salt.utils.to_unicode(linesep)
unicode_text = textwrap.dedent(salt.utils.to_unicode(text))
clean_text = linesep.join(unicode_text.splitlines())
if unicode_text.endswith(salt.utils.to_unicode('\n')):

This comment has been minimized.

@terminalmage

terminalmage Aug 26, 2018

Member

to_unicode isn't really necessary here, since the newline character is part of the ASCII set. You can just use u'\n' instead.

unicode_text = textwrap.dedent(salt.utils.to_unicode(text))
clean_text = linesep.join(unicode_text.splitlines())
if unicode_text.endswith(salt.utils.to_unicode('\n')):
clean_text = clean_text + linesep

This comment has been minimized.

@terminalmage

terminalmage Aug 26, 2018

Member

The += operator can be used here.

@dwoz dwoz merged commit 81428ed into saltstack:2017.7 Aug 27, 2018

8 checks passed

WIP ready for review
Details
continuous-integration/jenkins/pr-merge This commit looks good
Details
jenkins/pr/docs The docs job has passed
Details
jenkins/pr/lint The lint job has passed
Details
jenkins/pr/py2-centos-7 The py2-centos-7 job has passed
Details
jenkins/pr/py2-ubuntu-1604 The py2-ubuntu-1604 job has passed
Details
jenkins/pr/py3-centos-7 The py3-centos-7 job has passed
Details
jenkins/pr/py3-ubuntu-1604 The py3-ubuntu-1604 job has passed
Details

rallytime added a commit that referenced this pull request Aug 31, 2018

@dwoz dwoz deleted the dwoz:dedent branch Sep 17, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment