Skip to content

Commit

Permalink
frontmatter(nbpath::String) performance fix (#3150)
Browse files Browse the repository at this point in the history
  • Loading branch information
fonsp authored Feb 25, 2025
1 parent f8724fc commit 7fbf5d6
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/notebook/frontmatter.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ end
function frontmatter(abs_path::String; raise::Bool=false)
try
# this will load the notebook to analyse, it won't run it
frontmatter(load_notebook_nobackup(abs_path); raise)
frontmatter(load_notebook_nobackup(abs_path; skip_nbpkg=true); raise)
catch e
if raise
rethrow(e)
Expand Down
8 changes: 4 additions & 4 deletions src/notebook/saving and loading.jl
Original file line number Diff line number Diff line change
Expand Up @@ -314,11 +314,11 @@ function _read_notebook_appeared_order!(cell_order::Vector{UUID}, collected_cell
end

"Load a notebook without saving it or creating a backup; returns a `Notebook`. REMEMBER TO CHANGE THE NOTEBOOK PATH after loading it to prevent it from autosaving and overwriting the original file."
function load_notebook_nobackup(@nospecialize(io::IO), @nospecialize(path::AbstractString))::Notebook
function load_notebook_nobackup(@nospecialize(io::IO), @nospecialize(path::AbstractString); skip_nbpkg::Bool=false)::Notebook
notebook_metadata = _read_notebook_metadata!(io)
collected_cells = _read_notebook_collected_cells!(io)
cell_order = _read_notebook_cell_order!(io, collected_cells)
nbpkg_ctx = _read_notebook_nbpkg_ctx(cell_order, collected_cells)
nbpkg_ctx = skip_nbpkg ? nothing : _read_notebook_nbpkg_ctx(cell_order, collected_cells)
appeared_order = _read_notebook_appeared_order!(cell_order, collected_cells)

appeared_cells_dict = filter(collected_cells) do (k, v)
Expand All @@ -340,9 +340,9 @@ end

# UTILS

function load_notebook_nobackup(path::String)::Notebook
function load_notebook_nobackup(path::String; kwargs...)::Notebook
open(path, "r") do io
load_notebook_nobackup(io, path)
load_notebook_nobackup(io, path; kwargs...)
end
end

Expand Down

0 comments on commit 7fbf5d6

Please # to comment.