[red-knot] Add notebook support (#12338)

This commit is contained in:
Micha Reiser 2024-07-17 10:26:33 +02:00 committed by GitHub
parent fe04f2b09d
commit 0c72577b5d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
12 changed files with 246 additions and 53 deletions

View file

@ -3,6 +3,7 @@ use std::fmt::Debug;
pub use memory_fs::MemoryFileSystem;
#[cfg(feature = "os")]
pub use os::OsSystem;
use ruff_notebook::{Notebook, NotebookError};
pub use test::{DbWithTestSystem, TestSystem};
use walk_directory::WalkDirectoryBuilder;
@ -40,6 +41,13 @@ pub trait System: Debug {
/// Reads the content of the file at `path` into a [`String`].
fn read_to_string(&self, path: &SystemPath) -> Result<String>;
/// Reads the content of the file at `path` as a Notebook.
///
/// This method optimizes for the case where the system holds a structured representation of a [`Notebook`],
/// allowing to skip the notebook deserialization. Systems that don't use a structured
/// representation fall-back to deserializing the notebook from a string.
fn read_to_notebook(&self, path: &SystemPath) -> std::result::Result<Notebook, NotebookError>;
/// Returns `true` if `path` exists.
fn path_exists(&self, path: &SystemPath) -> bool {
self.path_metadata(path).is_ok()