如何为Google云端点方法生成pydoc文档?

2024-10-01 11:30:29 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一组使用Google云端点开发的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为包含此方法的模块生成文档。但是,在执行此操作时,由于使用了端点.方法装饰工。在

我已经看到了其他问题的答案,这些问题展示了如何使用函数工具.wrapps(例如Python decorator handling docstrings)编写您自己的decorator,以便它们保留修饰方法的docstring时。既然我无法控制这些装饰器的代码,那么有没有什么方法可以用Google云端点装饰器来实现呢?在


Tags: 方法nameapimessagegoogle装饰decoratormethod
1条回答
网友
1楼 · 发布于 2024-10-01 11:30:29

最后我对端点库的一个副本进行了本地修改。变化在api中_配置.py,特别是method装饰器的apiserving_method_decorator函数。我向@wraps中包含的invoke_remote函数添加了@wraps装饰:

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

相关问题 更多 >