本文整理汇总了Python中pants.option.global_options.GlobalOptionsRegistrar类的典型用法代码示例。如果您正苦于以下问题:Python GlobalOptionsRegistrar类的具体用法?Python GlobalOptionsRegistrar怎么用?Python GlobalOptionsRegistrar使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了GlobalOptionsRegistrar类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create
def create(cls, options_bootstrapper, build_configuration, init_subsystems=True):
global_bootstrap_options = options_bootstrapper.get_bootstrap_options().for_global_scope()
if global_bootstrap_options.pants_version != pants_version():
raise BuildConfigurationError(
'Version mismatch: Requested version was {}, our version is {}.'
.format(global_bootstrap_options.pants_version, pants_version())
)
pants_runtime_python_version = global_bootstrap_options.pants_runtime_python_version
current_python_version = '.'.join(map(str, sys.version_info[0:2]))
if pants_runtime_python_version and pants_runtime_python_version != current_python_version:
raise BuildConfigurationError(
'Running Pants with a different Python interpreter version than requested. '
'You requested {}, but are running with {}.\n\n'
'Note that Pants cannot use the value you give for `--pants-runtime-python-version` to '
'dynamically change the interpreter it uses, as it is too late for it to change once the program '
'is already running. Instead, your setup script (e.g. `./pants`) must configure which Python '
'interpreter and virtualenv to use. For example, the setup script we distribute '
'at https://www.pantsbuild.org/install.html#recommended-installation will read the '
'`pants_runtime_python_version` defined in your pants.ini to determine which Python '
'version to run with.'.format(pants_runtime_python_version, current_python_version)
)
# Parse and register options.
options = cls._construct_options(options_bootstrapper, build_configuration)
GlobalOptionsRegistrar.validate_instance(options.for_global_scope())
if init_subsystems:
Subsystem.set_options(options)
return options
示例2: 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")}),
)
示例3: 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
示例4: create_options_for_optionables
def create_options_for_optionables(optionables, extra_scopes=None, options=None):
"""Create a fake Options object for testing with appropriate defaults for the given optionables.
Any scoped `options` provided will override defaults, behaving as-if set on the command line.
:param iterable optionables: A series of `Optionable` types to register default options for.
:param iterable extra_scopes: An optional series of extra known scopes in play.
:param dict options: A dict of scope -> (dict of option name -> value) representing option values
explicitly set via the command line.
:returns: A fake `Options` object with defaults populated for the given `optionables` and any
explicitly set `options` overlayed.
"""
all_options = defaultdict(dict)
bootstrap_option_values = None
def register_func(on_scope):
scoped_options = all_options[on_scope]
register = _options_registration_function(scoped_options)
register.bootstrap = bootstrap_option_values
register.scope = on_scope
return register
# TODO: This sequence is a bit repetitive of the real registration sequence.
# Register bootstrap options and grab their default values for use in subsequent registration.
GlobalOptionsRegistrar.register_bootstrap_options(register_func(GLOBAL_SCOPE))
bootstrap_option_values = create_option_values(all_options[GLOBAL_SCOPE].copy())
# Now register the full global scope options.
GlobalOptionsRegistrar.register_options(register_func(GLOBAL_SCOPE))
for optionable in optionables:
optionable.register_options(register_func(optionable.options_scope))
# Make inner scopes inherit option values from their enclosing scopes.
all_scopes = set(all_options.keys())
# TODO(John Sirois): Kill extra scopes one this goes in:
# https://github.com/pantsbuild/pants/issues/1957
# For now we need a way for users of this utility to provide extra derived scopes out of band.
# With #1957 resolved, the extra scopes will be embedded in the Optionable's option_scope
# directly.
if extra_scopes:
all_scopes.update(extra_scopes)
# Iterating in sorted order guarantees that we see outer scopes before inner scopes,
# and therefore only have to inherit from our immediately enclosing scope.
for s in sorted(all_scopes):
if s != GLOBAL_SCOPE:
enclosing_scope = s.rpartition(".")[0]
opts = all_options[s]
for key, val in all_options.get(enclosing_scope, {}).items():
if key not in opts: # Inner scope values override the inherited ones.
opts[key] = val
if options:
for scope, opts in options.items():
all_options[scope].update(opts)
return create_options(all_options)
示例5: 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')}))
示例6: create_options_for_optionables
def create_options_for_optionables(optionables,
options=None,
options_fingerprintable=None,
passthru_args=None):
"""Create a fake Options object for testing with appropriate defaults for the given optionables.
Any scoped `options` provided will override defaults, behaving as-if set on the command line.
:param iterable optionables: A series of `Optionable` types to register default options for.
:param dict options: A dict of scope -> (dict of option name -> value) representing option values
explicitly set via the command line.
:param dict options_fingerprintable: A dict of scope -> (dict of option name -> option type)
representing the fingerprintable options
and the scopes they are registered for.
:param list passthru_args: A list of passthrough args (specified after `--` on the command line).
:returns: A fake `Options` object with defaults populated for the given `optionables` and any
explicitly set `options` overlayed.
"""
all_options = defaultdict(dict)
fingerprintable_options = defaultdict(dict)
bootstrap_option_values = None
if options_fingerprintable:
for scope, opts in options_fingerprintable.items():
fingerprintable_options[scope].update(opts)
def register_func(on_scope):
scoped_options = all_options[on_scope]
scoped_fingerprintables = fingerprintable_options[on_scope]
register = _options_registration_function(scoped_options, scoped_fingerprintables)
register.bootstrap = bootstrap_option_values
register.scope = on_scope
return register
# TODO: This sequence is a bit repetitive of the real registration sequence.
# Register bootstrap options and grab their default values for use in subsequent registration.
GlobalOptionsRegistrar.register_bootstrap_options(register_func(GLOBAL_SCOPE))
bootstrap_option_values = _FakeOptionValues(all_options[GLOBAL_SCOPE].copy())
# Now register the full global scope options.
GlobalOptionsRegistrar.register_options(register_func(GLOBAL_SCOPE))
for optionable in optionables:
optionable.register_options(register_func(optionable.options_scope))
if options:
for scope, opts in options.items():
all_options[scope].update(opts)
return create_options(all_options,
passthru_args=passthru_args,
fingerprintable_options=fingerprintable_options)
示例7: register_options
def register_options(self, subsystems):
# Standalone global options.
GlobalOptionsRegistrar.register_options_on_scope(self.options)
# Options for subsystems.
for subsystem in subsystems:
subsystem.register_options_on_scope(self.options)
# TODO(benjy): Should Goals be subsystems? Or should the entire goal-running mechanism
# be a subsystem?
for goal in Goal.all():
# Register task options.
goal.register_options(self.options)
示例8: _register_options
def _register_options(self, subsystems, options):
"""Registers global options."""
# Standalone global options.
GlobalOptionsRegistrar.register_options_on_scope(options)
# Options for subsystems.
for subsystem in subsystems:
subsystem.register_options_on_scope(options)
# TODO(benjy): Should Goals or the entire goal-running mechanism be a Subsystem?
for goal in Goal.all():
# Register task options.
goal.register_options(options)
示例9: 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
示例10: _install_options
def _install_options(self, options_bootstrapper, build_configuration):
"""Parse and register options.
:returns: An Options object representing the full set of runtime options.
"""
# TODO: This inline import is currently necessary to resolve a ~legitimate cycle between
# `GoalRunner`->`EngineInitializer`->`OptionsInitializer`->`GoalRunner`.
from pants.bin.goal_runner import GoalRunner
# Now that plugins and backends are loaded, we can gather the known scopes.
known_scope_infos = [GlobalOptionsRegistrar.get_scope_info()]
# Add scopes for all needed subsystems via a union of all known subsystem sets.
subsystems = Subsystem.closure(
GoalRunner.subsystems() | Goal.subsystems() | build_configuration.subsystems()
)
for subsystem in subsystems:
known_scope_infos.append(subsystem.get_scope_info())
# Add scopes for all tasks in all goals.
for goal in Goal.all():
known_scope_infos.extend(filter(None, goal.known_scope_infos()))
# Now that we have the known scopes we can get the full options.
options = options_bootstrapper.get_full_options(known_scope_infos)
self._register_options(subsystems, options)
# Make the options values available to all subsystems.
Subsystem.set_options(options)
return options
示例11: complete_scopes
def complete_scopes(cls, scope_infos):
"""Expand a set of scopes to include all enclosing scopes.
E.g., if the set contains `foo.bar.baz`, ensure that it also contains `foo.bar` and `foo`.
Also adds any deprecated scopes.
"""
ret = {GlobalOptionsRegistrar.get_scope_info()}
original_scopes = dict()
for si in scope_infos:
ret.add(si)
if si.scope in original_scopes:
raise cls.DuplicateScopeError('Scope `{}` claimed by {}, was also claimed by {}.'.format(
si.scope, si, original_scopes[si.scope]
))
original_scopes[si.scope] = si
if si.deprecated_scope:
ret.add(ScopeInfo(si.deprecated_scope, si.category, si.optionable_cls))
original_scopes[si.deprecated_scope] = si
# TODO: Once scope name validation is enforced (so there can be no dots in scope name
# components) we can replace this line with `for si in scope_infos:`, because it will
# not be possible for a deprecated_scope to introduce any new intermediate scopes.
for si in copy.copy(ret):
for scope in all_enclosing_scopes(si.scope, allow_global=False):
if scope not in original_scopes:
ret.add(ScopeInfo(scope, ScopeInfo.INTERMEDIATE))
return ret
示例12: complete_scopes
def complete_scopes(cls, scope_infos):
"""Expand a set of scopes to include all enclosing scopes.
E.g., if the set contains `foo.bar.baz`, ensure that it also contains `foo.bar` and `foo`.
Also adds any deprecated scopes.
"""
ret = {GlobalOptionsRegistrar.get_scope_info()}
original_scopes = set()
for si in scope_infos:
ret.add(si)
original_scopes.add(si.scope)
if si.deprecated_scope:
ret.add(ScopeInfo(si.deprecated_scope, si.category, si.optionable_cls))
original_scopes.add(si.deprecated_scope)
# TODO: Once scope name validation is enforced (so there can be no dots in scope name
# components) we can replace this line with `for si in scope_infos:`, because it will
# not be possible for a deprecated_scope to introduce any new intermediate scopes.
for si in copy.copy(ret):
scope = si.scope
while scope != '':
if scope not in original_scopes:
ret.add(ScopeInfo(scope, ScopeInfo.INTERMEDIATE))
scope = enclosing_scope(scope)
return ret
示例13: _options
def _options(self):
# NB: The PluginResolver runs very early in the pants startup sequence before the standard
# Subsystem facility is wired up. As a result PluginResolver is not itself a Subsystem with
# PythonRepos as a dependency. Instead it does the minimum possible work to hand-roll
# bootstrapping of the Subsystem it needs.
subsystems = Subsystem.closure([PythonRepos])
known_scope_infos = [subsystem.get_scope_info() for subsystem in subsystems]
options = self._options_bootstrapper.get_full_options(known_scope_infos)
# Ignore command line flags since we'd blow up on any we don't understand (most of them).
# If someone wants to bootstrap plugins in a one-off custom way they'll need to use env vars
# or a --pants-config-files pointing to a custom pants.ini snippet.
defaulted_only_options = options.drop_flag_values()
GlobalOptionsRegistrar.register_options_on_scope(defaulted_only_options)
for subsystem in subsystems:
subsystem.register_options_on_scope(defaulted_only_options)
return defaulted_only_options
示例14: do_test
def do_test(args, kwargs, expected_default):
# Defaults are computed in the parser and added into the kwargs, so we
# must jump through this hoop in this test.
parser = Parser(env={}, config=Config.load([]),
scope_info=GlobalOptionsRegistrar.get_scope_info(),
parent_parser=None, option_tracker=OptionTracker())
parser.register(*args, **kwargs)
oshi = HelpInfoExtracter.get_option_scope_help_info_from_parser(parser).basic
self.assertEquals(1, len(oshi))
ohi = oshi[0]
self.assertEqual(expected_default, ohi.default)
示例15: _setup_options
def _setup_options(self, options_bootstrapper, working_set):
# TODO: This inline import is currently necessary to resolve a ~legitimate cycle between
# `GoalRunner`->`EngineInitializer`->`OptionsInitializer`->`GoalRunner`.
from pants.bin.goal_runner import GoalRunner
bootstrap_options = options_bootstrapper.get_bootstrap_options()
global_bootstrap_options = bootstrap_options.for_global_scope()
if global_bootstrap_options.pants_version != pants_version():
raise BuildConfigurationError(
'Version mismatch: Requested version was {}, our version is {}.'.format(
global_bootstrap_options.pants_version, pants_version()
)
)
# Get logging setup prior to loading backends so that they can log as needed.
if self._init_logging:
self._setup_logging(global_bootstrap_options)
# Add any extra paths to python path (e.g., for loading extra source backends).
for path in global_bootstrap_options.pythonpath:
sys.path.append(path)
pkg_resources.fixup_namespace_packages(path)
# Load plugins and backends.
plugins = global_bootstrap_options.plugins
backend_packages = global_bootstrap_options.backend_packages
build_configuration = load_plugins_and_backends(plugins, working_set, backend_packages)
# Now that plugins and backends are loaded, we can gather the known scopes.
known_scope_infos = [GlobalOptionsRegistrar.get_scope_info()]
# Add scopes for all needed subsystems via a union of all known subsystem sets.
subsystems = Subsystem.closure(
GoalRunner.subsystems() | Goal.subsystems() | build_configuration.subsystems()
)
for subsystem in subsystems:
known_scope_infos.append(subsystem.get_scope_info())
# Add scopes for all tasks in all goals.
for goal in Goal.all():
known_scope_infos.extend(filter(None, goal.known_scope_infos()))
# Now that we have the known scopes we can get the full options.
options = options_bootstrapper.get_full_options(known_scope_infos)
self._register_options(subsystems, options)
# Make the options values available to all subsystems.
Subsystem.set_options(options)
return options, build_configuration