Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ uv.lock
# coverage files
.coverage
coverage.xml
invalid_objs.json
16 changes: 8 additions & 8 deletions src/sphinx_codelinks/analyse/analyse.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,15 +198,15 @@ def extract_oneline_need(
if not src_comment.source_file:
row_offset += 1
continue
self.oneline_warnings.append(
AnalyseWarning(
str(src_comment.source_file.filepath),
src_comment.node.start_point.row + row_offset + 1,
resolved.msg,
MarkedContentType.need,
resolved.sub_type.value,
)
lineno = src_comment.node.start_point.row + row_offset + 1
warning = AnalyseWarning(
str(src_comment.source_file.filepath),
lineno,
resolved.msg,
MarkedContentType.need,
resolved.sub_type.value,
)
self.oneline_warnings.append(warning)
row_offset += 1
continue
yield resolved, row_offset
Expand Down
11 changes: 10 additions & 1 deletion src/sphinx_codelinks/cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@


@app.command(no_args_is_help=True)
def analyse(
def analyse( # noqa: PLR0912
config: Annotated[
Path,
typer.Argument(
Expand Down Expand Up @@ -151,6 +151,15 @@ def analyse(
codelinks_config.projects = specifed_project_configs
analyse_projects = AnalyseProjects(codelinks_config)
analyse_projects.run()

# Output warnings to console for CLI users
for src_analyse in analyse_projects.projects_analyse.values():
for warning in src_analyse.oneline_warnings:
logger.warning(
f"Oneline parser warning in {warning.file_path}:{warning.lineno} "
f"- {warning.sub_type}: {warning.msg}",
)

analyse_projects.dump_markers()


Expand Down
24 changes: 24 additions & 0 deletions tests/test_analyse.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,3 +141,27 @@ def test_analyse_oneline_needs(
for src_file in src_analyse.src_files:
cnt_comments += len(src_file.src_comments)
assert cnt_comments == result["num_comments"]


def test_oneline_parser_warnings_are_collected(tmp_path):
"""Test that oneline parser warnings are collected for later output."""
src_dir = TEST_DIR / "data" / "oneline_comment_default"
src_paths = [src_dir / "default_oneliners.c"]

src_analyse_config = SourceAnalyseConfig(
src_files=src_paths,
src_dir=src_dir,
get_need_id_refs=False,
get_oneline_needs=True,
get_rst=False,
oneline_comment_style=ONELINE_COMMENT_STYLE_DEFAULT,
)

src_analyse = SourceAnalyse(src_analyse_config)
src_analyse.run()

# Verify that warnings were collected
assert len(src_analyse.oneline_warnings) == 1
warning = src_analyse.oneline_warnings[0]
assert "too_many_fields" in warning.sub_type
assert warning.lineno == 17
37 changes: 37 additions & 0 deletions tests/test_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,43 @@ def test_analyse(config_path: Path, tmp_path: Path) -> None:
assert marked_content


def test_analyse_outputs_warnings(tmp_path: Path) -> None:
"""Test that the analyse CLI command outputs warnings to console."""
# Create a config file that will produce warnings
src_dir = TEST_DIR / "data" / "oneline_comment_default"
config_dict = {
"codelinks": {
"outdir": str(tmp_path),
"projects": {
"test_project": {
"source_discover": {
"src_dir": str(src_dir),
"include": ["*.c"],
"comment_type": "cpp",
},
"analyse": {
"get_oneline_needs": True,
# Use default oneline_comment_style which will cause warnings
# for the test file with too many fields
},
}
},
}
}

config_file = tmp_path / "test_config.toml"
with config_file.open("w", encoding="utf-8") as f:
toml.dump(config_dict, f)

options: list[str] = ["analyse", str(config_file)]
result = runner.invoke(app, options)

assert result.exit_code == 0
# Verify that warnings are output to console
assert "Oneline parser warning" in result.output
assert "too_many_fields" in result.output


@pytest.mark.parametrize(
("options", "stdout"),
[
Expand Down
Loading