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
Conversation
from bumpversion.version_part import VersionPart, NumericVersionPartConfiguration, ConfiguredVersionPartConfiguration | ||
|
||
|
||
if platform.system() == 'Windows' and sys.version_info[0] == 2: | ||
def _command_args(args): |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
Thanks @jeremycarroll -- merging this in. |
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 stringto
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. Essentiallybumpversion
assumes unicode support, and the workaround at least is to change those two strings explicitly in the.bumpversion.cfg
or on the command line.