Skip to content
Draft
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ version = "1.2.0"

[deps]
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
Preferences = "21216c6a-2e73-6563-6e65-726566657250"

[compat]
julia = "1"
Expand Down
17 changes: 16 additions & 1 deletion src/Scratch.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ module Scratch
import Base: UUID
using Dates

@static if VERSION >= v"1.6"
using Preferences
end

export with_scratch_directory, scratch_dir, get_scratch!, delete_scratch!, clear_scratchspaces!, @get_scratch!

const SCRATCH_DIR_OVERRIDE = Ref{Union{String,Nothing}}(nothing)
Expand Down Expand Up @@ -30,7 +34,18 @@ be overridden via `with_scratch_directory()`.
"""
function scratch_dir(args...)
if SCRATCH_DIR_OVERRIDE[] === nothing
return abspath(first(Base.DEPOT_PATH), "scratchspaces", args...)
@static if VERSION >= v"1.6"
scratch_base_path = @load_preference("scratch_dir",
get(ENV, "JULIA_SCRATCH_DIR",
joinpath(first(Base.DEPOT_PATH), "scratchspaces")
)
)
else
scratch_base_path = get(ENV, "JULIA_SCRATCH_DIR",
joinpath(first(Base.DEPOT_PATH), "scratchspaces")
)
end
return abspath(scratch_base_path, args...)
else
# If we've been given an override, use _only_ that directory.
return abspath(SCRATCH_DIR_OVERRIDE[], args...)
Expand Down