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

Override scratch directory with preference or environmental variable #43

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
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"
kescobo marked this conversation as resolved.
Show resolved Hide resolved

[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"
kescobo marked this conversation as resolved.
Show resolved Hide resolved
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