Harmonise methods for distinguishing different Python source types (#13682)

This commit is contained in:
Alex Waygood
2024-10-09 14:18:52 +01:00
committed by GitHub
parent b9827a4122
commit 5b4afd30ca
9 changed files with 40 additions and 53 deletions

View File

@@ -20,7 +20,6 @@ ruff_python_ast = { workspace = true }
ruff_python_codegen = { workspace = true }
ruff_python_formatter = { workspace = true }
ruff_python_parser = { workspace = true }
ruff_python_stdlib = { workspace = true }
ruff_python_trivia = { workspace = true }
ruff_workspace = { workspace = true, features = ["schemars"] }

View File

@@ -6,8 +6,8 @@ use std::path::PathBuf;
use anyhow::Result;
use ruff_python_ast::PySourceType;
use ruff_python_codegen::round_trip;
use ruff_python_stdlib::path::is_jupyter_notebook;
#[derive(clap::Args)]
pub(crate) struct Args {
@@ -18,7 +18,7 @@ pub(crate) struct Args {
pub(crate) fn main(args: &Args) -> Result<()> {
let path = args.file.as_path();
if is_jupyter_notebook(path) {
if PySourceType::from(path).is_ipynb() {
println!("{}", ruff_notebook::round_trip(path)?);
} else {
let contents = fs::read_to_string(&args.file)?;