geopython / GeoHealthCheck

Service Status and QoS Checker for OGC Web Services
https://geohealthcheck.org
MIT License
84 stars 71 forks source link

autodoc fails on ReadTheDocs Sphinx documentation build #363

Closed justb4 closed 3 years ago

justb4 commented 3 years ago

Describe the bug Documentation on docs.geohealthcheck.org does not show GHC Python API content. This is due to a failure during documentation build on RTD.

To Reproduce

  1. Commit/push any change to GHC GitHub
  2. Wait for documentation build
  3. Open https://docs.geohealthcheck.org/en/latest/plugins.html#plugin-api-docs
  4. No API documentation is shown

Expected Behaviour Show API documentation like on demo site: https://demo.geohealthcheck.org/static/docs/plugins.html#plugin-api-docs

Screenshots or Logfiles The RTD Build logfile, e.g. https://readthedocs.org/api/v2/build/13646914.txt shows this recurring error:

WARNING: autodoc: failed to import module 'check' from module 'GeoHealthCheck'; the following exception was raised:
Traceback (most recent call last):
  File "/home/docs/checkouts/readthedocs.org/user_builds/geohealthcheck/envs/latest/lib/python3.7/site-packages/sphinx/ext/autodoc/importer.py", line 66, in import_module
    return importlib.import_module(modname)
  File "/home/docs/checkouts/readthedocs.org/user_builds/geohealthcheck/envs/latest/lib/python3.7/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 728, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/home/docs/checkouts/readthedocs.org/user_builds/geohealthcheck/checkouts/latest/GeoHealthCheck/__init__.py", line 30, in <module>
    from util import read
  File "/home/docs/checkouts/readthedocs.org/user_builds/geohealthcheck/checkouts/latest/GeoHealthCheck/util.py", line 42, in <module>
    from init import App
  File "/home/docs/checkouts/readthedocs.org/user_builds/geohealthcheck/checkouts/latest/GeoHealthCheck/init.py", line 129, in <module>
    App.init()
  File "/home/docs/checkouts/readthedocs.org/user_builds/geohealthcheck/checkouts/latest/GeoHealthCheck/init.py", line 70, in init
    app.config.from_pyfile('../instance/config_site.py')
  File "/home/docs/checkouts/readthedocs.org/user_builds/geohealthcheck/envs/latest/lib/python3.7/site-packages/flask/config.py", line 131, in from_pyfile
    with open(filename, mode="rb") as config_file:
FileNotFoundError: [Errno 2] Unable to load configuration file (No such file or directory): '/home/docs/checkouts/readthedocs.org/user_builds/geohealthcheck/checkouts/latest/GeoHealthCheck/../instance/config_site.py'

Context (please complete the following information):

If running with Docker: no problem

Additional context Problem seems to be due to the file GeoHealthCheck/app.py being loaded in RTD. This triggers App.init() being called. The following lines in that file show the problem (and potential solution):

    # in App.init():
.
.   
     app = Flask(__name__)

        # Read and override configs
        app.config.from_pyfile('config_main.py')
        app.config.from_pyfile('../instance/config_site.py')
        app.config.from_envvar('GHC_SETTINGS', silent=True)

'../instance/config_site.py' is only present in installed/deployed GHC instances. Hence the problem is not triggered for e.g. the 'demo' site.

Proposed Solution

Ignore error if '../instance/config_site.py' not present by using silent=True and issue just a warning, like:

config_file = '../instance/config_site.py'
if not app.config.from_pyfile(config_file,  silent=True):
    LOGGER.warning('Config file: %s not found - ignoring' % config_file)

or better: depend on os.environ['SPHINX_BUILD'] ( is '1' during doc builds) as for real deployments not finding config file is really a fatal error:

        # Read and override configs
        app.config.from_pyfile('config_main.py')
        app.config.from_pyfile('../instance/config_site.py', 
                             silent=os.environ['SPHINX_BUILD'] == '1')
        app.config.from_envvar('GHC_SETTINGS', silent=True)
justb4 commented 3 years ago

autodoc now enabled via PR #383, closing.