python - 如何为 Google Cloud Endpoints 方法生成 pydoc 文档?

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

我有一组使用 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 装饰器来做到这一点,因为我无法控制这些装饰器的代码?

最佳答案

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

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 中。

关于python - 如何为 Google Cloud Endpoints 方法生成 pydoc 文档?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21765597/

相关文章:

java - 将图像/视频从 Android/iOS 发送到 Google Cloud Endpoints

android - 将对谷歌云端点的访问限制为 Android 应用程序

android - 将模块部署到 App Engine 选项在 Android Studio 上不可用

python - AWS Hbase : Invalid method name: 'getTableNames'

java - 如何授予经过身份验证的网站用户(App Engine 标准)访问 Google Cloud Storage 存储桶的权限?

python - Django 中一个请求中的 GraphQL 多个查询

google-app-engine - 未找到 API 包 'urlfetch' 或调用 'Fetch()'

python - App 引擎命名空间

python - ArangoDB 读取超时(读取超时=60)

python - Django,移动变量