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
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
2c8949c
Use explicit cast to str for environment (for py2 on windows)
24e3046
Use encoding for command line args Windows Py2
3ac443f
Use text mode utf-8 for most I/O, not binary
3cf47a6
Extra git ignore
e457552
Fix tests when hg or git absent
0b9d7ca
Rework test_usage_string_fork
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,24 +12,32 @@ | |
except: | ||
from io import StringIO | ||
|
||
|
||
import argparse | ||
import codecs | ||
import io | ||
import os | ||
import platform | ||
import re | ||
import sre_constants | ||
import subprocess | ||
import sys | ||
import warnings | ||
import io | ||
from string import Formatter | ||
from datetime import datetime | ||
from difflib import unified_diff | ||
from tempfile import NamedTemporaryFile | ||
|
||
import sys | ||
import codecs | ||
|
||
from bumpversion.version_part import VersionPart, NumericVersionPartConfiguration, ConfiguredVersionPartConfiguration | ||
|
||
|
||
if platform.system() == 'Windows' and sys.version_info[0] == 2: | ||
def _command_args(args): | ||
return [a.encode("utf-8") for a in args] | ||
else: | ||
def _command_args(args): | ||
return args | ||
|
||
|
||
if sys.version_info[0] == 2: | ||
sys.stdout = codecs.getwriter('utf-8')(sys.stdout) | ||
|
||
|
@@ -64,6 +72,7 @@ def __call__(self, parser, namespace, values, option_string=None): | |
'utcnow': datetime.utcnow(), | ||
} | ||
|
||
|
||
class BaseVCS(object): | ||
|
||
@classmethod | ||
|
@@ -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 commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. f is a temporary file, and its name is ascii |
||
except subprocess.CalledProcessError as exc: | ||
|
@@ -153,7 +162,7 @@ def latest_tag_info(cls): | |
|
||
@classmethod | ||
def add_path(cls, path): | ||
subprocess.check_output(["git", "add", "--update", path]) | ||
subprocess.check_output(_command_args(["git", "add", "--update", path])) | ||
|
||
@classmethod | ||
def tag(cls, sign, name, message): | ||
|
@@ -162,7 +171,7 @@ def tag(cls, sign, name, message): | |
command += ['-s'] | ||
if message: | ||
command += ['--message', message] | ||
subprocess.check_output(command) | ||
subprocess.check_output(_command_args(command)) | ||
|
||
|
||
class Mercurial(BaseVCS): | ||
|
@@ -201,7 +210,7 @@ def tag(cls, sign, name, message): | |
) | ||
if message: | ||
command += ['--message', message] | ||
subprocess.check_output(command) | ||
subprocess.check_output(_command_args(command)) | ||
|
||
VCS = [Git, Mercurial] | ||
|
||
|
@@ -233,12 +242,12 @@ def should_contain_version(self, version, context): | |
assert False, msg | ||
|
||
def contains(self, search): | ||
with io.open(self.path, 'rb') as f: | ||
with io.open(self.path, 'rt', encoding='utf-8') as f: | ||
search_lines = search.splitlines() | ||
lookbehind = [] | ||
|
||
for lineno, line in enumerate(f.readlines()): | ||
lookbehind.append(line.decode('utf-8').rstrip("\n")) | ||
lookbehind.append(line.rstrip("\n")) | ||
|
||
if len(lookbehind) > len(search_lines): | ||
lookbehind = lookbehind[1:] | ||
|
@@ -247,14 +256,14 @@ def contains(self, search): | |
search_lines[-1] in lookbehind[-1] and | ||
search_lines[1:-1] == lookbehind[1:-1]): | ||
logger.info("Found '{}' in {} at line {}: {}".format( | ||
search, self.path, lineno - (len(lookbehind) - 1), line.decode('utf-8').rstrip())) | ||
search, self.path, lineno - (len(lookbehind) - 1), line.rstrip())) | ||
return True | ||
return False | ||
|
||
def replace(self, current_version, new_version, context, dry_run): | ||
|
||
with io.open(self.path, 'rb') as f: | ||
file_content_before = f.read().decode('utf-8') | ||
with io.open(self.path, 'rt', encoding='utf-8') as f: | ||
file_content_before = f.read() | ||
|
||
context['current_version'] = self._versionconfig.serialize(current_version, context) | ||
context['new_version'] = self._versionconfig.serialize(new_version, context) | ||
|
@@ -292,8 +301,8 @@ def replace(self, current_version, new_version, context, dry_run): | |
)) | ||
|
||
if not dry_run: | ||
with io.open(self.path, 'wb') as f: | ||
f.write(file_content_after.encode('utf-8')) | ||
with io.open(self.path, 'wt', encoding='utf-8') as f: | ||
f.write(file_content_after) | ||
|
||
def __str__(self): | ||
return self.path | ||
|
@@ -892,8 +901,8 @@ def main(original_args=None): | |
logger.info(new_config.getvalue()) | ||
|
||
if write_to_config_file: | ||
with io.open(config_file, 'wb') as f: | ||
f.write(new_config.getvalue().encode('utf-8')) | ||
with io.open(config_file, 'wt', encoding='utf-8') as f: | ||
f.write(new_config.getvalue()) | ||
|
||
except UnicodeEncodeError: | ||
warnings.warn( | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.