##// END OF EJS Templates
aliases match flag pattern ('-' as wordsep, not '_')...
MinRK -
Show More
@@ -111,7 +111,7 b' class Application(SingletonConfigurable):'
111 111 self.log.setLevel(new)
112 112
113 113 # the alias map for configurables
114 aliases = Dict(dict(log_level='Application.log_level'))
114 aliases = Dict({'log-level' : 'Application.log_level'})
115 115
116 116 # flags for loading Configurables or store_const style flags
117 117 # flags are loaded from this dict by '--key' flags
@@ -24,6 +24,7 b' import sys'
24 24
25 25 from IPython.external import argparse
26 26 from IPython.utils.path import filefind, get_ipython_dir
27 from IPython.utils import warn
27 28
28 29 #-----------------------------------------------------------------------------
29 30 # Exceptions
@@ -325,7 +326,22 b' class CommandLineConfigLoader(ConfigLoader):'
325 326 here.
326 327 """
327 328
328 kv_pattern = re.compile(r'\-\-[A-Za-z]\w*(\.\w+)*\=.*')
329 # raw --identifier=value pattern
330 # but *also* accept '-' as wordsep, for aliases
331 # accepts: --foo=a
332 # --Class.trait=value
333 # --alias-name=value
334 # rejects: -foo=value
335 # --foo
336 # --Class.trait
337 kv_pattern = re.compile(r'\-\-[A-Za-z][\w\-]*(\.[\w\-]+)*\=.*')
338
339 # just flags, no assignments, with two *or one* leading '-'
340 # accepts: --foo
341 # -foo-bar-again
342 # rejects: --anything=anything
343 # --two.word
344
329 345 flag_pattern = re.compile(r'\-\-?\w+[\-\w]*$')
330 346
331 347 class KeyValueConfigLoader(CommandLineConfigLoader):
@@ -364,8 +380,8 b' class KeyValueConfigLoader(CommandLineConfigLoader):'
364 380
365 381 >>> from IPython.config.loader import KeyValueConfigLoader
366 382 >>> cl = KeyValueConfigLoader()
367 >>> cl.load_config(["--foo='bar'","--A.name='brian'","--B.number=0"])
368 {'A': {'name': 'brian'}, 'B': {'number': 0}, 'foo': 'bar'}
383 >>> cl.load_config(["--A.name='brian'","--B.number=0"])
384 {'A': {'name': 'brian'}, 'B': {'number': 0}}
369 385 """
370 386 self.clear()
371 387 if argv is None:
@@ -444,6 +460,9 b' class KeyValueConfigLoader(CommandLineConfigLoader):'
444 460 # Substitute longnames for aliases.
445 461 if lhs in aliases:
446 462 lhs = aliases[lhs]
463 if '.' not in lhs:
464 # probably a mistyped alias, but not technically illegal
465 warn.warn("Unrecognized alias: '%s', it will probably have no effect."%lhs)
447 466 exec_str = 'self.config.' + lhs + '=' + rhs
448 467 try:
449 468 # Try to see if regular Python syntax will work. This
@@ -55,8 +55,13 b' class MyApp(Application):'
55 55 config_file = Unicode(u'', config=True,
56 56 help="Load this config file")
57 57
58 aliases = Dict(dict(i='Foo.i',j='Foo.j',name='Foo.name',
59 enabled='Bar.enabled', log_level='MyApp.log_level'))
58 aliases = Dict({
59 'i' : 'Foo.i',
60 'j' : 'Foo.j',
61 'name' : 'Foo.name',
62 'enabled' : 'Bar.enabled',
63 'log-level' : 'MyApp.log_level',
64 })
60 65
61 66 flags = Dict(dict(enable=({'Bar': {'enabled' : True}}, "Set Bar.enabled to True"),
62 67 disable=({'Bar': {'enabled' : False}}, "Set Bar.enabled to False")))
@@ -79,7 +84,7 b' class TestApplication(TestCase):'
79 84
80 85 def test_config(self):
81 86 app = MyApp()
82 app.parse_command_line(["--i=10","--Foo.j=10","--enabled=False","--log_level=50"])
87 app.parse_command_line(["--i=10","--Foo.j=10","--enabled=False","--log-level=50"])
83 88 config = app.config
84 89 self.assertEquals(config.Foo.i, 10)
85 90 self.assertEquals(config.Foo.j, 10)
@@ -88,7 +93,7 b' class TestApplication(TestCase):'
88 93
89 94 def test_config_propagation(self):
90 95 app = MyApp()
91 app.parse_command_line(["--i=10","--Foo.j=10","--enabled=False","--log_level=50"])
96 app.parse_command_line(["--i=10","--Foo.j=10","--enabled=False","--log-level=50"])
92 97 app.init_foo()
93 98 app.init_bar()
94 99 self.assertEquals(app.foo.i, 10)
@@ -27,6 +27,8 b' from unittest import TestCase'
27 27
28 28 from nose import SkipTest
29 29
30 from IPython.testing.tools import mute_warn
31
30 32 from IPython.utils.traitlets import Int, Unicode
31 33 from IPython.config.configurable import Configurable
32 34 from IPython.config.loader import (
@@ -120,6 +122,7 b' class TestKeyValueCL(TestCase):'
120 122 def test_basic(self):
121 123 cl = KeyValueConfigLoader()
122 124 argv = ['--'+s.strip('c.') for s in pyfile.split('\n')[2:-1]]
125 with mute_warn():
123 126 config = cl.load_config(argv)
124 127 self.assertEquals(config.a, 10)
125 128 self.assertEquals(config.b, 20)
@@ -129,16 +132,19 b' class TestKeyValueCL(TestCase):'
129 132
130 133 def test_extra_args(self):
131 134 cl = KeyValueConfigLoader()
135 with mute_warn():
132 136 config = cl.load_config(['--a=5', 'b', '--c=10', 'd'])
133 137 self.assertEquals(cl.extra_args, ['b', 'd'])
134 138 self.assertEquals(config.a, 5)
135 139 self.assertEquals(config.c, 10)
140 with mute_warn():
136 141 config = cl.load_config(['--', '--a=5', '--c=10'])
137 142 self.assertEquals(cl.extra_args, ['--a=5', '--c=10'])
138 143
139 144 def test_unicode_args(self):
140 145 cl = KeyValueConfigLoader()
141 146 argv = [u'--a=épsîlön']
147 with mute_warn():
142 148 config = cl.load_config(argv)
143 149 self.assertEquals(config.a, u'épsîlön')
144 150
@@ -150,6 +156,7 b' class TestKeyValueCL(TestCase):'
150 156 raise SkipTest("sys.stdin.encoding can't handle 'é'")
151 157
152 158 cl = KeyValueConfigLoader()
159 with mute_warn():
153 160 config = cl.load_config([barg])
154 161 self.assertEquals(config.a, u'é')
155 162
@@ -52,11 +52,11 b' from IPython.utils.traitlets import List, Unicode, Type, Bool, Dict'
52 52
53 53 # aliases and flags
54 54
55 base_aliases = dict(
56 profile='BaseIPythonApplication.profile',
57 ipython_dir='BaseIPythonApplication.ipython_dir',
58 log_level='Application.log_level',
59 )
55 base_aliases = {
56 'profile' : 'BaseIPythonApplication.profile',
57 'ipython-dir' : 'BaseIPythonApplication.ipython_dir',
58 'log-level' : 'Application.log_level',
59 }
60 60
61 61 base_flags = dict(
62 62 debug = ({'Application' : {'log_level' : logging.DEBUG}},
@@ -84,13 +84,13 b' class ProfileList(Application):'
84 84 name = u'ipython-profile'
85 85 description = list_help
86 86
87 aliases = Dict(dict(
88 ipython_dir = 'ProfileList.ipython_dir',
89 log_level = 'Application.log_level',
90 ))
87 aliases = Dict({
88 'ipython-dir' : 'ProfileList.ipython_dir',
89 'log-level' : 'Application.log_level',
90 })
91 91 flags = Dict(dict(
92 92 debug = ({'Application' : {'log_level' : 0}},
93 "Set log_level to 0, maximizing log output."
93 "Set Application.log_level to 0, maximizing log output."
94 94 )
95 95 ))
96 96 ipython_dir = Unicode(get_ipython_dir(), config=True,
@@ -90,13 +90,13 b' shell_flags[\'nosep\']=(nosep_config, "Eliminate all spacing between prompts.")'
90 90 # it's possible we don't want short aliases for *all* of these:
91 91 shell_aliases = dict(
92 92 autocall='InteractiveShell.autocall',
93 cache_size='InteractiveShell.cache_size',
94 93 colors='InteractiveShell.colors',
95 94 logfile='InteractiveShell.logfile',
96 95 logappend='InteractiveShell.logappend',
97 96 c='InteractiveShellApp.code_to_run',
98 97 ext='InteractiveShellApp.extra_extension',
99 98 )
99 shell_aliases['cache-size'] = 'InteractiveShell.cache_size'
100 100
101 101 #-----------------------------------------------------------------------------
102 102 # Main classes and functions
@@ -96,11 +96,11 b' class ParallelCrashHandler(CrashHandler):'
96 96 base_aliases = {}
97 97 base_aliases.update(base_ip_aliases)
98 98 base_aliases.update({
99 'profile_dir' : 'ProfileDir.location',
100 'work_dir' : 'BaseParallelApplication.work_dir',
101 'log_to_file' : 'BaseParallelApplication.log_to_file',
102 'clean_logs' : 'BaseParallelApplication.clean_logs',
103 'log_url' : 'BaseParallelApplication.log_url',
99 'profile-dir' : 'ProfileDir.location',
100 'work-dir' : 'BaseParallelApplication.work_dir',
101 'log-to-file' : 'BaseParallelApplication.log_to_file',
102 'clean-logs' : 'BaseParallelApplication.clean_logs',
103 'log-url' : 'BaseParallelApplication.log_url',
104 104 })
105 105
106 106 base_flags = {
@@ -321,9 +321,9 b' start_aliases = {}'
321 321 start_aliases.update(engine_aliases)
322 322 start_aliases.update(dict(
323 323 delay='IPClusterStart.delay',
324 clean_logs='IPClusterStart.clean_logs',
325 324 controller = 'IPClusterStart.controller_launcher_class',
326 325 ))
326 start_aliases['clean-logs'] = 'IPClusterStart.clean_logs'
327 327
328 328 class IPClusterStart(IPClusterEngines):
329 329
@@ -111,15 +111,13 b" flags.update(boolean_flag('secure', 'IPControllerApp.secure',"
111 111 "Don't authenticate messages."
112 112 ))
113 113 aliases = dict(
114 reuse_files = 'IPControllerApp.reuse_files',
115 114 secure = 'IPControllerApp.secure',
116 115 ssh = 'IPControllerApp.ssh_server',
117 use_threads = 'IPControllerApp.use_threads',
118 116 location = 'IPControllerApp.location',
119 117
120 118 ident = 'Session.session',
121 119 user = 'Session.username',
122 exec_key = 'Session.keyfile',
120 keyfile = 'Session.keyfile',
123 121
124 122 url = 'HubFactory.url',
125 123 ip = 'HubFactory.ip',
@@ -111,7 +111,7 b' aliases = dict('
111 111
112 112 ident = 'Session.session',
113 113 user = 'Session.username',
114 exec_key = 'Session.keyfile',
114 keyfile = 'Session.keyfile',
115 115
116 116 url = 'EngineFactory.url',
117 117 ip = 'EngineFactory.ip',
@@ -323,7 +323,7 b' class LocalControllerLauncher(LocalProcessLauncher):'
323 323 controller_cmd = List(ipcontroller_cmd_argv, config=True,
324 324 help="""Popen command to launch ipcontroller.""")
325 325 # Command line arguments to ipcontroller.
326 controller_args = List(['--log-to-file','--log_level=%i'%logging.INFO], config=True,
326 controller_args = List(['--log-to-file','--log-level=%i'%logging.INFO], config=True,
327 327 help="""command-line args to pass to ipcontroller""")
328 328
329 329 def find_args(self):
@@ -331,7 +331,7 b' class LocalControllerLauncher(LocalProcessLauncher):'
331 331
332 332 def start(self, profile_dir):
333 333 """Start the controller by profile_dir."""
334 self.controller_args.extend(['--profile_dir=%s'%profile_dir])
334 self.controller_args.extend(['--profile-dir=%s'%profile_dir])
335 335 self.profile_dir = unicode(profile_dir)
336 336 self.log.info("Starting LocalControllerLauncher: %r" % self.args)
337 337 return super(LocalControllerLauncher, self).start()
@@ -343,7 +343,7 b' class LocalEngineLauncher(LocalProcessLauncher):'
343 343 engine_cmd = List(ipengine_cmd_argv, config=True,
344 344 help="""command to launch the Engine.""")
345 345 # Command line arguments for ipengine.
346 engine_args = List(['--log-to-file','--log_level=%i'%logging.INFO], config=True,
346 engine_args = List(['--log-to-file','--log-level=%i'%logging.INFO], config=True,
347 347 help="command-line arguments to pass to ipengine"
348 348 )
349 349
@@ -352,7 +352,7 b' class LocalEngineLauncher(LocalProcessLauncher):'
352 352
353 353 def start(self, profile_dir):
354 354 """Start the engine by profile_dir."""
355 self.engine_args.extend(['--profile_dir=%s'%profile_dir])
355 self.engine_args.extend(['--profile-dir=%s'%profile_dir])
356 356 self.profile_dir = unicode(profile_dir)
357 357 return super(LocalEngineLauncher, self).start()
358 358
@@ -362,7 +362,7 b' class LocalEngineSetLauncher(BaseLauncher):'
362 362
363 363 # Command line arguments for ipengine.
364 364 engine_args = List(
365 ['--log-to-file','--log_level=%i'%logging.INFO], config=True,
365 ['--log-to-file','--log-level=%i'%logging.INFO], config=True,
366 366 help="command-line arguments to pass to ipengine"
367 367 )
368 368 # launcher class
@@ -468,14 +468,14 b' class MPIExecControllerLauncher(MPIExecLauncher):'
468 468 controller_cmd = List(ipcontroller_cmd_argv, config=True,
469 469 help="Popen command to launch the Contropper"
470 470 )
471 controller_args = List(['--log-to-file','--log_level=%i'%logging.INFO], config=True,
471 controller_args = List(['--log-to-file','--log-level=%i'%logging.INFO], config=True,
472 472 help="Command line arguments to pass to ipcontroller."
473 473 )
474 474 n = Int(1)
475 475
476 476 def start(self, profile_dir):
477 477 """Start the controller by profile_dir."""
478 self.controller_args.extend(['--profile_dir=%s'%profile_dir])
478 self.controller_args.extend(['--profile-dir=%s'%profile_dir])
479 479 self.profile_dir = unicode(profile_dir)
480 480 self.log.info("Starting MPIExecControllerLauncher: %r" % self.args)
481 481 return super(MPIExecControllerLauncher, self).start(1)
@@ -491,14 +491,14 b' class MPIExecEngineSetLauncher(MPIExecLauncher):'
491 491 help="Popen command for ipengine"
492 492 )
493 493 program_args = List(
494 ['--log-to-file','--log_level=%i'%logging.INFO], config=True,
494 ['--log-to-file','--log-level=%i'%logging.INFO], config=True,
495 495 help="Command line arguments for ipengine."
496 496 )
497 497 n = Int(1)
498 498
499 499 def start(self, n, profile_dir):
500 500 """Start n engines by profile or profile_dir."""
501 self.program_args.extend(['--profile_dir=%s'%profile_dir])
501 self.program_args.extend(['--profile-dir=%s'%profile_dir])
502 502 self.profile_dir = unicode(profile_dir)
503 503 self.n = n
504 504 self.log.info('Starting MPIExecEngineSetLauncher: %r' % self.args)
@@ -567,7 +567,7 b' class SSHControllerLauncher(SSHLauncher):'
567 567
568 568 program = List(ipcontroller_cmd_argv, config=True,
569 569 help="remote ipcontroller command.")
570 program_args = List(['--reuse-files', '--log-to-file','--log_level=%i'%logging.INFO], config=True,
570 program_args = List(['--reuse-files', '--log-to-file','--log-level=%i'%logging.INFO], config=True,
571 571 help="Command line arguments to ipcontroller.")
572 572
573 573
@@ -745,7 +745,7 b' class WindowsHPCControllerLauncher(WindowsHPCLauncher):'
745 745
746 746 def start(self, profile_dir):
747 747 """Start the controller by profile_dir."""
748 self.extra_args = ['--profile_dir=%s'%profile_dir]
748 self.extra_args = ['--profile-dir=%s'%profile_dir]
749 749 self.profile_dir = unicode(profile_dir)
750 750 return super(WindowsHPCControllerLauncher, self).start(1)
751 751
@@ -779,7 +779,7 b' class WindowsHPCEngineSetLauncher(WindowsHPCLauncher):'
779 779
780 780 def start(self, n, profile_dir):
781 781 """Start the controller by profile_dir."""
782 self.extra_args = ['--profile_dir=%s'%profile_dir]
782 self.extra_args = ['--profile-dir=%s'%profile_dir]
783 783 self.profile_dir = unicode(profile_dir)
784 784 return super(WindowsHPCEngineSetLauncher, self).start(n)
785 785
@@ -936,7 +936,7 b' class PBSControllerLauncher(PBSLauncher):'
936 936 default_template= Unicode("""#!/bin/sh
937 937 #PBS -V
938 938 #PBS -N ipcontroller
939 %s --log-to-file --profile_dir={profile_dir}
939 %s --log-to-file --profile-dir={profile_dir}
940 940 """%(' '.join(ipcontroller_cmd_argv)))
941 941
942 942 def start(self, profile_dir):
@@ -952,7 +952,7 b' class PBSEngineSetLauncher(PBSLauncher):'
952 952 default_template= Unicode(u"""#!/bin/sh
953 953 #PBS -V
954 954 #PBS -N ipengine
955 %s --profile_dir={profile_dir}
955 %s --profile-dir={profile_dir}
956 956 """%(' '.join(ipengine_cmd_argv)))
957 957
958 958 def start(self, n, profile_dir):
@@ -977,7 +977,7 b' class SGEControllerLauncher(SGELauncher):'
977 977 default_template= Unicode(u"""#$ -V
978 978 #$ -S /bin/sh
979 979 #$ -N ipcontroller
980 %s --log-to-file --profile_dir={profile_dir}
980 %s --log-to-file --profile-dir={profile_dir}
981 981 """%(' '.join(ipcontroller_cmd_argv)))
982 982
983 983 def start(self, profile_dir):
@@ -992,7 +992,7 b' class SGEEngineSetLauncher(SGELauncher):'
992 992 default_template = Unicode("""#$ -V
993 993 #$ -S /bin/sh
994 994 #$ -N ipengine
995 %s --profile_dir={profile_dir}
995 %s --profile-dir={profile_dir}
996 996 """%(' '.join(ipengine_cmd_argv)))
997 997
998 998 def start(self, n, profile_dir):
@@ -1012,7 +1012,7 b' class IPClusterLauncher(LocalProcessLauncher):'
1012 1012 ipcluster_cmd = List(ipcluster_cmd_argv, config=True,
1013 1013 help="Popen command for ipcluster")
1014 1014 ipcluster_args = List(
1015 ['--clean-logs', '--log-to-file', '--log_level=%i'%logging.INFO], config=True,
1015 ['--clean-logs', '--log-to-file', '--log-level=%i'%logging.INFO], config=True,
1016 1016 help="Command line arguments to pass to ipcluster.")
1017 1017 ipcluster_subcommand = Unicode('start')
1018 1018 ipcluster_n = Int(2)
@@ -55,7 +55,7 b' def setup():'
55 55
56 56 cp = TestProcessLauncher()
57 57 cp.cmd_and_args = ipcontroller_cmd_argv + \
58 ['--profile=iptest', '--log_level=50']
58 ['--profile=iptest', '--log-level=50']
59 59 cp.start()
60 60 launchers.append(cp)
61 61 tic = time.time()
@@ -74,7 +74,7 b" def add_engines(n=1, profile='iptest'):"
74 74 eps = []
75 75 for i in range(n):
76 76 ep = TestProcessLauncher()
77 ep.cmd_and_args = ipengine_cmd_argv + ['--profile=%s'%profile, '--log_level=50']
77 ep.cmd_and_args = ipengine_cmd_argv + ['--profile=%s'%profile, '--log-level=50']
78 78 ep.start()
79 79 launchers.append(ep)
80 80 eps.append(ep)
@@ -32,6 +32,8 b' import os'
32 32 import re
33 33 import sys
34 34
35 from contextlib import contextmanager
36
35 37 try:
36 38 # These tools are used by parts of the runtime, so we make the nose
37 39 # dependency optional at this point. Nose is a hard dependency to run the
@@ -307,3 +309,13 b' def check_pairs(func, pairs):'
307 309 for inp, expected in pairs:
308 310 out = func(inp)
309 311 assert out == expected, pair_fail_msg.format(func.func_name, inp, expected, out)
312
313 @contextmanager
314 def mute_warn():
315 from IPython.utils import warn
316 save_warn = warn.warn
317 warn.warn = lambda *a, **kw: None
318 try:
319 yield
320 finally:
321 warn.warn = save_warn No newline at end of file
General Comments 0
You need to be logged in to leave comments. Login now