Skip to content
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

Safe figure saving by default, + new arg #4965

Open
wants to merge 3 commits into
base: v2
Choose a base branch
from

Conversation

isentropic
Copy link
Member

Like I suggested before in #3001

@isentropic
Copy link
Member Author

julia> p = plot(rand(10), safe_saving=true);

julia> savefig(p, "this.png")
"/Users/z/Projects/Plots.jl/this.png"

julia> savefig(p, "this.png")
┌ Warning: Filename /Users/z/Projects/Plots.jl/this.png already exists, defaulting to prevent overriding. To disable this behavior, provide `:safe_saving=false` kwarg, i.e. `plot(rand(10), safe_saving=false)`
└ @ PlotsBase ~/Projects/Plots.jl/PlotsBase/src/output.jl:142

julia> p = plot(rand(10), safe_saving=false);

julia> savefig(p, "this.png")
"/Users/z/Projects/Plots.jl/this.png"

@isentropic
Copy link
Member Author

isentropic commented Jul 18, 2024

I'll fix the tests, once we agree if it goes into 2.0 or not. I was also thinking instead of making this a property of a plot, maybe just make it a flag in savefig feature, but then maybe someone would want this unsafe behavior by default. Making it part of plot struct will enable such defaulting

@BeastyBlacksmith
Copy link
Member

I'll fix the tests, once we agree if it goes into 2.0 or not. I was also thinking instead of making this a property of a plot, maybe just make it a flag in savefig feature, but then maybe someone would want this unsafe behavior by default.

I would be in favor of making it a part of savefig, same goes for tex_output_standalone. If changing the default is the main concern we could make it a ScopedValue

@BeastyBlacksmith BeastyBlacksmith added this to the v2.0 milestone Jul 18, 2024
@isentropic
Copy link
Member Author

I can't understand how scopedvalues can help here. Can you give an example please?

@BeastyBlacksmith
Copy link
Member

julia> using ScopedValues

julia> const DEFAULT_OVERWRITE = ScopedValue(false)
ScopedValue{Bool}(0)

julia> savefig(;overwrite = DEFAULT_OVERWRITE) = @show overwrite[]
savefig (generic function with 1 method)

julia> savefig()
overwrite[] = false
false

julia> with(DEFAULT_OVERWRITE => true) do
         savefig()
       end
overwrite[] = true
true

@isentropic
Copy link
Member Author

isentropic commented Jul 22, 2024

I see, I meant about script usage. Probably some people have their research pipelines such that there is some saving done inside. Like having users modify so much code to accomodate such a change might be too drastic

I was thinking that a user would set the flag in Prefernces.jl or startup.jl

Now that I'm looking into these, where are the docs about setting the defaults? I can't seem to find the docs about default setting anymore

@BeastyBlacksmith
Copy link
Member

I think its the tip on the bottom of this page: https://docs.juliaplots.org/stable/install/

@isentropic
Copy link
Member Author

So you still think ScopedValue is the right solution here?

@BeastyBlacksmith
Copy link
Member

I do. I mean, you can still do something like

const DEFAULT_OVERWRITE = ScopedValue(get(PLOTS_DEFAULTS, :overwrite, false))

To get change it based on some value in startup.jl.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants