简体   繁体   English

如何从 pdoc 隐藏 3rd 方导入?

[英]How to hide 3rd party imports from pdoc?

What is the proper way to hide imports from a documentation generator like pdoc?从像 pdoc 这样的文档生成器中隐藏导入的正确方法是什么?

Specifically, what is best practice for generating docs on adhoc scripts?具体来说,在临时脚本上生成文档的最佳实践是什么?

For example:例如:

import someThirdPartyLibrary

def main():
    someThirdPartyLibrary.somefunc()

if __name__ == '__main__':
    main()

One needs to have someThirdPartyLibrary installed in the environment or pdoc will FAIL.需要在环境中安装一些someThirdPartyLibrary否则 pdoc 将失败。

The options seem to be:选项似乎是:

A. Install all 3rd party libraries to whatever environment I'm running pdoc from. A. 将所有 3rd 方库安装到我正在运行 pdoc 的任何环境中。 This seems totally unnecessary since pdoc doesn't need to actually run the code only load it.这似乎完全没有必要,因为 pdoc 不需要实际运行代码只加载它。

B. Hide imports in main and violate PEP8 B. 在 main 中隐藏导入并违反 PEP8

def main():
    import someThirdPartyLibrary
    someThirdPartyLibrary.somefunc()

if __name__ == '__main__':
    main()

C. Something better than A and B that is best practice? C. 比 A 和 B 更好的最佳实践是什么?

This may not be the answer you are looking for, but pdoc needs to import your code to parse out (dynamic) annotations.这可能不是您正在寻找的答案,但pdoc需要导入您的代码以解析出(动态)注释。 As such, I would really recommend to just go with option A: install all third-party libraries.因此,我真的建议只使用选项 A:安装所有第三方库。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM