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

Windows behavior fixed, with appveyor tests passing (B) #34

Merged
merged 6 commits into from Aug 29, 2018

Conversation

jeremycarroll
Copy link
Contributor

@jeremycarroll jeremycarroll commented Aug 27, 2018

This replaces my previous PR on this topic, with cleaned up commit history, and no longer and extra xfail.

This PR fixes issues on the Windows platform, particularly python2, revealed in the appveyor test failures.
In particular, encoding when making external calls with subprocess was usually incorrect.

Two specific changes on py2:

use strings not unicode to add to the environment before making subprocess calls
encode any non-ascii command line arguments (particularly →) in utf-8 before making the call.
A third change for both py2 and py3 is to change the file operations to text mode rather than binary mode, which simplifies handling of encoding.

In the tests, two further issues were addressed:

incorrect handling when hg (or presumably git) is absent (this issue was not visible on appveyor, but locally to me)
test_usage_string_fork changed to not explicit encode, and to use byte strings instead; xfailing in the most difficult case to fix: Windows on py3.
NB: I don't have a windows machine, so I am entirely reliant on appveyor for above analysis.

Concerning test_usage_string_fork. This would fail in python3 on windows, except for the additional code for that case, which provides a .bumpversion.cfg file which replaces the unicode character with the ascii string to in the tag message and the commit message. Without this, I think there is a genuine defect (although I don't have a Windows machine) in which the -h option attempts to print out this character as part of the help message and fails. Essentially bumpversion assumes unicode support, and the workaround at least is to change those two strings explicitly in the .bumpversion.cfg or on the command line.

@jeremycarroll jeremycarroll changed the title Appveyor fixes b Windows behavior fixed, with appveyor tests passing (B) Aug 27, 2018
from bumpversion.version_part import VersionPart, NumericVersionPartConfiguration, ConfiguredVersionPartConfiguration


if platform.system() == 'Windows' and sys.version_info[0] == 2:
def _command_args(args):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Would it make sense to introduce a subprocess.check_output wrapper that does this instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That might be more readable, I was just going for as precise a change as needed.

@@ -72,7 +81,7 @@ def commit(cls, message):
f.write(message.encode('utf-8'))
f.close()
env = os.environ.copy()
env['HGENCODING'] = 'utf-8'
env[str('HGENCODING')] = str('utf-8')
try:
subprocess.check_output(cls._COMMIT_COMMAND + [f.name], env=env)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Odd that this dosen't need encoding.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

f is a temporary file, and its name is ascii

@ekohl ekohl mentioned this pull request Aug 29, 2018
@c4urself
Copy link
Owner

Thanks @jeremycarroll -- merging this in.

@c4urself c4urself merged commit c974b85 into c4urself:master Aug 29, 2018
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.

None yet

3 participants