c4urself / bump2version

Version-bump your software with a single command
https://pypi.python.org/pypi/bump2version
MIT License
1.06k stars 134 forks source link

`TypeError: environment can only contain strings` on Windows 10 #11

Closed jorgerodriguezveiga closed 6 years ago

jorgerodriguezveiga commented 6 years ago

I got an error working on Windows 10 with python 3.6.3, bump2version v0.5.7.

The traceback message is:

Traceback (most recent call last):
  File "c:\program files (x86)\python36-32\lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "c:\program files (x86)\python36-32\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "C:\Program Files (x86)\Python36-32\Scripts\bump2version.exe\__main__.py", line 9, in <module>
  File "c:\program files (x86)\python36-32\lib\site-packages\bumpversion\__init__.py", line 938, in main
    vcs.commit(message=commit_message)
  File "c:\program files (x86)\python36-32\lib\site-packages\bumpversion\__init__.py", line 75, in commit
    list(os.environ.items()) + [(b'HGENCODING', b'utf-8')]
  File "c:\program files (x86)\python36-32\lib\subprocess.py", line 336, in check_output
    **kwargs).stdout
  File "c:\program files (x86)\python36-32\lib\subprocess.py", line 403, in run
    with Popen(*popenargs, **kwargs) as process:
  File "c:\program files (x86)\python36-32\lib\subprocess.py", line 709, in __init__
    restore_signals, start_new_session)
  File "c:\program files (x86)\python36-32\lib\subprocess.py", line 997, in _execute_child
    startupinfo)
TypeError: environment can only contain strings

Actually, I solved the issue changing the class BaseVCS in __init__.py as follows:

class BaseVCS(object):

    @classmethod
    def commit(cls, message):
        f = NamedTemporaryFile('wb', delete=False)
        f.write(message.encode('utf-8'))
        f.close()
        subprocess.check_output(cls._COMMIT_COMMAND + [f.name], env=dict(
            [i for i in os.environ.items()] + [(u'HGENCODING', u'utf-8')]
        ))
        os.unlink(f.name)

    @classmethod
    def is_usable(cls):
        try:
            return subprocess.call(
                cls._TEST_USABLE_COMMAND,
                stderr=subprocess.PIPE,
                stdout=subprocess.PIPE
            ) == 0
        except OSError as e:
            if e.errno == 2:
                # mercurial is not installed then, ok.
                return False
            raise

As you can see, I only changed the params for subprocess.check_output:

        subprocess.check_output(cls._COMMIT_COMMAND + [f.name], env=dict(
            [i for i in os.environ.items()] + [(u'HGENCODING', u'utf-8')]
lansman commented 6 years ago

Same issue. Python 3.6.5. Windows 10. bump2version 0.5.7 (latest on 06.04.2018)

c4urself commented 6 years ago

This should work now with version 0.5.8, please reopen if that's not the case.