RuntimeError: Cannot locate a COMSPEC environment variable... with os.popen on Windows

Issue #359 on hold
Cosimo Lupo
created an issue

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'