diff --git a/compendium_v2/__init__.py b/compendium_v2/__init__.py index 69673b9f75c396332fb87c8284ae335ff34209be..622565f2f7a3a5d39c1df9b562e11bd336dfc230 100644 --- a/compendium_v2/__init__.py +++ b/compendium_v2/__init__.py @@ -17,6 +17,22 @@ def migrate_database(config: dict) -> None: migration_utils.upgrade(dsn) +def _create_app(app_config) -> Flask: + # used by sphinx to create documentation without config and db migrations + app = Flask(__name__) + CORS(app) + + app.config['CONFIG_PARAMS'] = app_config + + from compendium_v2.routes import default + app.register_blueprint(default.routes, url_prefix='/') + + from compendium_v2.routes import api + app.register_blueprint(api.routes, url_prefix='/api') + + return app + + def create_app() -> Flask: """ overrides default settings with those found @@ -30,16 +46,7 @@ def create_app() -> Flask: with open(os.environ['SETTINGS_FILENAME']) as f: app_config = config.load(f) - app = Flask(__name__) - CORS(app) - - app.config['CONFIG_PARAMS'] = app_config - - from compendium_v2.routes import default - app.register_blueprint(default.routes, url_prefix='/') - - from compendium_v2.routes import api - app.register_blueprint(api.routes, url_prefix='/api') + app = _create_app(app_config) logging.info('Flask app initialized') diff --git a/compendium_v2/routes/api.py b/compendium_v2/routes/api.py index e4fd41042a065ed283dd21b2b3da84f0e749bd43..ec39ab773ee426a387b49911a7399dd3b82662d2 100644 --- a/compendium_v2/routes/api.py +++ b/compendium_v2/routes/api.py @@ -1,15 +1,3 @@ -""" -API Endpoints -========================= - -.. contents:: :local: - -/api/ ---------------------- - - - -""" import logging from flask import Blueprint diff --git a/compendium_v2/routes/default.py b/compendium_v2/routes/default.py index eaf1420685079ac49119b3a84355df8f49d752c8..9d2ed2f9bef6e6e8d742a7d8ad02d41d99f90f5d 100644 --- a/compendium_v2/routes/default.py +++ b/compendium_v2/routes/default.py @@ -1,15 +1,3 @@ -""" -Default Endpoints -========================= - -.. contents:: :local: - -/version ---------------------- - -.. autofunction:: compendium_v2.routes.default.version - -""" import pkg_resources from flask import Blueprint, jsonify, render_template, Response diff --git a/docs/source/api.rst b/docs/source/api.rst index 1db2969abd99b080c252bb06be8b75e5b7572c82..bd4f24693c5a6e754886afa585b3e4d04945c0f3 100644 --- a/docs/source/api.rst +++ b/docs/source/api.rst @@ -9,14 +9,8 @@ Responses to valid requests are returned as JSON messages. The server will therefore return an error unless `application/json` is in the `Accept` request header field. -HTTP communication and JSON grammar details are -beyond the scope of this document. -Please refer to [RFC 2616](https://tools.ietf.org/html/rfc2616) -and www.json.org for more details. - -.. contents:: :local: - -.. automodule:: compendium_v2.routes.default - -.. automodule:: compendium_v2.routes.api +.. qrefflask:: compendium_v2:_create_app(None) + :autoquickref: +.. autoflask:: compendium_v2:_create_app(None) + :undoc-static: diff --git a/docs/source/conf.py b/docs/source/conf.py index 48b40e921dbb72df8f82c3604f36a250bd557c14..62ba0d569569f45347cb9c6a3974ab948a79b3f7 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -73,7 +73,9 @@ release = '0.0' extensions = [ 'sphinx_rtd_theme', 'sphinx.ext.autodoc', - 'sphinx.ext.coverage' + 'sphinx.ext.coverage', + 'sphinxcontrib.autohttp.flask', + 'sphinxcontrib.autohttp.flaskqref' ] # Add any paths that contain templates here, relative to this directory. diff --git a/docs/source/publishers.rst b/docs/source/publishers.rst index 011de02fd88a431ec847dc8c98c68a221e2a864c..85818b3f9a1370bacff99e806de11ca1951248bc 100644 --- a/docs/source/publishers.rst +++ b/docs/source/publishers.rst @@ -11,4 +11,3 @@ Publishers .. automodule:: compendium_v2.publishers.survey_publisher_2022 :members: - diff --git a/requirements.txt b/requirements.txt index 1dc1ed6bb4758b60024bae897c8f68813c895b45..f409d9fa4cb574651214e8f455436d4298aef041 100644 --- a/requirements.txt +++ b/requirements.txt @@ -13,6 +13,7 @@ python-dotenv sphinx sphinx-rtd-theme +sphinxcontrib-httpdomain tox mypy