当前位置: 首页>>代码示例>>Python>>正文


Python FunctionMetadata.FunctionMetadata类代码示例

本文整理汇总了Python中coalib.settings.FunctionMetadata.FunctionMetadata的典型用法代码示例。如果您正苦于以下问题:Python FunctionMetadata类的具体用法?Python FunctionMetadata怎么用?Python FunctionMetadata使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了FunctionMetadata类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get_metadata

 def get_metadata(cls):
     return FunctionMetadata.merge(
         FunctionMetadata.from_function(
             cls.run,
             omit={"self", "dependency_results"}),
         cls.get_shortlog_checks_metadata(),
         cls.get_body_checks_metadata())
开发者ID:Ana06,项目名称:coala-bears,代码行数:7,代码来源:GitCommitBear.py

示例2: get_metadata

 def get_metadata(cls):
     metadata = FunctionMetadata(
         'run',
         optional_params=cls.get_optional_params(),
         non_optional_params=cls.get_non_optional_params())
     metadata.desc = inspect.getdoc(cls)
     return metadata
开发者ID:CarIosRibeiro,项目名称:coala,代码行数:7,代码来源:ExternalBearWrap.py

示例3: test_from_function

    def test_from_function(self):
        uut = FunctionMetadata.from_function(self.test_from_function)
        self.check_function_metadata_data_set(uut, "test_from_function")

        uut = FunctionMetadata.from_function(TestClass(5, 5).__init__)
        self.check_function_metadata_data_set(uut,
                                              "__init__",
                                              desc="Description",
                                              retval_desc="ret",
                                              non_optional_params={
                                                  "param1": (uut.str_nodesc, None),
                                                  "param2": ("d", None)
                                              },
                                              optional_params={
                                                  "param3": (uut.str_nodesc + " (" + uut.str_optional.format("5") + ")",
                                                             None, 5),
                                                  "param4": ("p4 desc (" + uut.str_optional.format("6") + ")", int, 6)
                                              })

        uut = FunctionMetadata.from_function(TestClass(5, 5).__init__, omit=["param3", "param2"])
        self.check_function_metadata_data_set(uut,
                                              "__init__",
                                              desc="Description",
                                              retval_desc="ret",
                                              non_optional_params={
                                                  "param1": (uut.str_nodesc, None)
                                              },
                                              optional_params={
                                                  "param4": ("p4 desc (" + uut.str_optional.format("6") + ")", int, 6)
                                              })
开发者ID:AhmedKamal1432,项目名称:coala,代码行数:30,代码来源:FunctionMetadataTest.py

示例4: run

        def run(self, filename, file, **kwargs):
            # Get the **kwargs params to forward to `generate_config()`
            # (from `_create_config()`).
            generate_config_kwargs = FunctionMetadata.filter_parameters(
                self._get_generate_config_metadata(), kwargs)

            with self._create_config(
                    filename,
                    file,
                    **generate_config_kwargs) as config_file:
                # And now retrieve the **kwargs for `create_arguments()`.
                create_arguments_kwargs = (
                    FunctionMetadata.filter_parameters(
                        self._get_create_arguments_metadata(), kwargs))

                arguments = (self.get_executable(),) + tuple(
                    self.create_arguments(
                        filename, file, config_file,
                        **create_arguments_kwargs))
                self.debug("Running '{}'".format(' '.join(arguments)))

                output = run_shell_command(
                    arguments,
                    stdin="".join(file) if options["use_stdin"] else None)

                output = tuple(compress(
                    output,
                    (options["use_stdout"], options["use_stderr"])))
                if len(output) == 1:
                    output = output[0]

                process_output_kwargs = FunctionMetadata.filter_parameters(
                    self._get_process_output_metadata(), kwargs)
                return self.process_output(output, filename, file,
                                           **process_output_kwargs)
开发者ID:NalinG,项目名称:coala,代码行数:35,代码来源:Linter.py

示例5: get_metadata

 def get_metadata(cls):
     return FunctionMetadata.merge(
         FunctionMetadata.from_function(
             cls.run,
             omit={'self', 'dependency_results'}),
         cls.get_shortlog_checks_metadata(),
         cls.get_body_checks_metadata(),
         cls.get_issue_checks_metadata())
开发者ID:srisankethu,项目名称:coala-bears,代码行数:8,代码来源:GitCommitBear.py

示例6: test_add_deprecated_param

    def test_add_deprecated_param(self):
        uut = FunctionMetadata(
            'test',
            non_optional_params={'not_optional': ('desc', str)},
            optional_params={'optional': ('desc2', str, 'default')})

        uut.add_deprecated_param('optional', 'old_optional')
        uut.add_deprecated_param('not_optional', 'old_not_optional')

        self.assertEqual(uut.non_optional_params,
                         {'not_optional': ('desc', str)})
        self.assertEqual(uut.optional_params,
                         {'optional': ('desc2', str, 'default'),
                          'old_optional': ('desc2', str, 'default'),
                          'old_not_optional': ('desc', str, None)})
开发者ID:Anmolbansal1,项目名称:coala,代码行数:15,代码来源:FunctionMetadataTest.py

示例7: _func_decorator

    def _func_decorator(func):
        @wraps(func)
        def _new_func(self, *args, **kwargs):
            if not self.section.aspects:
                return func(self, *args, **kwargs)

            aspects = self.section.aspects
            for arg, aspect_value in aspectable_settings.items():
                # Explicit bear setting takes priority over aspects
                if arg in self.section:
                    continue

                taste, aspect_settings = aspect_value
                aspect_instance = aspects.get(taste.aspect_name)
                if aspect_instance:
                    value = aspect_instance.tastes[taste.name]
                    for value_pair in aspect_value[1]:
                        if value_pair[0] == value:
                            kwargs[arg] = value_pair[1]

            return func(self, *args, **kwargs)

        # Keep metadata
        _new_func.__metadata__ = FunctionMetadata.from_function(func)

        return _new_func
开发者ID:Anmolbansal1,项目名称:coala,代码行数:26,代码来源:decorators.py

示例8: get_metadata

 def get_metadata(cls):
     merged_metadata = FunctionMetadata.merge(
         cls._get_process_output_metadata(),
         cls._get_generate_config_metadata(),
         cls._get_create_arguments_metadata())
     merged_metadata.desc = inspect.getdoc(cls)
     return merged_metadata
开发者ID:icoz,项目名称:coala,代码行数:7,代码来源:Linter.py

示例9: test_create_params_from_section_invalid

    def test_create_params_from_section_invalid(self):
        section = Section("name")
        section.append(Setting("bad_param", "value"))
        uut = FunctionMetadata.from_function(TestClass(5, 5).bad_function)

        with self.assertRaises(ValueError):
            uut.create_params_from_section(section)
开发者ID:Tanmay28,项目名称:coala,代码行数:7,代码来源:FunctionMetadataTest.py

示例10: _deprecate_decorator

    def _deprecate_decorator(func):

        def wrapping_function(*args, **kwargs):
            for arg, depr_arg_and_modifier in depr_args.items():
                deprecated_arg, _func = (
                    depr_arg_and_modifier
                    if isinstance(depr_arg_and_modifier, tuple)
                    else (depr_arg_and_modifier, lambda x: x))
                if deprecated_arg in kwargs:
                    print("The setting `{}` is deprecated. Please use `{}` "
                          "instead.".format(deprecated_arg, arg))
                    depr_arg_value = _func.__call__(kwargs[deprecated_arg])
                    if arg in kwargs and depr_arg_value != kwargs[arg]:
                        print('The value of `{}` and `{}` are conflicting.'
                              ' `{}` will be used instead.'.format(
                                  deprecated_arg, arg, arg))
                    else:
                        kwargs[arg] = depr_arg_value
                    del kwargs[deprecated_arg]
            return func(*args, **kwargs)

        new_metadata = FunctionMetadata.from_function(func)
        for arg, depr_arg_and_modifier in depr_args.items():
            deprecated_arg = (depr_arg_and_modifier[0]
                              if isinstance(depr_arg_and_modifier, tuple)
                              else depr_arg_and_modifier)
            new_metadata.add_alias(arg, deprecated_arg)
        wrapping_function.__metadata__ = new_metadata

        return wrapping_function
开发者ID:sudoankit,项目名称:coala,代码行数:30,代码来源:__init__.py

示例11: get_metadata

 def get_metadata(cls):
     """
     :return: Metadata for the run function. However parameters like
              ``self`` or parameters implicitly used by coala (e.g.
              filename for local bears) are already removed.
     """
     return FunctionMetadata.from_function(cls.run, omit={"self", "dependency_results"})
开发者ID:srisankethu,项目名称:coala,代码行数:7,代码来源:Bear.py

示例12: get_metadata

 def get_metadata(cls):
     """
     :return:
         Metadata for the ``analyze`` function extracted from its signature.
         Excludes parameters ``self``, ``filename`` and ``file``.
     """
     return FunctionMetadata.from_function(
         cls.analyze,
         omit={'self', 'filename', 'file'})
开发者ID:Anmolbansal1,项目名称:coala,代码行数:9,代码来源:FileBear.py

示例13: _deprecate_decorator

    def _deprecate_decorator(func):

        logged_deprecated_args = set()

        @wraps(func)
        def wrapping_function(*args, **kwargs):
            for arg, depr_value in wrapping_function.__metadata__.depr_values:
                deprecated_arg = depr_value[0]
                _func = depr_value[1]
                if deprecated_arg in kwargs:
                    if deprecated_arg not in logged_deprecated_args:
                        logging.warning(
                            'The setting `{}` is deprecated. Please use `{}` '
                            'instead.'.format(deprecated_arg, arg))
                        logged_deprecated_args.add(deprecated_arg)
                    depr_arg_value = _func.__call__(kwargs[deprecated_arg])
                    if arg in kwargs and depr_arg_value != kwargs[arg]:
                        logging.warning(
                            'The value of `{}` and `{}` are conflicting.'
                            ' `{}` will be used instead.'.format(
                                  deprecated_arg, arg, arg))
                    else:
                        kwargs[arg] = depr_arg_value
                    del kwargs[deprecated_arg]
            return func(*args, **kwargs)

        new_metadata = FunctionMetadata.from_function(func)
        new_metadata.depr_values = []
        for arg, depr_values in depr_args.items():
            if not isinstance(depr_values, tuple):
                depr_values = (depr_values,)

            if callable(depr_values[-1]):
                deprecated_args = depr_values[:-1]
                default_modifier = depr_values[-1]
            else:
                deprecated_args = depr_values
                default_modifier = _do_nothing

            for depr_value in deprecated_args:
                if isinstance(depr_value, dict):
                    deprecated_arg = list(depr_value.keys())[0]
                    modifier = depr_value[deprecated_arg]
                    new_metadata.depr_values.append((arg,
                                                     (deprecated_arg,
                                                      modifier)))
                else:
                    deprecated_arg = depr_value
                    new_metadata.depr_values.append((arg,
                                                     (deprecated_arg,
                                                      default_modifier)))
                new_metadata.add_deprecated_param(arg, deprecated_arg)

        wrapping_function.__metadata__ = new_metadata

        return wrapping_function
开发者ID:arush0311,项目名称:coala,代码行数:56,代码来源:__init__.py

示例14: get_metadata

        def get_metadata(cls):
            merged_metadata = FunctionMetadata.merge(
                cls._get_process_output_metadata(),
                cls._get_generate_config_metadata(),
                cls._get_create_arguments_metadata())
            merged_metadata.desc = (
                "{}\n\nThis bear uses the {!r} tool.".format(
                    inspect.getdoc(cls), cls.get_executable()))

            return merged_metadata
开发者ID:d6e,项目名称:coala,代码行数:10,代码来源:Linter.py

示例15: run

        def run(self, filename, file, **kwargs):
            # Get the **kwargs params to forward to `generate_config()`
            # (from `_create_config()`).
            generate_config_kwargs = FunctionMetadata.filter_parameters(
                self._get_generate_config_metadata(), kwargs)

            with self._create_config(
                    filename,
                    file,
                    **generate_config_kwargs) as config_file:
                # And now retrieve the **kwargs for `create_arguments()`.
                create_arguments_kwargs = (
                    FunctionMetadata.filter_parameters(
                        self._get_create_arguments_metadata(), kwargs))

                args = self.create_arguments(filename, file, config_file,
                                             **create_arguments_kwargs)

                try:
                    args = tuple(args)
                except TypeError:
                    self.err('The given arguments '
                             '{!r} are not iterable.'.format(args))
                    return

                arguments = (self.get_executable(),) + args
                self.debug("Running '{}'".format(' '.join(arguments)))

                output = run_shell_command(
                    arguments,
                    stdin=''.join(file) if options['use_stdin'] else None,
                    cwd=self.get_config_dir())

                output = tuple(compress(
                    output,
                    (options['use_stdout'], options['use_stderr'])))
                if len(output) == 1:
                    output = output[0]

                process_output_kwargs = FunctionMetadata.filter_parameters(
                    self._get_process_output_metadata(), kwargs)
                return self.process_output(output, filename, file,
                                           **process_output_kwargs)
开发者ID:icoz,项目名称:coala,代码行数:43,代码来源:Linter.py


注:本文中的coalib.settings.FunctionMetadata.FunctionMetadata类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。