Skip to content

Commit cb3ffde

Browse files
committed
fixed
- outdir type error - exceptions to users
1 parent ba66e17 commit cb3ffde

7 files changed

Lines changed: 56 additions & 6 deletions

File tree

src/sphinx_codelinks/cmd.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ def analyse(
6363

6464
data: CodeLinksConfigType = load_config_from_toml(config)
6565

66-
codelinks_config = CodeLinksConfig(**data)
6766
try:
67+
codelinks_config = CodeLinksConfig(**data)
6868
generate_project_configs(codelinks_config.projects)
6969
except TypeError as e:
7070
raise typer.BadParameter(str(e)) from e
@@ -186,14 +186,14 @@ def load_config_from_toml(toml_file: Path) -> CodeLinksConfigType:
186186
toml_data = tomllib.load(f)
187187

188188
except Exception as e:
189-
raise Exception(
189+
raise typer.BadParameter(
190190
f"Failed to load CodeLinks configuration from {toml_file}"
191191
) from e
192192

193193
codelink_dict = toml_data.get("codelinks")
194194

195195
if not codelink_dict:
196-
raise Exception(f"No 'codelinks' section found in {toml_file}")
196+
raise typer.BadParameter(f"No 'codelinks' section found in {toml_file}")
197197

198198
return cast(CodeLinksConfigType, codelink_dict)
199199

src/sphinx_codelinks/config.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -534,6 +534,9 @@ def __setattr__(self, name: str, value: Any) -> None: # type: ignore[explicit-a
534534
super().__getattribute__("_sphinx_config"), f"src_trace_{name}", value
535535
)
536536

537+
if name == "outdir" and isinstance(value, str):
538+
# Ensure outdir is a Path object
539+
value = Path(value)
537540
return object.__setattr__(self, name, value)
538541

539542
@classmethod
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
[codelinks]
2+
# Configuration for source tracing
3+
set_local_url = true # Set to true to enable local code html and URL generation
4+
local_url_field = "local-url" # Need's field name for local URL
5+
set_remote_url = true # Set to true to enable remote url to be generated
6+
remote_url_field = "remote-url" # Need's field name for remote URL
7+
outdir = "codelinks_output" # Output directory for generated files
8+
9+
# Configuration for source tracing project "dcdc"
10+
[codelinks.projects.dcdc]
11+
remote_url_pattern = "https://github.com/useblocks/sphinx-codelinks/blob/{commit}/{path}#L{line}" # URL pattern for remote source code
12+
13+
[codelinks.projects.dcdc.source_discover]
14+
src_dir = "../dcdc" # Relative path from this TOML config to the source directory
15+
comment_type = "cpp"
16+
exclude = []
17+
include = ["**/*.c", "**/*.h"]
18+
gitignore = false
19+
20+
[codelinks.projects.dcdc.analyse]
21+
get_need_id_refs = false
22+
get_oneline_needs = true
23+
get_rst = false
24+
25+
[codelinks.projects.dcdc.analyse.oneline_comment_style]
26+
# Configuration for oneline comment style
27+
start_sequence = "[[" # Start sequence for oneline comments
28+
end_sequence = "]]" # End sequence for the online comments; default is newline character
29+
field_split_char = "," # Character to split fields in the comment
30+
# Fields that are defined in the oneline comment style
31+
needs_fields = [
32+
{ "name" = "id", "type" = "str" },
33+
{ "name" = "title", "type" = "str" },
34+
{ "name" = "type", "type" = "str", "default" = "impl" },
35+
{ "name" = "links", "type" = "list[str]", "default" = [
36+
] },
37+
]
38+
39+
[codelinks.projects.src]
40+
remote_url_pattern = "https://github.com/useblocks/sphinx-codelinks/blob/{commit}/{path}#L{line}"
41+
42+
[codelinks.projects.src.source_discover]
43+
src_dir = "../doc_test/minimum_config"

tests/data/oneline_comment_basic/analyse_config.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[codelinks.projects.basic.source_discover]
22
src_dir = "./"
3-
comment_type = "c"
3+
comment_type = "cpp"
44
exclude = []
55
include = ["**/*.c", "**/*.h"]
66
gitignore = false
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[codelinks.projects.default.source_discover]
22
src_dir = "./"
3-
comment_type = "c"
3+
comment_type = "cpp"
44
exclude = []
55
include = ["**/*.c", "**/*.h"]
66
gitignore = false

tests/test_cmd.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,11 @@
4646

4747

4848
@pytest.mark.parametrize(
49-
("config_path"), [(DATA_DIR / "analyse" / "minimum_config.toml")]
49+
("config_path"),
50+
[
51+
(DATA_DIR / "configs" / "minimum_config.toml"),
52+
(DATA_DIR / "configs" / "full_config.toml"),
53+
],
5054
)
5155
def test_analyse(config_path: Path, tmp_path: Path) -> None:
5256
options: list[str] = ["analyse", str(config_path), "--outdir", str(tmp_path)]

0 commit comments

Comments
 (0)