Skip to content

Commit 6e55a28

Browse files
committed
removed option types
1 parent d31f2ed commit 6e55a28

3 files changed

Lines changed: 16 additions & 54 deletions

File tree

src/sphinx_codelinks/cmd.py

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
from collections import deque
2-
from enum import Enum
32
from os import linesep
43
from pathlib import Path
54
import tomllib
65
from typing import Annotated, TypeAlias, cast
76

87
import typer
98

10-
from sphinx_codelinks.analyse.models import MarkedContentType
119
from sphinx_codelinks.analyse.projects import AnalyseProjects
1210
from sphinx_codelinks.config import (
1311
CodeLinksConfig,
@@ -221,11 +219,6 @@ def discover(
221219
typer.echo(file_path)
222220

223221

224-
class SupportedMarkerTypes(str, Enum):
225-
need = "need"
226-
need_id_refs = "need-id-refs"
227-
228-
229222
@write_app.command("rst", no_args_is_help=True)
230223
def write_rst( # noqa: PLR0913 # for CLI, so it takes as many as it requires
231224
jsonpath: Annotated[
@@ -240,21 +233,12 @@ def write_rst( # noqa: PLR0913 # for CLI, so it takes as many as it requires
240233
resolve_path=True,
241234
),
242235
],
243-
types: Annotated[
244-
list[SupportedMarkerTypes],
245-
typer.Option(
246-
"--types",
247-
"-t",
248-
help="The types of marked content to be exported",
249-
show_default=True,
250-
),
251-
] = [SupportedMarkerTypes.need_id_refs], # noqa: B006 # to show the default value on CLI
252236
outpath: Annotated[
253237
Path,
254238
typer.Option(
255-
"--outdir",
239+
"--outpath",
256240
"-o",
257-
help="The output path for needextend.rst",
241+
help="The output path for generated rst file",
258242
show_default=True,
259243
dir_okay=False,
260244
file_okay=True,
@@ -284,9 +268,7 @@ def write_rst( # noqa: PLR0913 # for CLI, so it takes as many as it requires
284268
) -> None:
285269
"""Generate needextend.rst from the extracted obj in JSON."""
286270
logger.configure(verbose, quiet)
287-
convert_marked_content(
288-
jsonpath, outpath, remote_url_field, cast(list[MarkedContentType], types), title
289-
)
271+
convert_marked_content(jsonpath, outpath, remote_url_field, title)
290272

291273

292274
def load_config_from_toml(toml_file: Path) -> CodeLinksConfigType:

src/sphinx_codelinks/needextend_write.py

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -167,12 +167,9 @@ def convert_marked_content(
167167
jsonpath: Path,
168168
outpath: Path,
169169
remote_url_field: str = "remote-url",
170-
types: list[MarkedContentType] | None = None,
171170
title: str | None = None,
172171
) -> None:
173172
"""Convert marked objects extracted by anaylse CLI to needextend in RST"""
174-
if not types:
175-
types = [MarkedContentType.need_id_refs]
176173
with jsonpath.open("r") as f:
177174
marked_content = json.load(f)
178175

@@ -183,7 +180,11 @@ def convert_marked_content(
183180
obj for objs in marked_content.values() for obj in objs
184181
]
185182

186-
intersted_objs = [obj for obj in marked_objs if obj["type"] in types]
183+
intersted_objs = [
184+
obj
185+
for obj in marked_objs
186+
if obj["type"] == MarkedContentType.need_id_refs.value
187+
]
187188

188189
for obj in intersted_objs:
189190
schema = MarkedContentSchema(**obj)
@@ -212,21 +213,8 @@ def convert_marked_content(
212213
remote_url=obj["remote_url"],
213214
)
214215
needextend_texts.append(needextend_text)
215-
elif obj["type"] == MarkedContentType.need.value and obj["need"]:
216-
oneline_need_id = obj["need"].get("id")
217-
if not oneline_need_id:
218-
warnings.append(
219-
f"Oneline-need definition {obj} does not have 'id' field in 'need', skipping."
220-
)
221-
continue
222-
needextend_text = NEEDEXTEND_TEMPLATE.safe_substitute(
223-
need_id=oneline_need_id,
224-
remote_url_field=remote_url_field,
225-
remote_url=obj["remote_url"],
226-
)
227-
needextend_texts.append(needextend_text)
228216

229217
with outpath.open("w") as f:
230218
f.writelines(needextend_texts)
231219

232-
logger.info(f"Generated needextend.rst in {outpath}")
220+
logger.info(f"Generated {outpath}")

tests/test_needextend_write.py

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,16 @@
11
from pathlib import Path
22

3-
import pytest
4-
5-
from sphinx_codelinks.analyse.models import MarkedContentType
63
from sphinx_codelinks.needextend_write import convert_marked_content
74

85

9-
@pytest.mark.parametrize(
10-
"types",
11-
[
12-
None, # Default case
13-
[MarkedContentType.need_id_refs],
14-
[MarkedContentType.need],
15-
[MarkedContentType.rst],
16-
[MarkedContentType.need, MarkedContentType.need_id_refs],
17-
],
18-
)
19-
def test_convert_marked_content(types, tmp_path):
6+
def test_convert_marked_content(tmp_path):
207
jsonpath = Path(__file__).parent / "data" / "analyse" / "marked_content.json"
218
outpath = tmp_path / "needextend.rst"
22-
convert_marked_content(jsonpath, outpath, types=types)
9+
convert_marked_content(jsonpath, outpath)
2310

2411
assert outpath.exists()
12+
13+
with outpath.open("r") as f:
14+
content = f.readlines()
15+
16+
assert content

0 commit comments

Comments
 (0)