Skip to content

feat(pyo3): implement flow spec pretty print and add verbose mode #442

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

lemorage
Copy link
Contributor

@lemorage lemorage commented May 7, 2025

Following #427 and #404, this PR implements the flow spec pretty print in Rust and adds --verbose mode to enable more detailed output.

Changes on Rust side

  1. We first port the code from feat: beautify show cli command with colorful structured output #404, using Rust, and then rewrite it using idiomatic Rust style, largely via Display trait.
  2. We add verbose mode to the spec getter method.

Changes on Python side

  1. We change it to use get_spec from Rust side.
  2. We use rich.Tree instead of rich.Console for clearer readability.

Preview

python main.py cocoindex show DocsToKG

image

After adding --verbose flag, it will then produce a more detailed output with full operation specs, including all fields and JSON-like formatting, similar to preview in #404.

Resolves #410.

Copy link
Member

@badmonster0 badmonster0 left a comment

Choose a reason for hiding this comment

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

Beautiful! Thanks a lot!

@lemorage
Copy link
Contributor Author

lemorage commented May 9, 2025

Thanks for all the reviews from @badmonster0. We made a lot of changes since my first comment, so I will try to give a whole summary of them here.

  1. We made an enum for distinct output modes in Rust: verbose or concise.
  2. We made a trait SpecFormatter to enforce the spec formatting logic per output mode for each opSpec.
  3. We made two structs RenderedSpecLine and RenderedSpec, to handle the spec line rendering logic on Rust side, so we can grab those and structure the content via rich.Tree simply on Python side.

So now this is what cocoindex show looks like on the terminal. Basically, for verbose mode, all the nested contents will be unfolded (e.g., a JSON struct), but in concise mode, not.

The following output can be acquired by running python main.py cocoindex show under cocoindex/examples/text_embedding.

cocoindex show in different modes

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.

[FEATURE] Implement flow spec pretty print in Rust
2 participants