Skip to content

Conversation

@gauthsvenkat
Copy link
Contributor

@gauthsvenkat gauthsvenkat commented Oct 31, 2025

Summary

ruff analyze graph skips jupyter notebooks. This MR addresses that issue so that jupyter notebooks are also considered in the output.

Closes: #21099

Detailed Summary

ruff analyze graph has the following lines to skip if the source is a jupyter notebook.

if matches!(source_type, PySourceType::Ipynb) {
debug!("Ignoring Jupyter notebook: {}", path.display());
continue;
}

Removing these lines alone is not enough (see this comment on the issue). The reason is because in detect() the file under consideration is read and parsed to be a .py file.

pub fn detect(
db: &ModuleDb,
path: &SystemPath,
package: Option<&SystemPath>,
string_imports: StringImports,
) -> Result<Self> {
// Read and parse the source code.
let source = std::fs::read_to_string(path)?;
let parsed = parse(&source, ParseOptions::from(Mode::Module))?;

For notebooks, you'd expect this parsing to fail as a .ipynb and .py are different. However that is not the case as under the hood, contents of a jupyter notebook are JSON. What instead is happening is that the jupyter notebooks get parsed as
a giant nested python dictionary.

Fix

  • detect() now takes two more arguments; source: the raw content and source_type to correctly parse both .py and .ipynb content.
  • in analyze_graph.rs we extract the raw content correctly for both .py and .ipynb.

Test Plan

All existing unit tests pass and added two new tests to make sure the jupyter notebook flow also works.

Added two unit tests for ruff analyze graph to make sure that jupyter
notebooks are handled.
@amyreese amyreese added notebook Related to (Jupyter) notebooks analyze Related to Ruff analyze functionality labels Oct 31, 2025
@github-actions
Copy link
Contributor

github-actions bot commented Oct 31, 2025

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

Copy link
Member

@MichaReiser MichaReiser left a comment

Choose a reason for hiding this comment

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

This is great. Thank you

@MichaReiser MichaReiser merged commit 521217b into astral-sh:main Oct 31, 2025
37 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

analyze Related to Ruff analyze functionality notebook Related to (Jupyter) notebooks

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ruff analyze graph seems to skip notebooks

3 participants