Skip to content

Commit fc75e0f

Browse files
committed
raise error when trying to run Xvfb on Mac. close #1400
1 parent 46dff1c commit fc75e0f

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

nipype/utils/config.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
'''
1212
from __future__ import print_function, division, unicode_literals, absolute_import
1313
import os
14+
import sys
1415
import errno
1516
import atexit
1617
from warnings import warn
@@ -284,6 +285,14 @@ def _mock():
284285
self._display = Xvfb(ndisp, _mock)
285286
return sysdisplay
286287
else:
288+
if 'darwin' in sys.platform:
289+
raise RuntimeError(
290+
'Xvfb requires root permissions to run in OSX. Please '
291+
'make sure that an X server is listening and set the '
292+
'appropriate config on either $DISPLAY or nipype\'s '
293+
'"display_variable" config. Valid X servers include '
294+
'VNC, XQuartz, or manually started Xvfb.')
295+
287296
# If $DISPLAY is empty, it confuses Xvfb so unset
288297
if sysdisplay == '':
289298
del os.environ['DISPLAY']

nipype/utils/tests/test_config.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,3 +108,15 @@ def test_display_empty_installed(monkeypatch):
108108
config._config.remove_option('execution', 'display_variable')
109109
monkeypatch.setitem(os.environ, 'DISPLAY', '')
110110
assert int(config.get_display().split(':')[-1]) > 1000
111+
112+
113+
def test_display_empty_macosx(monkeypatch):
114+
"""Check that when no display is specified, a virtual Xvfb is used"""
115+
config._display = None
116+
if config.has_option('execution', 'display_variable'):
117+
config._config.remove_option('execution', 'display_variable')
118+
monkeypatch.delitem(os.environ, 'DISPLAY', '')
119+
120+
monkeypatch.setattr(sys, 'platform', 'darwin')
121+
with pytest.raises(RuntimeError):
122+
config.get_display()

0 commit comments

Comments
 (0)