Repository: tox-dev/tox (python)

Issue:
RuntimeError: Cannot locate a COMSPEC environment variable... with os.popen on Windows
- Bitbucket: https://bitbucket.org/hpk42/tox/issue/359
- Originally reported by: @anthrotype
- Originally created at: 2016-08-16T13:27:03.478


The distutils cygwinccompiler.py uses `os.popen`, which seems to require the %COMSPEC% environment variable to be set, else it raises a runtime error (see traceback below).

If I use `passenv = COMSPEC` in my tox.ini, then it works fine.
The value of the variable on my system is the default `C:\Windows\system32\cmd.exe`.

Thanks,

Cosimo

```
py27 runtests: commands[2] | python setup.py test
running pytest
running egg_info
writing top-level names to src/python\compreffor.egg-info\top_level.txt
writing dependency_links to src/python\compreffor.egg-info\dependency_links.txt
writing src/python\compreffor.egg-info\PKG-INFO
reading manifest file 'src/python\compreffor.egg-info\SOURCES.txt'
reading manifest template 'MANIFEST.in'
writing manifest file 'src/python\compreffor.egg-info\SOURCES.txt'
running build_ext
Traceback (most recent call last):
  File "setup.py", line 168, in <module>
    setup(**setup_params)
  File "C:\Python27-mingwpy\Lib\distutils\core.py", line 151, in setup
    dist.run_commands()
  File "C:\Python27-mingwpy\Lib\distutils\dist.py", line 953, in run_commands
    self.run_command(cmd)
  File "C:\Python27-mingwpy\Lib\distutils\dist.py", line 972, in run_command
    cmd_obj.run()
  File "build\bdist.win32\egg\ptr.py", line 85, in run
  File "C:\UsersLocal\cosimo.lupo\Documents\GitHub\compreffor\.tox\py27\lib\site-packages\setuptools\command\test.py", line 111, in with_project_on_sys_path
    with self.project_on_sys_path():
  File "C:\Python27-mingwpy\Lib\contextlib.py", line 17, in __enter__
    return self.gen.next()
  File "C:\UsersLocal\cosimo.lupo\Documents\GitHub\compreffor\.tox\py27\lib\site-packages\setuptools\command\test.py", line 139, in project_on_sys_path
    self.run_command('build_ext')
  File "C:\Python27-mingwpy\Lib\distutils\cmd.py", line 326, in run_command
    self.distribution.run_command(command)
  File "C:\Python27-mingwpy\Lib\distutils\dist.py", line 972, in run_command
    cmd_obj.run()
  File "C:\UsersLocal\cosimo.lupo\Documents\GitHub\compreffor\.tox\py27\lib\site-packages\setuptools\command\build_ext.py", line 68, in run
    _build_ext.run(self)
  File "C:\Python27-mingwpy\Lib\distutils\command\build_ext.py", line 306, in run
    force=self.force)
  File "C:\Python27-mingwpy\Lib\distutils\ccompiler.py", line 1004, in new_compiler
    return klass(None, dry_run, force)
  File "C:\Python27-mingwpy\Lib\distutils\cygwinccompiler.py", line 306, in __init__
    CygwinCCompiler.__init__ (self, verbose, dry_run, force)
  File "C:\Python27-mingwpy\Lib\distutils\cygwinccompiler.py", line 107, in __init__
    get_versions()
  File "C:\Python27-mingwpy\Lib\distutils\cygwinccompiler.py", line 420, in get_versions
    out = os.popen(gcc_exe + ' -dumpversion','r')
RuntimeError: Cannot locate a COMSPEC environment variable to use as the shell
ERROR: InvocationError: 'C:\\UsersLocal\\cosimo.lupo\\Documents\\GitHub\\compreffor\\.tox\\py27\\Scripts\\python.EXE setup.py test'
```


Pull request description:
fix #359 -- add COMSPEC to passenv

Patch:
diff --git a/CHANGELOG b/CHANGELOG
index 63bfa8d3..25c691f7 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -8,6 +8,9 @@ unreleased
   tox -- "'some string'"  # can has to be written simply as 
   tox -- "some string"
 
+- fix #359: add COMSPEC to default passenv on windows.  Thanks
+  @anthrotype.
+
 - add support for py36 and py37 and add py36-dev and py37(nightly) to
   travis builds. Thanks John Vandenberg.
 
diff --git a/tox/config.py b/tox/config.py
index 40f64e20..38bfa1a9 100644
--- a/tox/config.py
+++ b/tox/config.py
@@ -474,6 +474,7 @@ def tox_addoption(parser):
             passenv.add("SYSTEMDRIVE")  # needed for pip6
             passenv.add("SYSTEMROOT")   # needed for python's crypto module
             passenv.add("PATHEXT")      # needed for discovering executables
+            passenv.add("COMSPEC")      # needed for distutils cygwincompiler
             passenv.add("TEMP")
             passenv.add("TMP")
         else:


Test patch:
diff --git a/tests/test_config.py b/tests/test_config.py
index 419d3321..c488f583 100644
--- a/tests/test_config.py
+++ b/tests/test_config.py
@@ -846,6 +846,7 @@ class TestConfigTestEnv:
             assert "PATHEXT" in envconfig.passenv
             assert "SYSTEMDRIVE" in envconfig.passenv
             assert "SYSTEMROOT" in envconfig.passenv
+            assert "COMSPEC" in envconfig.passenv
             assert "TEMP" in envconfig.passenv
             assert "TMP" in envconfig.passenv
         else: