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: environment can only contain strings #79

Closed
hborchardt opened this issue Nov 2, 2020 · 1 comment · Fixed by #80
Closed

Windows: environment can only contain strings #79

hborchardt opened this issue Nov 2, 2020 · 1 comment · Fixed by #80

Comments

@hborchardt
Copy link
Contributor

Upon install of stgit in a virtualenv in Windows, running stg show (or any command) throws the following error:

Error: Unhandled exception:
Traceback (most recent call last):
  File "C:\Users\hborchardt\.pyenv\pyenv-win\versions\3.8.3-amd64\lib\site-packages\stgit\main.py", line 188, in _main
    ret = command.func(parser, options, args)
  File "C:\Users\hborchardt\.pyenv\pyenv-win\versions\3.8.3-amd64\lib\site-packages\stgit\commands\series.py", line 194, in func
    stack = directory.repository.get_stack(options.branch)
  File "C:\Users\hborchardt\.pyenv\pyenv-win\versions\3.8.3-amd64\lib\site-packages\stgit\lib\stack.py", line 428, in get_stack
    name = self.current_branch_name
  File "C:\Users\hborchardt\.pyenv\pyenv-win\versions\3.8.3-amd64\lib\site-packages\stgit\lib\git\repository.py", line 223, in current_branch_name  
    return utils.strip_prefix('refs/heads/', self.head_ref)
  File "C:\Users\hborchardt\.pyenv\pyenv-win\versions\3.8.3-amd64\lib\site-packages\stgit\lib\git\repository.py", line 311, in head_ref
    return self.run(['git', 'symbolic-ref', '-q', 'HEAD']).output_one_line()
  File "C:\Users\hborchardt\.pyenv\pyenv-win\versions\3.8.3-amd64\lib\site-packages\stgit\run.py", line 254, in output_one_line
    outlines = self.output_lines(sep)
  File "C:\Users\hborchardt\.pyenv\pyenv-win\versions\3.8.3-amd64\lib\site-packages\stgit\run.py", line 245, in output_lines
    outdata = self._run_io()
  File "C:\Users\hborchardt\.pyenv\pyenv-win\versions\3.8.3-amd64\lib\site-packages\stgit\run.py", line 133, in _run_io
    p = subprocess.Popen(
  File "C:\Users\hborchardt\.pyenv\pyenv-win\versions\3.8.3-amd64\lib\subprocess.py", line 854, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "C:\Users\hborchardt\.pyenv\pyenv-win\versions\3.8.3-amd64\lib\subprocess.py", line 1307, in _execute_child
    hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
TypeError: environment can only contain strings

It can be quick-fixed on my system by replacing

def _prep_env(self):
with the following:

def _prep_env(self):
    return self._env

My understanding, also from reading this comment (https://bugzilla.mozilla.org/show_bug.cgi?id=1585258#c4)
is, that this is a relict from Python2, and as Stgit supports Python >=3.5, that the opposite of fsencode_utf8 is required, fsdecode_utf8. On Linux, both strings and bytes are accepted, but Windows needs the env to be strings.

Stgit version: master (c01b32a)
Python version: 3.8.3
OS: Windows 10-msys2

@hborchardt
Copy link
Contributor Author

Turns out that changing to fsdecode_utf8 only works for Python >= 3.7, where PEP 540 UTF-8-Mode is included, and all conversions are using utf-8 anyway. On Python 3.5/3.6, if there are non-ascii characters in environment variables they have to be passed as bytes, such that they don't get converted by os.fsencode using the ascii codec in subprocess.Popen (which is the reason for the fsencode_utf8 function in the first place). It seems to me that this is not resolvable without a special case for windows systems.

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 a pull request may close this issue.

1 participant