Check if Sphinx doc called the script

前端 未结 4 2130
予麋鹿
予麋鹿 2021-01-18 15:41

I am currently trying to generate sphinx documentation for scripts which use the ArcGIS arcpy library.

I am running into an issue when sphinx tries to run the scrip

4条回答
  •  太阳男子
    2021-01-18 16:17

    I do something like this. In my conf.py I add a new variable to the builtins module like:

    # anywhere in conf.py before any of your modules are imported
    import builtins
    builtins.__sphinx_build__ = True
    

    Then in my module code I can write a check like:

    try:
        from some_dependency import SomeClass
    except ImportError:
        try:
            if __sphinx_build__:
                class SomeClass:
                    """Mock the class"""
        except NameError:
            raise ImportError('some_dependency')
    

提交回复
热议问题