From bd496a67aeeed86c37e3d20147677ecd09f685ad Mon Sep 17 00:00:00 2001 From: Felix Fontein Date: Sat, 20 Aug 2022 16:22:16 +0200 Subject: [PATCH] Update config mechanism; use project-specific app context. --- src/antsibull_docs/app_context.py | 12 ++++++++++++ src/antsibull_docs/cli/antsibull_docs.py | 6 +++--- src/antsibull_docs/cli/doc_commands/collection.py | 2 +- src/antsibull_docs/cli/doc_commands/current.py | 2 +- src/antsibull_docs/cli/doc_commands/devel.py | 2 +- .../cli/doc_commands/lint_collection_docs.py | 2 +- src/antsibull_docs/cli/doc_commands/plugin.py | 2 +- src/antsibull_docs/cli/doc_commands/sphinx_init.py | 2 +- src/antsibull_docs/cli/doc_commands/stable.py | 2 +- .../schemas/{config.py => app_context.py} | 4 ++-- 10 files changed, 24 insertions(+), 12 deletions(-) create mode 100644 src/antsibull_docs/app_context.py rename src/antsibull_docs/schemas/{config.py => app_context.py} (91%) diff --git a/src/antsibull_docs/app_context.py b/src/antsibull_docs/app_context.py new file mode 100644 index 00000000..9ac405c1 --- /dev/null +++ b/src/antsibull_docs/app_context.py @@ -0,0 +1,12 @@ +# Author: Felix Fontein +# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or +# https://www.gnu.org/licenses/gpl-3.0.txt) +# SPDX-License-Identifier: GPL-3.0-or-later +# SPDX-FileCopyrightText: 2022, Ansible Project +"""Local app and lib context provider""" + +from antsibull_core.app_context import lib_ctx, AppContextWrapper +from antsibull_docs.schemas.app_context import DocsAppContext + + +app_ctx: AppContextWrapper[DocsAppContext] = AppContextWrapper() diff --git a/src/antsibull_docs/cli/antsibull_docs.py b/src/antsibull_docs/cli/antsibull_docs.py index a36e6cab..0abb7891 100644 --- a/src/antsibull_docs/cli/antsibull_docs.py +++ b/src/antsibull_docs/cli/antsibull_docs.py @@ -30,7 +30,7 @@ from ..constants import DOCUMENTABLE_PLUGINS # noqa: E402 from ..docs_parsing.fqcn import is_fqcn # noqa: E402 -from ..schemas.config import DocsConfigModel +from ..schemas.app_context import DocsAppContext # noqa: E402 from .doc_commands import ( # noqa: E402 collection, current, devel, plugin, stable, sphinx_init, lint_collection_docs ) @@ -427,13 +427,13 @@ def run(args: List[str]) -> int: flog.fields(args=parsed_args).info('Arguments parsed') try: - cfg = load_config(parsed_args.config_file, config_model=DocsConfigModel) + cfg = load_config(parsed_args.config_file, app_context_model=DocsAppContext) flog.fields(config=cfg).info('Config loaded') except ConfigError as e: print(e) return 2 - context_data = app_context.create_contexts(args=parsed_args, cfg=cfg) + context_data = app_context.create_contexts(args=parsed_args, cfg=cfg, app_context_model=DocsAppContext) with app_context.app_and_lib_context(context_data) as (app_ctx, dummy_): twiggy.dict_config(app_ctx.logging_cfg.dict()) flog.debug('Set logging config') diff --git a/src/antsibull_docs/cli/doc_commands/collection.py b/src/antsibull_docs/cli/doc_commands/collection.py index 96e7f9f1..66eb785d 100644 --- a/src/antsibull_docs/cli/doc_commands/collection.py +++ b/src/antsibull_docs/cli/doc_commands/collection.py @@ -15,7 +15,6 @@ import aiohttp import asyncio_pool # type: ignore[import] -from antsibull_core import app_context from antsibull_core.collections import install_together from antsibull_core.compat import asyncio_run from antsibull_core.galaxy import CollectionDownloader @@ -23,6 +22,7 @@ from antsibull_core.venv import FakeVenvRunner from .stable import generate_docs_for_all_collections +from ... import app_context if t.TYPE_CHECKING: import semantic_version as semver # pylint:disable=unused-import diff --git a/src/antsibull_docs/cli/doc_commands/current.py b/src/antsibull_docs/cli/doc_commands/current.py index 2fcd6049..6c96ee1f 100644 --- a/src/antsibull_docs/cli/doc_commands/current.py +++ b/src/antsibull_docs/cli/doc_commands/current.py @@ -5,11 +5,11 @@ # SPDX-FileCopyrightText: 2020, Ansible Project """Entrypoint to the antsibull-docs script.""" -from antsibull_core import app_context from antsibull_core.logging import log from antsibull_core.venv import FakeVenvRunner from .stable import generate_docs_for_all_collections +from ... import app_context mlog = log.fields(mod=__name__) diff --git a/src/antsibull_docs/cli/doc_commands/devel.py b/src/antsibull_docs/cli/doc_commands/devel.py index 896d95d2..af57bb9c 100644 --- a/src/antsibull_docs/cli/doc_commands/devel.py +++ b/src/antsibull_docs/cli/doc_commands/devel.py @@ -14,7 +14,6 @@ import aiohttp import asyncio_pool # type: ignore[import] -from antsibull_core import app_context from antsibull_core.ansible_core import get_ansible_core from antsibull_core.collections import install_together from antsibull_core.compat import asyncio_run @@ -24,6 +23,7 @@ from antsibull_core.venv import VenvRunner from .stable import generate_docs_for_all_collections +from ... import app_context if t.TYPE_CHECKING: import semantic_version as semver # pylint:disable=unused-import diff --git a/src/antsibull_docs/cli/doc_commands/lint_collection_docs.py b/src/antsibull_docs/cli/doc_commands/lint_collection_docs.py index 5c160a0f..2f6bc201 100644 --- a/src/antsibull_docs/cli/doc_commands/lint_collection_docs.py +++ b/src/antsibull_docs/cli/doc_commands/lint_collection_docs.py @@ -5,9 +5,9 @@ # SPDX-FileCopyrightText: 2020, Ansible Project """Entrypoint to the antsibull-docs script.""" -from antsibull_core import app_context from antsibull_core.logging import log +from ... import app_context from ...collection_links import lint_collection_links from ...lint_extra_docs import lint_collection_extra_docs_files from ...lint_plugin_docs import lint_collection_plugin_docs diff --git a/src/antsibull_docs/cli/doc_commands/plugin.py b/src/antsibull_docs/cli/doc_commands/plugin.py index eb63b6bd..dd29a950 100644 --- a/src/antsibull_docs/cli/doc_commands/plugin.py +++ b/src/antsibull_docs/cli/doc_commands/plugin.py @@ -14,13 +14,13 @@ import sh -from antsibull_core import app_context from antsibull_core.compat import asyncio_run from antsibull_core.logging import log from antsibull_core.vendored.json_utils import _filter_non_json_lines from antsibull_core.venv import FakeVenvRunner from .stable import normalize_plugin_info +from ... import app_context from ...augment_docs import augment_docs from ...collection_links import CollectionLinks from ...docs_parsing import AnsibleCollectionMetadata diff --git a/src/antsibull_docs/cli/doc_commands/sphinx_init.py b/src/antsibull_docs/cli/doc_commands/sphinx_init.py index 904b0f8e..f0dea0d1 100644 --- a/src/antsibull_docs/cli/doc_commands/sphinx_init.py +++ b/src/antsibull_docs/cli/doc_commands/sphinx_init.py @@ -8,9 +8,9 @@ import os import os.path -from antsibull_core import app_context from antsibull_core.logging import log +from ... import app_context from ...jinja2.environment import doc_environment diff --git a/src/antsibull_docs/cli/doc_commands/stable.py b/src/antsibull_docs/cli/doc_commands/stable.py index 3467a829..d1091a6a 100644 --- a/src/antsibull_docs/cli/doc_commands/stable.py +++ b/src/antsibull_docs/cli/doc_commands/stable.py @@ -18,7 +18,6 @@ import asyncio_pool # type: ignore[import] from pydantic import ValidationError -from antsibull_core import app_context from antsibull_core.ansible_core import get_ansible_core from antsibull_core.collections import install_together from antsibull_core.compat import asyncio_run, best_get_loop @@ -27,6 +26,7 @@ from antsibull_core.logging import log from antsibull_core.venv import VenvRunner, FakeVenvRunner +from ... import app_context from ...augment_docs import augment_docs from ...extra_docs import load_collections_extra_docs from ...collection_links import load_collections_links diff --git a/src/antsibull_docs/schemas/config.py b/src/antsibull_docs/schemas/app_context.py similarity index 91% rename from src/antsibull_docs/schemas/config.py rename to src/antsibull_docs/schemas/app_context.py index 5abd5706..8d1475e6 100644 --- a/src/antsibull_docs/schemas/config.py +++ b/src/antsibull_docs/schemas/app_context.py @@ -14,7 +14,7 @@ import pydantic as p from antsibull_core.schemas.validators import convert_bool -from antsibull_core.schemas.config import ConfigModel as CoreConfigModel +from antsibull_core.schemas.context import AppContext as CoreAppContext #: Valid choices for a logging level field @@ -22,7 +22,7 @@ 'ansible-internal', regex='^(auto|ansible-doc|ansible-core-2.13|ansible-internal)$') -class DocsConfigModel(CoreConfigModel): +class DocsAppContext(CoreAppContext): # These are already defined in CoreConfigModel, but might vanish from there eventually breadcrumbs: p.StrictBool = True doc_parsing_backend: str = DOC_PARSING_BACKEND_CHOICES_F