Skip to content

Commit

Permalink
Update config mechanism; use project-specific app context.
Browse files Browse the repository at this point in the history
  • Loading branch information
felixfontein committed Aug 20, 2022
1 parent d51e64b commit bd496a6
Show file tree
Hide file tree
Showing 10 changed files with 24 additions and 12 deletions.
12 changes: 12 additions & 0 deletions src/antsibull_docs/app_context.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Author: Felix Fontein <[email protected]>
# 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()
6 changes: 3 additions & 3 deletions src/antsibull_docs/cli/antsibull_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down Expand Up @@ -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')
Expand Down
2 changes: 1 addition & 1 deletion src/antsibull_docs/cli/doc_commands/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@
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
from antsibull_core.logging import log
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
Expand Down
2 changes: 1 addition & 1 deletion src/antsibull_docs/cli/doc_commands/current.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)
Expand Down
2 changes: 1 addition & 1 deletion src/antsibull_docs/cli/doc_commands/devel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/antsibull_docs/cli/doc_commands/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/antsibull_docs/cli/doc_commands/sphinx_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
2 changes: 1 addition & 1 deletion src/antsibull_docs/cli/doc_commands/stable.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@
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
DOC_PARSING_BACKEND_CHOICES_F = p.Field(
'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
Expand Down

0 comments on commit bd496a6

Please sign in to comment.