Skip to content

Hide boilerplate in documentation examples #14557

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

Closed
Tracked by #7013
alamb opened this issue Feb 8, 2025 · 5 comments · Fixed by #14544
Closed
Tracked by #7013

Hide boilerplate in documentation examples #14557

alamb opened this issue Feb 8, 2025 · 5 comments · Fixed by #14544
Assignees
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@alamb
Copy link
Contributor

alamb commented Feb 8, 2025

Is your feature request related to a problem or challenge?

Part of #7013

@ugoa has updated our examples in the following PR to all compile and be tested

One major problem I have with using # to hide setup code, is that the sphinx won't respect the leading # and still renders the whole block, which leading huge chunk of ugly code blocks.

Image

Describe the solution you'd like

I would like to be able to hide the setup code for the examples, following the rustdoc convention of ignoring lines that begin with #

For example, in our docs here:

//! ```rust
//! # use datafusion::prelude::*;
//! # use datafusion::error::Result;
//! # use datafusion::functions_aggregate::expr_fn::min;
//! # use datafusion::arrow::record_batch::RecordBatch;
//!
//! # #[tokio::main]
//! # async fn main() -> Result<()> {
//! let ctx = SessionContext::new();
//!
//! // create the dataframe
//! let df = ctx.read_csv("tests/data/example.csv", CsvReadOptions::new()).await?;
//!
//! // create a plan
//! let df = df.filter(col("a").lt_eq(col("b")))?
//! .aggregate(vec![col("a")], vec![min(col("b"))])?
//! .limit(0, Some(100))?;
//!
//! // execute the plan
//! let results: Vec<RecordBatch> = df.collect().await?;
//!
//! // format the results
//! let pretty_results = arrow::util::pretty::pretty_format_batches(&results)?
//! .to_string();
//!
//! let expected = vec![
//! "+---+----------------+",
//! "| a | min(?table?.b) |",
//! "+---+----------------+",
//! "| 1 | 2 |",
//! "+---+----------------+"
//! ];
//!
//! assert_eq!(pretty_results.trim().lines().collect::<Vec<_>>(), expected);
//! # Ok(())
//! # }

Lines that start with # are not rendered in the markdown docs on https://docs.rs/datafusion/latest/datafusion/index.html

Image

Describe alternatives you've considered

I wonder if we can find find some way to add a sphinx plugin or something to avoid rendering the blocks of ugly code.

You can build and test the documentation locally by following the instructions here: https://github.com/apache/datafusion/blob/main/docs/README.md

I normally do

cd docs
./build.sh
open build/html/index.html

Additional context

No response

@alamb
Copy link
Contributor Author

alamb commented Feb 8, 2025

I think this would be a good first issue as it is super helpful, well specified, and doesn't need deep DataFusion internals expertise

@bhavesh26
Copy link

@alamb assign this to me

@alamb
Copy link
Contributor Author

alamb commented Feb 8, 2025

@alamb assign this to me

Thanks @bhavesh26

Note in the future you can put the comment take and the bot will automatically assign it to you

@ugoa
Copy link
Contributor

ugoa commented Feb 8, 2025

Please help review workaround solution in 997504f in #14544

@alamb
Copy link
Contributor Author

alamb commented Feb 10, 2025

Please help review workaround solution in 997504f in #14544

From my perspective the solution your PR is a real fix @ugoa (not just a workaround)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants