本文整理汇总了Python中pants.option.options.Options.for_global_scope方法的典型用法代码示例。如果您正苦于以下问题:Python Options.for_global_scope方法的具体用法?Python Options.for_global_scope怎么用?Python Options.for_global_scope使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pants.option.options.Options
的用法示例。
在下文中一共展示了Options.for_global_scope方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_bootstrap_option_values
# 需要导入模块: from pants.option.options import Options [as 别名]
# 或者: from pants.option.options.Options import for_global_scope [as 别名]
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()
示例2: OptionsBootstrapper
# 需要导入模块: from pants.option.options import Options [as 别名]
# 或者: from pants.option.options.Options import for_global_scope [as 别名]
class OptionsBootstrapper(object):
"""An object that knows how to create options in two stages: bootstrap, and then full options."""
def __init__(self, env=None, configpath=None, args=None, buildroot=None):
self._buildroot = buildroot or get_buildroot()
self._env = env or os.environ.copy()
Config.reset_default_bootstrap_option_values(buildroot=self._buildroot)
self._pre_bootstrap_config = Config.load([configpath] if configpath else None)
self._post_bootstrap_config = None # Will be set later.
self._args = args or sys.argv
self._bootstrap_options = None # We memoize the bootstrap options here.
self._full_options = None # We memoize the full options here.
# So other startup code has config to work with. This will go away once we replace direct
# config accesses with options, and plumb those through everywhere that needs them.
Config.cache(self._pre_bootstrap_config)
def get_bootstrap_options(self):
"""Returns an Options instance that only knows about the bootstrap 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
def get_full_options(self, known_scopes):
if not self._full_options:
# Note: Don't inline this into the Options() call, as this populates
# self._post_bootstrap_config, which is another argument to that call.
bootstrap_options = self.get_bootstrap_options()
self._full_options = Options(self._env,
self._post_bootstrap_config,
known_scopes,
args=self._args,
bootstrap_option_values=bootstrap_options.for_global_scope())
# The bootstrap options need to be registered on the post-bootstrap Options instance, so it
# won't choke on them on the command line, and also so we can access their values as regular
# global-scope options, for convenience.
register_bootstrap_options(self._full_options.register_global, buildroot=self._buildroot)
return self._full_options
示例3: GoalRunner
# 需要导入模块: from pants.option.options import Options [as 别名]
# 或者: from pants.option.options.Options import for_global_scope [as 别名]
class GoalRunner(Command):
"""Lists installed goals or else executes a named goal."""
class IntermixedArgumentsError(GoalError):
pass
__command__ = 'goal'
output = None
# TODO(John Sirois): revisit wholesale locking when we move py support into pants new
@classmethod
def serialized(cls):
# Goal serialization is now handled in goal execution during group processing.
# The goal command doesn't need to hold the serialization lock; individual goals will
# acquire the lock if they need to be serialized.
return False
def __init__(self, *args, **kwargs):
self.targets = []
self.config = Config.from_cache()
known_scopes = ['']
for goal in Goal.all():
# Note that enclosing scopes will appear before scopes they enclose.
known_scopes.extend(filter(None, goal.known_scopes()))
# Annoying but temporary hack to get the parser. We can't use self.parser because
# that only gets set up in the superclass ctor, and we can't call that until we have
# self.new_options set up because the superclass ctor calls our register_options().
# Fortunately this will all go away once we're fully off the old "Command" mechanism.
legacy_parser = args[2] if len(args) > 2 else kwargs['parser']
self.new_options = Options(os.environ.copy(), self.config, known_scopes, args=sys.argv,
legacy_parser=legacy_parser)
super(GoalRunner, self).__init__(*args, needs_old_options=False, **kwargs)
def get_spec_excludes(self):
spec_excludes = self.config.getlist(Config.DEFAULT_SECTION, 'spec_excludes',
default=None)
if spec_excludes is None:
return [self.config.getdefault('pants_workdir')]
return [os.path.join(self.root_dir, spec_exclude) for spec_exclude in spec_excludes]
@property
def global_options(self):
return self.new_options.for_global_scope()
@contextmanager
def check_errors(self, banner):
errors = {}
def error(key, include_traceback=False):
exc_type, exc_value, _ = sys.exc_info()
msg = StringIO()
if include_traceback:
frame = inspect.trace()[-2]
filename = frame[1]
lineno = frame[2]
funcname = frame[3]
code = ''.join(frame[4]) if frame[4] else None
traceback.print_list([(filename, lineno, funcname, code)], file=msg)
if exc_type:
msg.write(''.join(traceback.format_exception_only(exc_type, exc_value)))
errors[key] = msg.getvalue()
sys.exc_clear()
yield error
if errors:
msg = StringIO()
msg.write(banner)
invalid_keys = [key for key, exc in errors.items() if not exc]
if invalid_keys:
msg.write('\n %s' % '\n '.join(invalid_keys))
for key, exc in errors.items():
if exc:
msg.write('\n %s =>\n %s' % (key, '\n '.join(exc.splitlines())))
# The help message for goal is extremely verbose, and will obscure the
# actual error message, so we don't show it in this case.
self.error(msg.getvalue(), show_help=False)
def register_options(self):
register_global_options(self.new_options.register_global)
for goal in Goal.all():
goal.register_options(self.new_options)
def setup_parser(self, parser, args):
if not args:
args.append('help')
logger = logging.getLogger(__name__)
goals = self.new_options.goals
specs = self.new_options.target_specs
fail_fast = self.new_options.for_global_scope().fail_fast
for goal in goals:
if BuildFile.from_cache(get_buildroot(), goal, must_exist=False).exists():
logger.warning(" Command-line argument '{0}' is ambiguous and was assumed to be "
"a goal. If this is incorrect, disambiguate it with ./{0}.".format(goal))
if self.new_options.is_help:
self.new_options.print_help(goals=goals, legacy=True)
#.........这里部分代码省略.........