@@ -67,29 +67,44 @@ include("storage_drivers.jl")
6767# -------------------------------------------------------------------------------
6868# Global datasets configuration for current Julia session
6969
70- function expand_project_path (path)
70+ function data_project_from_path (path; depot_paths )
7171 if path == " @"
72- return path
72+ ActiveDataProject ()
7373 elseif path == " "
74- return joinpath (homedir (), " .julia" , " datasets" , " Data.toml" )
74+ # We will not throw an error here because this gets call in __init__, and we
75+ # do not want to interrupt the loading of the package. Instead, we omit this
76+ # project.
77+ if isempty (depot_paths)
78+ @warn " Julia depot data project (for an empty dataset path) can not be constructed because DEPOT_PATH is empty."
79+ return nothing
80+ end
81+ depot = first (depot_paths)
82+ # Julia is perfectly happy with DEPOT_PATHs that are not absolute, and hence their
83+ # interpretation changes when the user cd-s around in their session.
84+ #
85+ # https://github.com/JuliaLang/julia/issues/44958
86+ #
87+ # To offer a little bit more reliability here for the user, we absolutize the
88+ # path when DataSets gets loaded, so that things would not be affected by the
89+ # user changing directories.
90+ if ! isabspath (depot)
91+ depot = abspath (expanduser (depot))
92+ @warn " Julia depot path ($(first (depot_paths)) ) not absolute. Fixing data project path relative to current working directory." depot
93+ end
94+ TomlFileDataProject (joinpath (depot, " datasets" , " Data.toml" ))
7595 else
96+ # In other cases, we expect a reasonable absolute (or relative) path from
97+ # the user, which can either points directly to a file, unless it is an existing
98+ # directory.
7699 path = abspath (expanduser (path))
77100 if isdir (path)
78101 path = joinpath (path, " Data.toml" )
79102 end
80- end
81- path
82- end
83-
84- function data_project_from_path (path)
85- if path == " @"
86- ActiveDataProject ()
87- else
88- TomlFileDataProject (expand_project_path (path))
103+ TomlFileDataProject (path)
89104 end
90105end
91106
92- function create_project_stack (env)
107+ function create_project_stack (env, depot_paths )
93108 stack = []
94109 env_search_path = get (env, " JULIA_DATASETS_PATH" , nothing )
95110 if isnothing (env_search_path)
@@ -99,7 +114,8 @@ function create_project_stack(env)
99114 split (env_search_path, Sys. iswindows () ? ' ;' : ' :' )
100115 end
101116 for path in paths
102- project = data_project_from_path (path)
117+ project = data_project_from_path (path; depot_paths)
118+ isnothing (project) && continue
103119 push! (stack, project)
104120 end
105121 StackedDataProject (stack)
@@ -124,11 +140,13 @@ interpreted as follows:
124140 For directories, the filename "Data.toml" is implicitly appended.
125141 `expanduser()` is used to expand the user's home directory.
126142 - As in `DEPOT_PATH`, an *empty* path component means the user's default
127- Julia home directory, `joinpath(homedir(), ".julia", "datasets")`
143+ Julia depot (e.g. `~/.julia/datasets`), determined by the first element
144+ of `DEPOT_PATH`.
128145
129- This simplified version of the code loading rules (LOAD_PATH/ DEPOT_PATH) is
146+ This simplified version of the code loading rules (` LOAD_PATH`/` DEPOT_PATH`` ) is
130147used as it seems unlikely that we'll want data location to be version-
131- dependent in the same way that that code is.
148+ dependent in the same way that that code is. Note that any changes to `DEPOT_PATH`
149+ after `DataSets` has been loaded do not affect `DataSets.PROJECT`.
132150
133151Unlike `LOAD_PATH`, `JULIA_DATASETS_PATH` is represented inside the program as
134152a `StackedDataProject`, and users can add custom projects by defining their own
@@ -146,7 +164,7 @@ function __init__()
146164 # be unnecessary and can cause problems if those driver modules use
147165 # Requires-like code loading.
148166 if ! _isprecompiling ()
149- global PROJECT = create_project_stack (ENV )
167+ global PROJECT = create_project_stack (ENV , DEPOT_PATH )
150168 for proj in PROJECT. projects
151169 try
152170 add_storage_driver (proj)
0 commit comments