當前位置: 首頁>>代碼示例>>Python>>正文


Python arg_splitter.ArgSplitter類代碼示例

本文整理匯總了Python中pants.option.arg_splitter.ArgSplitter的典型用法代碼示例。如果您正苦於以下問題:Python ArgSplitter類的具體用法?Python ArgSplitter怎麽用?Python ArgSplitter使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了ArgSplitter類的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: create

  def create(cls, env, config, known_scope_infos, args=None, bootstrap_option_values=None):
    """Create an Options instance.

    :param env: a dict of environment variables.
    :param :class:`pants.option.config.Config` config: data from a config file.
    :param known_scope_infos: ScopeInfos for all scopes that may be encountered.
    :param args: a list of cmd-line args; defaults to `sys.argv` if None is supplied.
    :param bootstrap_option_values: An optional namespace containing the values of bootstrap
           options. We can use these values when registering other options.
    """
    # We need parsers for all the intermediate scopes, so inherited option values
    # can propagate through them.
    complete_known_scope_infos = cls.complete_scopes(known_scope_infos)
    splitter = ArgSplitter(complete_known_scope_infos)
    args = sys.argv if args is None else args
    goals, scope_to_flags, target_specs, passthru, passthru_owner, unknown_scopes = splitter.split_args(args)

    option_tracker = OptionTracker()

    if bootstrap_option_values:
      target_spec_files = bootstrap_option_values.target_spec_files
      if target_spec_files:
        for spec in target_spec_files:
          with open(spec, 'r') as f:
            target_specs.extend([line for line in [line.strip() for line in f] if line])

    help_request = splitter.help_request

    parser_hierarchy = ParserHierarchy(env, config, complete_known_scope_infos, option_tracker)
    bootstrap_option_values = bootstrap_option_values
    known_scope_to_info = {s.scope: s for s in complete_known_scope_infos}
    return cls(goals, scope_to_flags, target_specs, passthru, passthru_owner, help_request,
               parser_hierarchy, bootstrap_option_values, known_scope_to_info,
               option_tracker, unknown_scopes)
開發者ID:jsirois,項目名稱:pants,代碼行數:34,代碼來源:options.py

示例2: create

  def create(cls, env, config, known_scope_infos, args=None, bootstrap_option_values=None):
    """Create an Options instance.

    :param env: a dict of environment variables.
    :param config: data from a config file (must support config.get[list](section, name, default=)).
    :param known_scope_infos: ScopeInfos for all scopes that may be encountered.
    :param args: a list of cmd-line args; defaults to `sys.argv` if None is supplied.
    :param bootstrap_option_values: An optional namespace containing the values of bootstrap
           options. We can use these values when registering other options.
    """
    # We need parsers for all the intermediate scopes, so inherited option values
    # can propagate through them.
    complete_known_scope_infos = cls.complete_scopes(known_scope_infos)
    splitter = ArgSplitter(complete_known_scope_infos)
    args = sys.argv if args is None else args
    goals, scope_to_flags, target_specs, passthru, passthru_owner = splitter.split_args(args)

    if bootstrap_option_values:
      target_spec_files = bootstrap_option_values.target_spec_files
      if target_spec_files:
        for spec in target_spec_files:
          with open(spec) as f:
            target_specs.extend(filter(None, [line.strip() for line in f]))

    help_request = splitter.help_request

    parser_hierarchy = ParserHierarchy(env, config, complete_known_scope_infos)
    values_by_scope = {}  # Arg values, parsed per-scope on demand.
    bootstrap_option_values = bootstrap_option_values
    known_scope_to_info = {s.scope: s for s in complete_known_scope_infos}
    return cls(goals, scope_to_flags, target_specs, passthru, passthru_owner, help_request,
               parser_hierarchy, values_by_scope, bootstrap_option_values, known_scope_to_info)
開發者ID:areitz,項目名稱:pants,代碼行數:32,代碼來源:options.py

示例3: __init__

  def __init__(self, env, config, known_scopes, args=sys.argv, bootstrap_option_values=None):
    """Create an Options instance.

    :param env: a dict of environment variables.
    :param config: data from a config file (must support config.get[list](section, name, default=)).
    :param known_scopes: a list of all possible scopes that may be encountered.
    :param args: a list of cmd-line args.
    :param bootstrap_option_values: An optional namespace containing the values of bootstrap
           options. We can use these values when registering other options.
    """
    splitter = ArgSplitter(known_scopes)
    self._goals, self._scope_to_flags, self._target_specs, self._passthru, self._passthru_owner = \
      splitter.split_args(args)

    if bootstrap_option_values:
      target_spec_files = bootstrap_option_values.target_spec_files
      if target_spec_files:
        for spec in target_spec_files:
          with open(spec) as f:
            self._target_specs.extend(filter(None, [line.strip() for line in f]))

    self._help_request = splitter.help_request
    self._parser_hierarchy = ParserHierarchy(env, config, known_scopes, self._help_request)
    self._values_by_scope = {}  # Arg values, parsed per-scope on demand.
    self._bootstrap_option_values = bootstrap_option_values
    self._known_scopes = set(known_scopes)
開發者ID:MathewJennings,項目名稱:pants,代碼行數:26,代碼來源:options.py

示例4: _split

 def _split(self, args_str, expected_scope_to_flags, expected_target_specs, expected_help=False):
   splitter = ArgSplitter(ArgSplitterTest._known_scopes)
   args = shlex.split(str(args_str))
   scope_to_flags, target_specs = splitter.split_args(args)
   self.assertEquals(expected_scope_to_flags, scope_to_flags)
   self.assertEquals(expected_target_specs, target_specs)
   self.assertEquals(expected_help, splitter.is_help)
開發者ID:Yasumoto,項目名稱:pants,代碼行數:7,代碼來源:test_arg_splitter.py

示例5: _split

 def _split(self, args_str, expected_goals, expected_scope_to_flags, expected_target_specs,
            expected_passthru=None, expected_passthru_owner=None, expected_is_help=False):
   expected_passthru = expected_passthru or []
   splitter = ArgSplitter(ArgSplitterTest._known_scopes)
   args = shlex.split(str(args_str))
   goals, scope_to_flags, target_specs, passthru, passthru_owner = splitter.split_args(args)
   self.assertEquals(expected_goals, goals)
   self.assertEquals(expected_scope_to_flags, scope_to_flags)
   self.assertEquals(expected_target_specs, target_specs)
   self.assertEquals(expected_passthru, passthru)
   self.assertEquals(expected_passthru_owner, passthru_owner)
   self.assertEquals(expected_is_help, splitter.is_help)
開發者ID:digideskio,項目名稱:pants,代碼行數:12,代碼來源:test_arg_splitter.py

示例6: __init__

  def __init__(self, env, config, known_scopes, args=sys.argv, legacy_parser=None):
    """Create an Options instance.

    :param env: a dict of environment variables.
    :param config: data from a config file (must support config.get(section, name, default=)).
    :param known_scopes: a list of all possible scopes that may be encountered.
    :param args: a list of cmd-line args.
    :param legacy_parser: optional instance of optparse.OptionParser, used to register and access
           the old-style flags during migration.
    """
    splitter = ArgSplitter(known_scopes)
    self._scope_to_flags, self._target_specs, self._passthru = splitter.split_args(args)
    self._is_help = splitter.is_help
    self._parser_hierarchy = ParserHierarchy(env, config, known_scopes, legacy_parser)
    self._legacy_parser = legacy_parser  # Old-style options, used temporarily during transition.
    self._legacy_values = None  # Values parsed from old-stype options.
    self._values_by_scope = {}  # Arg values, parsed per-scope on demand.
開發者ID:rgbenson,項目名稱:pants,代碼行數:17,代碼來源:options.py

示例7: _split

 def _split(self, args_str, expected_goals, expected_scope_to_flags, expected_target_specs,
            expected_passthru=None, expected_passthru_owner=None,
            expected_is_help=False, expected_help_advanced=False, expected_help_all=False):
   expected_passthru = expected_passthru or []
   splitter = ArgSplitter(ArgSplitterTest._known_scopes)
   args = shlex.split(str(args_str))
   goals, scope_to_flags, target_specs, passthru, passthru_owner = splitter.split_args(args)
   self.assertEquals(expected_goals, goals)
   self.assertEquals(expected_scope_to_flags, scope_to_flags)
   self.assertEquals(expected_target_specs, target_specs)
   self.assertEquals(expected_passthru, passthru)
   self.assertEquals(expected_passthru_owner, passthru_owner)
   self.assertEquals(expected_is_help, splitter.help_request is not None)
   self.assertEquals(expected_help_advanced,
                     splitter.help_request is not None and splitter.help_request.advanced)
   self.assertEquals(expected_help_all,
                     splitter.help_request is not None and splitter.help_request.all_scopes)
開發者ID:arloherrine,項目名稱:pants,代碼行數:17,代碼來源:test_arg_splitter.py

示例8: _error_split

 def _error_split(self, args_str):
   parser = ArgSplitter(ArgSplitterTest._known_scopes)
   args = shlex.split(str(args_str))
   with pytest.raises(ArgSplitterError):
     parser.split_args(args)
開發者ID:Yasumoto,項目名稱:pants,代碼行數:5,代碼來源:test_arg_splitter.py

示例9: _split_version

 def _split_version(self, args_str):
   splitter = ArgSplitter(ArgSplitterTest._known_scope_infos)
   args = shlex.split(args_str)
   splitter.split_args(args)
   self.assertTrue(splitter.help_request is not None and splitter.help_request.version)
開發者ID:digwanderlust,項目名稱:pants,代碼行數:5,代碼來源:test_arg_splitter.py

示例10: _split_no_goal

 def _split_no_goal(self, args_str):
   splitter = ArgSplitter(ArgSplitterTest._known_scope_infos)
   splitter.split_args(shlex.split(args_str))
   self.assertTrue(isinstance(splitter.help_request, NoGoalHelp))
開發者ID:areitz,項目名稱:pants,代碼行數:4,代碼來源:test_arg_splitter.py

示例11: _split_unknown_goal

 def _split_unknown_goal(self, args_str, unknown_goals):
   splitter = ArgSplitter(ArgSplitterTest._known_scope_infos)
   splitter.split_args(shlex.split(args_str))
   self.assertTrue(isinstance(splitter.help_request, UnknownGoalHelp))
   self.assertSetEqual(set(unknown_goals), set(splitter.help_request.unknown_goals))
開發者ID:areitz,項目名稱:pants,代碼行數:5,代碼來源:test_arg_splitter.py

示例12: _split_version_request

 def _split_version_request(self, args_str):
   splitter = ArgSplitter(ArgSplitterTest._known_scope_infos)
   splitter.split_args(shlex.split(args_str))
   self.assertTrue(isinstance(splitter.help_request, VersionHelp))
開發者ID:foursquare,項目名稱:pants,代碼行數:4,代碼來源:test_arg_splitter.py


注:本文中的pants.option.arg_splitter.ArgSplitter類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。