Skip to content

✨ Write needextend rst from need-id-refs markers#13

Merged
juiwenchen merged 14 commits into
mainfrom
generate-need-extend
Aug 22, 2025
Merged

✨ Write needextend rst from need-id-refs markers#13
juiwenchen merged 14 commits into
mainfrom
generate-need-extend

Conversation

@juiwenchen
Copy link
Copy Markdown
Contributor

@juiwenchen juiwenchen commented Aug 12, 2025

  • Added new module needextend_write, which consume the output of analyse and generate the corresponding rst with needextend directive
  • Added write rst CLI which use needextend_write
  • Added a Sphinx demo project for the whole workflow. Simply run rye run demo:clean to have documentation ready
  • added title option to inject the specified section in the generated rst

@juiwenchen juiwenchen changed the title Generate need extend ✨ Needextend bridge Aug 12, 2025
@juiwenchen juiwenchen requested a review from ubmarco August 12, 2025 15:16
@ubmarco ubmarco force-pushed the generate-need-extend branch from 5677466 to 2e167cd Compare August 14, 2025 12:14
@ubmarco
Copy link
Copy Markdown
Member

ubmarco commented Aug 14, 2025

The invocation works! Some points:

Can you change the CLI interface to codelinks write rst --type need-id-refs.
Then it is expandable in future. Think about writing the source code to a json as discussed in the morning, it could be codelinks write sources.
Also with above proposal we could do codelinks write rst --type need-id-refs --type need so we can write multiple things to a single RST.

This looks like a bug to me. The input
image
leads to
image
Last one wins or it's an exception in SN, haven't tested.
I think the remote url should be a list in case one need is reference by 2 locations.

Generally I think the output will be pretty ugly because the URLs are so long. Maybe https://sphinx-needs.readthedocs.io/en/latest/configuration.html#needs-string-links would help shorten what is displayed while still being able to have the full link.

This leads to an exception:

 rye run codelinks bridge -r foo output/marked_content.json

KeyError: 'foo'

Is there a use case for rye run codelinks bridge --outdir <somedir>? There is just a single file generated with a pre-given name.
Why not give it a single file as in rye run codelinks bridge --outpath <file> that accepts a file path?

@ubmarco ubmarco force-pushed the generate-need-extend branch from 2e167cd to ac6dd5c Compare August 21, 2025 11:47
@juiwenchen juiwenchen force-pushed the generate-need-extend branch from ac6dd5c to 3a62190 Compare August 21, 2025 12:31
@ubmarco ubmarco changed the title ✨ Needextend bridge ✨ Write needextend rst from need-id-refs markers Aug 21, 2025
ubmarco
ubmarco previously approved these changes Aug 21, 2025
Comment thread pyproject.toml Outdated
# needextend demo
"analyse" = "codelinks analyse tests/data/configs/minimum_config.toml"
"analyse:rm" = "rm -rf output/marked_content.json"
"bridge" = "codelinks bridge output/marked_content.json --outdir tests/data/needextend_demo"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

outdated

Comment thread pyproject.toml Outdated
"demo:clean" = { chain = [
"demo:rm",
"analyse:rm",
"bridge:rm",
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

try:
with jsonpath.open("r") as f:
marked_content = json.load(f)
except Exception as e:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

raise typer.BadParameter(
f"Errors occurred during conversion: {linesep.join(errors)}"
)
with outpath.open("w") as f:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

btw, this can also fail easily - permission issues and stuff

@juiwenchen juiwenchen merged commit bd1fae9 into main Aug 22, 2025
8 checks passed
@juiwenchen juiwenchen deleted the generate-need-extend branch August 22, 2025 08:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants