【问题标题】:How to generate pydoc documentation for Google Cloud Endpoints method?如何为 Google Cloud Endpoints 方法生成 pydoc 文档?
【发布时间】:2014-03-13 00:02:33
【问题描述】:

我有一组使用 Google Cloud Endpoints 开发的 API。 API 方法如下所示:

@endpoints.method(message_types.VoidMessage, SystemAboutResponse, name="about", http_method="GET")
def about(self, request):
    """
    Returns some simple information about the APIs.

    Example:
      ...
    """
    return SystemAboutResponse(version=API_VERSION)

我想使用 pydoc 为包含此方法的模块生成文档。但是,当我这样做时,由于使用了 endpoints.method 装饰器,文档字符串不会被保留。

我已经看到了其他问题的答案,这些问题展示了在编写自己的装饰器时如何使用 functools.wraps(例如Python decorator handling docstrings),以便它们保留装饰方法的文档字符串。有没有办法使用 Google Cloud Endpoints 装饰器来做到这一点,因为我无法控制这些装饰器的代码?

【问题讨论】:

    标签: python google-app-engine google-cloud-endpoints pydoc


    【解决方案1】:

    我最终对端点库的副本进行了本地修改。更改在 api_config.py 中,特别是 method 装饰器的 apiserving_method_decorator 函数。我将@wraps 装饰添加到invoke_remote 包含在apiserving_method_decorator 中的函数中:

    def method(request_message=message_types.VoidMessage,
               response_message=message_types.VoidMessage,
               name=None,
               path=None,
               http_method='POST',
               cache_control=None,
               scopes=None,
               audiences=None,
               allowed_client_ids=None,
               auth_level=None):
        # ...
    
        def apiserving_method_decorator(api_method):
            # ...
    
            @wraps(api_method)
            def invoke_remote(service_instance, request):
                # ...
    

    然后,当我运行 pydoc 时,我确保端点库的这个本地修改副本位于我的 PYTHONPATH 中。

    【讨论】:

      猜你喜欢
      • 2013-10-04
      • 1970-01-01
      • 2018-06-03
      • 2014-06-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-06-03
      相关资源
      最近更新 更多