Skip to content

Commit af5e568

Browse files
authored
Merge branch 'main' into 53-git-root-config-option
2 parents 6083b69 + bf13214 commit af5e568

File tree

5 files changed

+70
-8
lines changed

5 files changed

+70
-8
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,4 @@ uv.lock
2323
# coverage files
2424
.coverage
2525
coverage.xml
26+
invalid_objs.json

src/sphinx_codelinks/analyse/analyse.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -202,15 +202,15 @@ def extract_oneline_need(
202202
if not src_comment.source_file:
203203
row_offset += 1
204204
continue
205-
self.oneline_warnings.append(
206-
AnalyseWarning(
207-
str(src_comment.source_file.filepath),
208-
src_comment.node.start_point.row + row_offset + 1,
209-
resolved.msg,
210-
MarkedContentType.need,
211-
resolved.sub_type.value,
212-
)
205+
lineno = src_comment.node.start_point.row + row_offset + 1
206+
warning = AnalyseWarning(
207+
str(src_comment.source_file.filepath),
208+
lineno,
209+
resolved.msg,
210+
MarkedContentType.need,
211+
resolved.sub_type.value,
213212
)
213+
self.oneline_warnings.append(warning)
214214
row_offset += 1
215215
continue
216216
yield resolved, row_offset

src/sphinx_codelinks/cmd.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,15 @@ def analyse( # noqa: PLR0912 # for CLI, so it needs the branches
157157
codelinks_config.projects = specifed_project_configs
158158
analyse_projects = AnalyseProjects(codelinks_config)
159159
analyse_projects.run()
160+
161+
# Output warnings to console for CLI users
162+
for src_analyse in analyse_projects.projects_analyse.values():
163+
for warning in src_analyse.oneline_warnings:
164+
logger.warning(
165+
f"Oneline parser warning in {warning.file_path}:{warning.lineno} "
166+
f"- {warning.sub_type}: {warning.msg}",
167+
)
168+
160169
analyse_projects.dump_markers()
161170

162171

tests/test_analyse.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,3 +210,18 @@ def test_git_root_auto_detection_when_not_configured(tmp_path):
210210
# We just verify it's not None (since this test runs in the sphinx-codelinks repo)
211211
assert src_analyse.git_root is not None
212212
assert (src_analyse.git_root / ".git").exists()
213+
oneline_comment_style=ONELINE_COMMENT_STYLE_DEFAULT,
214+
)
215+
216+
def test_oneline_parser_warnings_are_collected(tmp_path):
217+
"""Test that oneline parser warnings are collected for later output."""
218+
src_dir = TEST_DIR / "data" / "oneline_comment_default"
219+
src_paths = [src_dir / "default_oneliners.c"]
220+
src_analyse = SourceAnalyse(src_analyse_config)
221+
src_analyse.run()
222+
223+
# Verify that warnings were collected
224+
assert len(src_analyse.oneline_warnings) == 1
225+
warning = src_analyse.oneline_warnings[0]
226+
assert "too_many_fields" in warning.sub_type
227+
assert warning.lineno == 17

tests/test_cmd.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,43 @@ def test_analyse(config_path: Path, tmp_path: Path) -> None:
6767
assert marked_content
6868

6969

70+
def test_analyse_outputs_warnings(tmp_path: Path) -> None:
71+
"""Test that the analyse CLI command outputs warnings to console."""
72+
# Create a config file that will produce warnings
73+
src_dir = TEST_DIR / "data" / "oneline_comment_default"
74+
config_dict = {
75+
"codelinks": {
76+
"outdir": str(tmp_path),
77+
"projects": {
78+
"test_project": {
79+
"source_discover": {
80+
"src_dir": str(src_dir),
81+
"include": ["*.c"],
82+
"comment_type": "cpp",
83+
},
84+
"analyse": {
85+
"get_oneline_needs": True,
86+
# Use default oneline_comment_style which will cause warnings
87+
# for the test file with too many fields
88+
},
89+
}
90+
},
91+
}
92+
}
93+
94+
config_file = tmp_path / "test_config.toml"
95+
with config_file.open("w", encoding="utf-8") as f:
96+
toml.dump(config_dict, f)
97+
98+
options: list[str] = ["analyse", str(config_file)]
99+
result = runner.invoke(app, options)
100+
101+
assert result.exit_code == 0
102+
# Verify that warnings are output to console
103+
assert "Oneline parser warning" in result.output
104+
assert "too_many_fields" in result.output
105+
106+
70107
@pytest.mark.parametrize(
71108
("options", "stdout"),
72109
[

0 commit comments

Comments
 (0)