Skip to content

Commit 79ba31d

Browse files
authored
Merge pull request #106 from openSUSE/toms/4-automate-json
Automate JSON generation
2 parents 8530a19 + 0c3f067 commit 79ba31d

17 files changed

Lines changed: 1057 additions & 526 deletions

File tree

changelog.d/106.feature.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Introduces the new :command:`docbuild metadata` to automate the process of generating and caching documentation metadata.

src/docbuild/cli/cmd_cli.py

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from rich.pretty import install
1010
from rich.traceback import install as install_traceback
1111
from pydantic import ValidationError
12-
from typing import Any, cast
12+
from typing import Any, cast
1313

1414
from ..__about__ import __version__
1515
from ..config.app import replace_placeholders
@@ -112,7 +112,6 @@ def cli(
112112
:param env_config: Filename to a environment's TOML config file.
113113
:param kwargs: Additional keyword arguments.
114114
"""
115-
116115
if ctx.invoked_subcommand is None:
117116
# If no subcommand is invoked, show the help message
118117
click.echo(10 * '-')
@@ -127,9 +126,9 @@ def cli(
127126
context.verbose = verbose
128127
context.dry_run = dry_run
129128
context.debug = debug
130-
129+
131130
# --- PHASE 1: Load and Validate Application Config (and setup logging) ---
132-
131+
#
133132
# 1. Load the raw application config dictionary
134133
(
135134
context.appconfigfiles,
@@ -162,7 +161,7 @@ def cli(
162161
setup_logging(cliverbosity=verbose, user_config={'logging': logging_config})
163162

164163
# --- PHASE 2: Load Environment Config, Validate, and Acquire Lock ---
165-
164+
#
166165
# 1. Load raw Environment Config
167166
(
168167
context.envconfigfiles,
@@ -175,10 +174,10 @@ def cli(
175174
DEFAULT_ENV_CONFIG_FILENAME,
176175
DEFAULT_ENV_CONFIG,
177176
)
178-
177+
179178
# Explicitly cast the raw_envconfig type to silence Pylance
180179
raw_envconfig = cast(dict[str, Any], raw_envconfig)
181-
180+
182181
# 2. VALIDATE the raw environment config dictionary using Pydantic
183182
try:
184183
# Pydantic validation handles placeholder replacement via @model_validator
@@ -191,14 +190,14 @@ def cli(
191190
context.envconfigfiles, e
192191
)
193192
ctx.exit(1)
194-
193+
195194
env_config_path = context.envconfigfiles[0] if context.envconfigfiles else None
196-
195+
197196
# --- CONCURRENCY CONTROL: Use explicit __enter__ and cleanup registration ---
198197
if env_config_path:
199198
# 1. Instantiate the lock object
200199
ctx.obj.env_lock = PidFileLock(resource_path=env_config_path)
201-
200+
202201
try:
203202
# 2. Acquire the lock by explicitly calling the __enter__ method.
204203
ctx.obj.env_lock.__enter__()
@@ -212,16 +211,16 @@ def cli(
212211
# Handles critical errors
213212
log.error("Failed to set up environment lock: %s", e)
214213
ctx.exit(1)
215-
214+
216215
# 3. Register the lock's __exit__ method to be called when the context terminates.
217216
# We use a lambda to supply the three mandatory positional arguments (None)
218217
# expected by __exit__, satisfying the click.call_on_close requirement.
219218
ctx.call_on_close(lambda: ctx.obj.env_lock.__exit__(None, None, None))
220-
219+
221220
# Add subcommand
222221
cli.add_command(build)
223222
cli.add_command(c14n)
224223
cli.add_command(config)
225224
cli.add_command(repo)
226225
cli.add_command(metadata)
227-
cli.add_command(validate)
226+
cli.add_command(validate)

src/docbuild/cli/cmd_metadata/__init__.py

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
from .metaprocess import process
1414

1515
# Set up rich consoles for output
16-
console_out = Console()
16+
stdout = Console()
17+
console_err = Console(stderr=True, style='red')
1718

1819

1920
@click.command(help=__doc__)
@@ -22,20 +23,32 @@
2223
nargs=-1,
2324
callback=validate_doctypes,
2425
)
26+
@click.option(
27+
'-E', '--exitfirst',
28+
is_flag=True,
29+
default=False,
30+
show_default=True,
31+
help='Exit on first failed deliverable.',
32+
)
33+
@click.option(
34+
'-S', '--skip-repo-update',
35+
is_flag=True,
36+
default=False,
37+
show_default=True,
38+
help='Skip updating git repositories before processing.',
39+
)
2540
@click.pass_context
2641
def metadata(
2742
ctx: click.Context,
2843
doctypes: tuple[Doctype],
44+
exitfirst: bool,
45+
skip_repo_update: bool,
2946
) -> None:
3047
"""Subcommand to create metadata files.
3148
3249
:param ctx: The Click context object.
3350
"""
3451
context: DocBuildContext = ctx.obj
35-
if context.envconfig is None:
36-
# log.critical('No envconfig found in context.')
37-
raise ValueError('No envconfig found in context.')
38-
3952
timer = make_timer('metadata')
4053
result = 1 # Default exit code for interruption or error
4154

@@ -44,9 +57,12 @@ def metadata(
4457
t = None
4558
try:
4659
with timer() as t:
47-
result = asyncio.run(process(context, doctypes))
60+
result = asyncio.run(
61+
process(context, doctypes,
62+
exitfirst=exitfirst, skip_repo_update=skip_repo_update)
63+
)
4864
finally:
4965
if t and not math.isnan(t.elapsed):
50-
console_out.print(f'Elapsed time {t.elapsed:0.2f}s')
66+
stdout.print(f'Elapsed time {t.elapsed:0.2f}s')
5167

5268
ctx.exit(result)

0 commit comments

Comments
 (0)