Knowing where to find/place files can be hard. So far in the Julia ecosystem I’ve seen two approaches:
- Try a basic (sometimes incorrect) approach, as has been done in FreeTypeAbstraction.jl and DataDeps.jl.
- Just shove any/every-thing under the Julia depot path, leading to a cluttering of
.julia. From the packages I have installed, I see:
symbolstorev2-lsp-juliamixing state, cache, user data, and other categories of information.
Neither of these approaches correctly determine appropriate locations for data. This has niggled me for a while, and so I’ve finally got around to producing:
XDG.jl A cross platform implementation of the XDG Directory Spec
It is essentially an implementation of the XDG (Cross-Desktop Group) directory specifications, with analogues for Windows and MacOS for cross-platform support. More specifically, this is a hybrid of:
- The XDG base directory and the XDG user directory specifications on Linux
- The Known Folder API on Windows
- The Standard Directories guidelines on macOS
This has taken longer that I expected to develop, because I did an investigation of other translations of the XDG spec to Windows/Mac (looking at Qt, Go, Rust, and Python libraries). You can find my collated results and conclusions here, and the approach I’m taking here.
Why does this matter
It may be easy to treat file paths haphazardly, but for the user in particular
abiding by the standards/conventions of the their platform has a number of major
benefits, such as:
- Improved ease of backups, since it is easier to make rules for which folders need to be backed up.
- Improved configuration portability, since it is easier to identify and share the relevant configuration files.
- Ease of isolating application state, by containing state to a single directory it is easy to avoid sharing it.
- Decreased reliance on hard-coded paths, improving flexibility and composability.
It is worth noting that these considerations apply to both graphical and
command-line desktop applications.
Choosing the correct location
Along with this package, I’ve also produced an initial attempt of a flowchart to work out the appropriate directory (first pass, will likely be edited for clarity in the future).
(@v1.8) pkg> add https://github.com/tecosaur/XDG.jl.git julia> using XDG julia> XDG.CONFIG_HOME "/home/tec/.config" julia> XDG.User.config() "/home/tec/.config" julia> XDG.User.config("sub", "dir/") "/home/tec/.config/sub/dir/" julia> XDG.User.config(XDG.Project("mything"), "config.conf", create=true) "/home/tec/.config/mything/config.conf"
Feedback would be appreciated
Ideally, this would be taken up by the various Julia packages that need to think about where to look for/put files, to help them do so more idiomatically. In order for this to have the best chance of doing so, this package needs to be:
- As easy to use as reasonably possible
- As idiomatic (on Windows/Mac) as reasonably possible
With this in mind, I’d be very appreciative of feedback on both the overall design choices and details of this package.