本文整理汇总了Python中pants.option.options.Options类的典型用法代码示例。如果您正苦于以下问题:Python Options类的具体用法?Python Options怎么用?Python Options使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Options类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_complete_scopes
def test_complete_scopes(self):
_global = GlobalOptionsRegistrar.get_scope_info()
self.assertEquals(
{_global, intermediate("foo"), intermediate("foo.bar"), task("foo.bar.baz")},
Options.complete_scopes({task("foo.bar.baz")}),
)
self.assertEquals(
{_global, intermediate("foo"), intermediate("foo.bar"), task("foo.bar.baz")},
Options.complete_scopes({GlobalOptionsRegistrar.get_scope_info(), task("foo.bar.baz")}),
)
self.assertEquals(
{_global, intermediate("foo"), intermediate("foo.bar"), task("foo.bar.baz")},
Options.complete_scopes({intermediate("foo"), task("foo.bar.baz")}),
)
self.assertEquals(
{
_global,
intermediate("foo"),
intermediate("foo.bar"),
task("foo.bar.baz"),
intermediate("qux"),
task("qux.quux"),
},
Options.complete_scopes({task("foo.bar.baz"), task("qux.quux")}),
)
示例2: test_complete_scopes
def test_complete_scopes(self):
self.assertEquals({'', 'foo', 'foo.bar', 'foo.bar.baz'},
Options.complete_scopes({'foo.bar.baz'}))
self.assertEquals({'', 'foo', 'foo.bar', 'foo.bar.baz'},
Options.complete_scopes({'', 'foo.bar.baz'}))
self.assertEquals({'', 'foo', 'foo.bar', 'foo.bar.baz'},
Options.complete_scopes({'foo', 'foo.bar.baz'}))
self.assertEquals({'', 'foo', 'foo.bar', 'foo.bar.baz', 'qux', 'qux.quux'},
Options.complete_scopes({'foo.bar.baz', 'qux.quux'}))
示例3: test_complete_scopes
def test_complete_scopes(self):
_global = ScopeInfo.for_global_scope()
self.assertEquals({_global, intermediate('foo'), intermediate('foo.bar'), task('foo.bar.baz')},
Options.complete_scopes({task('foo.bar.baz')}))
self.assertEquals({_global, intermediate('foo'), intermediate('foo.bar'), task('foo.bar.baz')},
Options.complete_scopes({ScopeInfo.for_global_scope(), task('foo.bar.baz')}))
self.assertEquals({_global, goal('foo'), intermediate('foo.bar'), task('foo.bar.baz')},
Options.complete_scopes({goal('foo'), task('foo.bar.baz')}))
self.assertEquals({_global, intermediate('foo'), intermediate('foo.bar'), task('foo.bar.baz'),
intermediate('qux'), task('qux.quux')},
Options.complete_scopes({task('foo.bar.baz'), task('qux.quux')}))
示例4: test_complete_scopes
def test_complete_scopes(self):
_global = GlobalOptionsRegistrar.get_scope_info()
self.assertEquals({_global, intermediate('foo'), intermediate('foo.bar'), task('foo.bar.baz')},
Options.complete_scopes({task('foo.bar.baz')}))
self.assertEquals({_global, intermediate('foo'), intermediate('foo.bar'), task('foo.bar.baz')},
Options.complete_scopes({GlobalOptionsRegistrar.get_scope_info(),
task('foo.bar.baz')}))
self.assertEquals({_global, intermediate('foo'), intermediate('foo.bar'), task('foo.bar.baz')},
Options.complete_scopes({intermediate('foo'), task('foo.bar.baz')}))
self.assertEquals({_global, intermediate('foo'), intermediate('foo.bar'), task('foo.bar.baz'),
intermediate('qux'), task('qux.quux')},
Options.complete_scopes({task('foo.bar.baz'), task('qux.quux')}))
示例5: get_bootstrap_option_values
def get_bootstrap_option_values(env=None, config=None, args=None, buildroot=None):
"""Get the values of just the bootstrap options."""
# Filter just the bootstrap args, so we don't choke on other global-scope args on the cmd line.
flags = set()
def capture_the_flags(*args, **kwargs):
flags.update(args)
register_bootstrap_options(capture_the_flags, buildroot=buildroot)
bargs = filter(lambda x: x.partition('=')[0] in flags, args)
bootstrap_options = Options(env=env, config=config, known_scopes=[GLOBAL_SCOPE], args=bargs)
register_bootstrap_options(bootstrap_options.register_global, buildroot=buildroot)
return bootstrap_options.for_global_scope()
示例6: test_env_type_int
def test_env_type_int(self):
options = Options.create(env={'PANTS_FOO_BAR': "['123','456']"},
config=self._create_config({}),
known_scope_infos=OptionsTest._known_scope_infos,
args=shlex.split('./pants'),
option_tracker=OptionTracker())
options.register(GLOBAL_SCOPE, '--foo-bar', type=list, member_type=int)
self.assertEqual([123, 456], options.for_global_scope().foo_bar)
options = Options.create(env={'PANTS_FOO_BAR': '123'},
config=self._create_config({}),
known_scope_infos=OptionsTest._known_scope_infos,
args=shlex.split('./pants'),
option_tracker=OptionTracker())
options.register(GLOBAL_SCOPE, '--foo-bar', type=int)
self.assertEqual(123, options.for_global_scope().foo_bar)
示例7: get_bootstrap_options
def get_bootstrap_options(self):
"""Returns an Options instance that only knows about the bootstrap options."""
if not self._bootstrap_options:
flags = set()
def capture_the_flags(*args, **kwargs):
flags.update(args)
register_bootstrap_options(capture_the_flags, buildroot=self._buildroot)
# Take just the bootstrap args, so we don't choke on other global-scope args on the cmd line.
bargs = filter(lambda x: x.partition('=')[0] in flags, self._args or [])
self._bootstrap_options = Options(env=self._env, config=self._pre_bootstrap_config,
known_scopes=[GLOBAL_SCOPE], args=bargs)
register_bootstrap_options(self._bootstrap_options.register_global, buildroot=self._buildroot)
bootstrap_option_values = self._bootstrap_options.for_global_scope()
Config.reset_default_bootstrap_option_values(values=bootstrap_option_values)
# Now re-read the config, post-bootstrapping. Note the order: First whatever we bootstrapped
# from (typically pants.ini), then config override, then rcfiles.
configpaths = list(self._pre_bootstrap_config.sources())
if bootstrap_option_values.config_override:
configpaths.append(bootstrap_option_values.config_override)
if bootstrap_option_values.pantsrc:
rcfiles = [os.path.expanduser(rcfile) for rcfile in bootstrap_option_values.pantsrc_files]
existing_rcfiles = filter(os.path.exists, rcfiles)
configpaths.extend(existing_rcfiles)
self._post_bootstrap_config = Config.load(configpaths)
Config.cache(self._post_bootstrap_config)
return self._bootstrap_options
示例8: bootstrap_options_from_config
def bootstrap_options_from_config(config):
bootstrap_options = Options.create(env=self._env, config=config,
known_scope_infos=[GlobalOptionsRegistrar.get_scope_info()], args=bargs)
def register_global(*args, **kwargs):
bootstrap_options.register(GLOBAL_SCOPE, *args, **kwargs)
GlobalOptionsRegistrar.register_bootstrap_options(register_global)
return bootstrap_options
示例9: test_double_registration
def test_double_registration(self):
options = Options.create(env={},
config=self._create_config({}),
known_scope_infos=OptionsTest._known_scope_infos,
args=shlex.split('./pants'),
option_tracker=OptionTracker())
options.register(GLOBAL_SCOPE, '--foo-bar')
self.assertRaises(OptionAlreadyRegistered, lambda: options.register(GLOBAL_SCOPE, '--foo-bar'))
示例10: test_deprecated_option_past_removal
def test_deprecated_option_past_removal(self):
with self.assertRaises(PastRemovalVersionError):
options = Options.create(env={},
config=self._create_config({}),
known_scope_infos=OptionsTest._known_scope_infos,
args="./pants")
options.register(GLOBAL_SCOPE, '--too-old-option', deprecated_version='0.0.24',
deprecated_hint='The semver for this option has already passed.')
示例11: _parse
def _parse(self, args_str, env=None, config=None, bootstrap_option_values=None):
args = shlex.split(str(args_str))
options = Options.create(env=env or {},
config=self._create_config(config or {}),
known_scope_infos=OptionsTest._known_scope_infos,
args=args,
bootstrap_option_values=bootstrap_option_values)
self._register(options)
return options
示例12: _parse_type_int
def _parse_type_int(self, args_str, env=None, config=None, bootstrap_option_values=None,
action=None):
args = shlex.split(str(args_str))
options = Options.create(env=env or {},
config=self._create_config(config or {}),
known_scope_infos=OptionsTest._known_scope_infos,
args=args,
bootstrap_option_values=bootstrap_option_values)
options.register(GLOBAL_SCOPE, '--config-override', action=action, type=int)
return options
示例13: test_shadowing
def test_shadowing(self):
options = Options.create(
env={},
config=self._create_config({}),
known_scope_infos=[task("foo")],
args="./pants",
option_tracker=OptionTracker(),
)
options.register("", "--bar")
with self.assertRaises(RegistrationError):
options.register("foo", "--bar")
示例14: get_bootstrap_options
def get_bootstrap_options(self):
""":returns: an Options instance that only knows about the bootstrap options.
:rtype: Options
"""
if not self._bootstrap_options:
flags = set()
short_flags = set()
def capture_the_flags(*args, **kwargs):
for flag in Parser.expand_flags(*args, **kwargs):
flags.add(flag.name)
if len(flag.name) == 2:
short_flags.add(flag.name)
if flag.inverse_name:
flags.add(flag.inverse_name)
register_bootstrap_options(capture_the_flags, buildroot=self._buildroot)
def is_bootstrap_option(arg):
components = arg.split('=', 1)
if components[0] in flags:
return True
for flag in short_flags:
if arg.startswith(flag):
return True
return False
# Take just the bootstrap args, so we don't choke on other global-scope args on the cmd line.
# Stop before '--' since args after that are pass-through and may have duplicate names to our
# bootstrap options.
bargs = filter(is_bootstrap_option, itertools.takewhile(lambda arg: arg != '--', self._args))
self._bootstrap_options = Options(env=self._env, config=self._pre_bootstrap_config,
known_scopes=[GLOBAL_SCOPE], args=bargs)
register_bootstrap_options(self._bootstrap_options.register_global, buildroot=self._buildroot)
bootstrap_option_values = self._bootstrap_options.for_global_scope()
Config.reset_default_bootstrap_option_values(values=bootstrap_option_values)
# Now re-read the config, post-bootstrapping. Note the order: First whatever we bootstrapped
# from (typically pants.ini), then config override, then rcfiles.
configpaths = list(self._pre_bootstrap_config.sources())
if bootstrap_option_values.config_override:
configpaths.append(bootstrap_option_values.config_override)
if bootstrap_option_values.pantsrc:
rcfiles = [os.path.expanduser(rcfile) for rcfile in bootstrap_option_values.pantsrc_files]
existing_rcfiles = filter(os.path.exists, rcfiles)
configpaths.extend(existing_rcfiles)
self._post_bootstrap_config = Config.load(configpaths)
Config.cache(self._post_bootstrap_config)
return self._bootstrap_options
示例15: parse_bootstrap_options
def parse_bootstrap_options(env, args, config):
bootstrap_options = Options.create(
env=env,
config=config,
known_scope_infos=[GlobalOptionsRegistrar.get_scope_info()],
args=args,
)
def register_global(*args, **kwargs):
## Only use of Options.register?
bootstrap_options.register(GLOBAL_SCOPE, *args, **kwargs)
GlobalOptionsRegistrar.register_bootstrap_options(register_global)
return bootstrap_options