Skip to content

Commit

Permalink
Merge pull request #326 from enthought/fix/remove-toolkit-commandline…
Browse files Browse the repository at this point in the history
…-option

Remove command-line option for setting toolkit
  • Loading branch information
mdickinson committed Sep 2, 2016
2 parents e7a83cf + b121dda commit 3241611
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 72 deletions.
26 changes: 3 additions & 23 deletions traits/etsconfig/etsconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ def _set_company(self, company):
def provisional_toolkit(self, toolkit):
""" Perform an operation with toolkit provisionally set
This sets the toolkit attribute of the ETSConfig object set to the
This sets the toolkit attribute of the ETSConfig object to the
provided value. If the operation fails with an exception, the toolkit
is reset to nothing.
Expand Down Expand Up @@ -245,8 +245,7 @@ def provisional_toolkit(self, toolkit):
def _get_toolkit(self):
"""
Property getter for the GUI toolkit. The value returned is, in order
of preference: the value set by the application; the value passed on
the command line using the '-toolkit' option; the value specified by
of preference: the value set by the application; the value specified by
the 'ETS_TOOLKIT' environment variable; otherwise the empty string.
"""
Expand Down Expand Up @@ -282,8 +281,7 @@ def _get_enable_toolkit(self):
Deprecated: This property is no longer used.
Property getter for the Enable backend. The value returned is, in order
of preference: the value set by the application; the value passed on
the command line using the '-toolkit' option; the value specified by
of preference: the value set by the application; the value specified by
the 'ENABLE_TOOLKIT' environment variable; otherwise the empty string.
"""
from warnings import warn
Expand Down Expand Up @@ -461,26 +459,8 @@ def _initialize_toolkit(self):
Initializes the toolkit.
"""
# We handle the command line option even though it doesn't have the
# highest precedence because we always want to remove it from the
# command line.
if '-toolkit' in sys.argv:
opt_idx = sys.argv.index('-toolkit')

try:
opt_toolkit = sys.argv[opt_idx + 1]
except IndexError:
raise ValueError, "the -toolkit command line argument must be followed by a toolkit name"

# Remove the option.
del sys.argv[opt_idx:opt_idx + 2]
else:
opt_toolkit = None

if self._toolkit is not None:
toolkit = self._toolkit
elif opt_toolkit is not None:
toolkit = opt_toolkit
else:
toolkit = os.environ.get('ETS_TOOLKIT', '')

Expand Down
30 changes: 1 addition & 29 deletions traits/etsconfig/tests/test_etsconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,20 +223,6 @@ def _test_default_application_home(self):
self.assertEqual(dirname, self.ETSConfig.application_data)
self.assertEqual(app_name, 'tests')

def test_toolkit_argv(self):
test_args = ['something', '-toolkit', 'test', 'something_else']
with mock_sys_argv(test_args):
toolkit = self.ETSConfig.toolkit

self.assertEqual(toolkit, 'test')
self.assertEqual(test_args, ['something', 'something_else'])

def test_toolkit_argv_missing(self):
test_args = ['something', '-toolkit']
with mock_sys_argv(test_args):
with self.assertRaises(ValueError):
self.ETSConfig.toolkit

def test_toolkit_environ(self):
test_args = ['something']
test_environ = {'ETS_TOOLKIT': 'test'}
Expand All @@ -255,18 +241,8 @@ def test_toolkit_environ_missing(self):

self.assertEqual(toolkit, '')

def test_toolkit_argv_wins(self):
test_args = ['something', '-toolkit', 'test_args', 'something_else']
test_environ = {'ETS_TOOLKIT': 'test_environ'}
with mock_sys_argv(test_args):
with mock_os_environ(test_environ):
toolkit = self.ETSConfig.toolkit

self.assertEqual(toolkit, 'test_args')
self.assertEqual(test_args, ['something', 'something_else'])

def test_set_toolkit(self):
test_args = ['something', '-toolkit', 'test_args', 'something_else']
test_args = []
test_environ = {'ETS_TOOLKIT': 'test_environ'}

with mock_sys_argv(test_args):
Expand All @@ -275,10 +251,6 @@ def test_set_toolkit(self):
toolkit = self.ETSConfig.toolkit

self.assertEqual(toolkit, 'test_direct')
# XXX this is a bit of a dodgy outcome...
self.assertEqual(test_args,
['something', '-toolkit', 'test_args',
'something_else'])

def test_provisional_toolkit(self):
test_args = []
Expand Down
20 changes: 0 additions & 20 deletions traits/trait_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ def _get_toolkit ( self ):
"""
Property getter for the GUI toolkit. The value returned is, in
order of preference: the value set by the application; the value
passed on the command line using the '-toolkit' option; the value
specified by the 'ETS_TOOLKIT' environment variable; otherwise the
empty string.
"""
Expand Down Expand Up @@ -161,27 +160,8 @@ def _initialize_application_data ( self ):
def _initialize_toolkit ( self ):
""" Initializes the toolkit.
"""
# We handle the command line option even though it doesn't have the
# highest precedence because we always want to remove it from the
# command line:
if '-toolkit' in sys.argv:
opt_idx = sys.argv.index( '-toolkit' )

try:
opt_toolkit = sys.argv[ opt_idx + 1 ]
except IndexError:
raise ValueError( 'The -toolkit command line argument must '
'be followed by a toolkit name' )

# Remove the option:
del sys.argv[ opt_idx: opt_idx + 1 ]
else:
opt_toolkit = None

if self._toolkit is not None:
toolkit = self._toolkit
elif opt_toolkit is not None:
toolkit = opt_toolkit
else:
toolkit = os.environ.get( 'ETS_TOOLKIT', '' )

Expand Down

0 comments on commit 3241611

Please sign in to comment.