Skip to content

Commit f91f7e9

Browse files
committed
Output meta_cache_dir
1 parent f61b3e1 commit f91f7e9

File tree

3 files changed

+43
-21
lines changed

3 files changed

+43
-21
lines changed

src/docbuild/cli/cmd_cli.py

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,23 @@
11
"""Main CLI tool for document operations."""
22

3+
from docbuild.cli.cmd_metadata import stdout
4+
import logging
35
from pathlib import Path
46
import sys
5-
import logging
7+
from typing import Any, cast
8+
69
import click
10+
from pydantic import ValidationError
711
import rich.console
812
import rich.logging
913
from rich.pretty import install
1014
from rich.traceback import install as install_traceback
11-
from pydantic import ValidationError
12-
from typing import Any, cast
1315

1416
from ..__about__ import __version__
15-
from ..config.app import replace_placeholders
17+
from ..config.app import PlaceholderResolutionError, replace_placeholders
1618
from ..config.load import handle_config
1719
from ..models.config_model.app import AppConfig
18-
from ..models.config_model.env import EnvConfig
20+
from ..models.config_model.env import EnvConfig
1921

2022
from ..constants import (
2123
APP_CONFIG_BASENAMES,
@@ -26,7 +28,8 @@
2628
PROJECT_LEVEL_APP_CONFIG_FILENAMES,
2729
)
2830
from ..logging import setup_logging
29-
from ..utils.pidlock import PidFileLock, LockAcquisitionError
31+
from ..models.config_model.app import AppConfig
32+
from ..utils.pidlock import LockAcquisitionError, PidFileLock
3033
from .cmd_build import build
3134
from .cmd_c14n import c14n
3235
from .cmd_config import config
@@ -127,9 +130,9 @@ def cli(
127130
context.verbose = verbose
128131
context.dry_run = dry_run
129132
context.debug = debug
130-
133+
131134
# --- PHASE 1: Load and Validate Application Config (and setup logging) ---
132-
135+
133136
# 1. Load the raw application config dictionary
134137
(
135138
context.appconfigfiles,
@@ -150,6 +153,7 @@ def cli(
150153
try:
151154
# Pydantic validation also handles placeholder replacement via @model_validator
152155
context.appconfig = AppConfig.from_dict(raw_appconfig)
156+
153157
except (ValueError, ValidationError) as e:
154158
log.error("Application configuration failed validation:")
155159
log.error("Error in config file(s): %s", context.appconfigfiles)
@@ -162,7 +166,7 @@ def cli(
162166
setup_logging(cliverbosity=verbose, user_config={'logging': logging_config})
163167

164168
# --- PHASE 2: Load Environment Config, Validate, and Acquire Lock ---
165-
169+
166170
# 1. Load raw Environment Config
167171
(
168172
context.envconfigfiles,
@@ -175,10 +179,10 @@ def cli(
175179
DEFAULT_ENV_CONFIG_FILENAME,
176180
DEFAULT_ENV_CONFIG,
177181
)
178-
182+
179183
# Explicitly cast the raw_envconfig type to silence Pylance
180184
raw_envconfig = cast(dict[str, Any], raw_envconfig)
181-
185+
182186
# 2. VALIDATE the raw environment config dictionary using Pydantic
183187
try:
184188
# Pydantic validation handles placeholder replacement via @model_validator
@@ -191,14 +195,14 @@ def cli(
191195
context.envconfigfiles, e
192196
)
193197
ctx.exit(1)
194-
198+
195199
env_config_path = context.envconfigfiles[0] if context.envconfigfiles else None
196-
200+
197201
# --- CONCURRENCY CONTROL: Use explicit __enter__ and cleanup registration ---
198202
if env_config_path:
199203
# 1. Instantiate the lock object
200204
ctx.obj.env_lock = PidFileLock(resource_path=env_config_path)
201-
205+
202206
try:
203207
# 2. Acquire the lock by explicitly calling the __enter__ method.
204208
ctx.obj.env_lock.__enter__()
@@ -212,16 +216,16 @@ def cli(
212216
# Handles critical errors
213217
log.error("Failed to set up environment lock: %s", e)
214218
ctx.exit(1)
215-
219+
216220
# 3. Register the lock's __exit__ method to be called when the context terminates.
217221
# We use a lambda to supply the three mandatory positional arguments (None)
218222
# expected by __exit__, satisfying the click.call_on_close requirement.
219223
ctx.call_on_close(lambda: ctx.obj.env_lock.__exit__(None, None, None))
220-
224+
221225
# Add subcommand
222226
cli.add_command(build)
223227
cli.add_command(c14n)
224228
cli.add_command(config)
225229
cli.add_command(repo)
226230
cli.add_command(metadata)
227-
cli.add_command(validate)
231+
cli.add_command(validate)

src/docbuild/cli/cmd_metadata/__init__.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import click
77
from rich.console import Console
88

9+
from ...config.app import PlaceholderResolutionError
910
from ...models.doctype import Doctype
1011
from ...utils.contextmgr import make_timer
1112
from ..callback import validate_doctypes
@@ -53,9 +54,22 @@ def metadata(
5354
t = None
5455
try:
5556
with timer() as t:
56-
result = asyncio.run(process(context, doctypes, exitfirst=exitfirst))
57+
result = asyncio.run(
58+
process(context, doctypes, exitfirst=exitfirst)
59+
)
60+
61+
except PlaceholderResolutionError as e:
62+
log.fatal(e)
63+
ctx.exit(10)
64+
5765
finally:
5866
if t and not math.isnan(t.elapsed):
5967
stdout.print(f'Elapsed time {t.elapsed:0.2f}s')
6068

69+
# base_cache_dir_str = context.envconfig.get(
70+
# 'paths', {}).get('base_cache_dir', None)
71+
meta_cache_dir_str = context.envconfig.get(
72+
'paths', {}).get('meta_cache_dir', None)
73+
stdout.print(f'Find your files in meta directory: {meta_cache_dir_str}')
74+
#
6175
ctx.exit(result)

src/docbuild/cli/cmd_metadata/metaprocess.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ async def process_deliverable(
7878
:return: True if successful, False otherwise.
7979
:raises ValueError: If required configuration paths are missing.
8080
"""
81-
log.info('> Processing deliverable: %s', deliverable.full_id)
81+
log.debug('> Processing deliverable: %s', deliverable.full_id)
8282

8383
meta_cache_dir = Path(meta_cache_dir)
8484

@@ -114,12 +114,13 @@ async def process_deliverable(
114114
# The source file for daps might be in a subdirectory
115115
dcfile_path = Path(deliverable.subdir) / deliverable.dcfile
116116

117+
output = str((outputdir / deliverable.dcfile).with_suffix('.json'))
117118
# 2. Run the daps command
118119
cmd = shlex.split(
119120
dapstmpl.format(
120121
builddir=str(worktree_dir),
121122
dcfile=str(worktree_dir / dcfile_path),
122-
output=str(outputdir / deliverable.dcfile),
123+
output=output,
123124
)
124125
)
125126

@@ -130,6 +131,7 @@ async def process_deliverable(
130131
f'DAPS command {" ".join(cmd)!r} failed for {deliverable.full_id}: '
131132
f'{stderr}'
132133
)
134+
log.info("Created metadata %s", output)
133135

134136
# stdout.print(f'> Processed deliverable: {deliverable.pdlangdc}')
135137
return True
@@ -210,7 +212,8 @@ async def process_doctype(
210212
f'temp_repo_dir={temp_repo_dir_str}, meta_cache_dir={meta_cache_dir_str}'
211213
)
212214

213-
# Ensure base directories exist
215+
# Ensure base directories exist.
216+
# This will become obsolete when PR#101 is merged
214217
temp_repo_dir = Path(temp_repo_dir_str)
215218
meta_cache_dir = Path(meta_cache_dir_str)
216219
base_cache_dir = Path(base_cache_dir_str)
@@ -324,4 +327,5 @@ async def process(
324327
console_err.print(f'- {d.full_id}')
325328
return 1
326329

330+
# log.info('Finished process.')
327331
return 0

0 commit comments

Comments
 (0)