Check if Sphinx doc called the script

纵然是瞬间 提交于 2019-12-01 19:32:22

The solution I came up with, while probably no-where near ideal, is to simply check

if 'sphinx' in sys.modules:
    in_mxds = [r"C:/test.mxd"]
else:
    in_mxds = arcpy.GetParameterAsText(1)

This will ensure the script is not trying to get a parameter from the GUI which isn't set when generating sphinx documents.

If your project is importing sphinx (in my case a sphinx extension), the following may also work for you

import os
import sys
if os.path.basename(sys.argv[0]) == "sphinx-build":
    # code for when sphinx is running
else:
    # code for regular application

I'm not sure if that will work on Windows or if it should be something like

if os.path.basename(sys.argv[0]) in ["sphinx-build", "sphinx-build.exe"]:
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!