[ANN] BaseDirs.jl (was XDG)

After much indecision regarding the package name, BaseDirs is finally registered! :partying_face:

See the Pre-ANN/RFC thread for a recap on what the package is, but the TLDR; is it provides a cross-platform way of finding the appropriate place to look for/put files, because .julia is not a panacea.

This is a very small and lightweight package (with zero dependencies), using Julia 1.9-rc1 it takes ~25ms to load on my machine.

If you work on a package that asks any questions like “where should I put some cache files?”, “where can I find system fonts?”, “what’s a good place to save a document?” or similar, I’d recommend giving this package a look.

For more info, see the (somewhat detailed) docs: https://tecosaur.github.io/BaseDirs.jl


To finish off, here’s some example usage of the package:

julia> using BaseDirs

julia> BaseDirs.CONFIG_HOME[]
"/home/tec/.config"

julia> BaseDirs.User.config()
"/home/tec/.config"

julia> BaseDirs.User.config("sub", "dir/")
"/home/tec/.config/sub/dir/"

julia> BaseDirs.User.config(BaseDirs.Project("mything"), "config.conf", create=true)
"/home/tec/.config/mything/config.conf"
10 Likes

See GitHub - JuliaPackaging/Scratch.jl: Scratch spaces for all your persistent mutable data needs that features automatic garbage collection and optional versioning.

2 Likes

From a glance, since Scratch.jl seems to want to make interacting with cache files easier, I’d suggest that Scratch.jl itself may want to consider using BaseDirs to put the cache files in the platform-appropriate location.

1 Like

Version 1.3 has just been released, and includes a few nice improvements:

  • The accessor functions BaseDirs.User.cache, BaseDirs.User.runtime and, BaseDirs.User.state have been copied into the top-level module since they don’t conflict with any system directories.
  • A BaseDirs.Project can now be constructed from a module, and modules can be passed as the first argument of an accessor function.
  • Together these first two changes let you simplify BaseDirs.User.cache(BaseDirs.Project("MyModule"), ...) to BaseDirs.cache(MyModule, ...)
  • Warnings when a BaseDirs result is illegally baked into precompilation are now raised
  • TTFX has been further improved, I’m now seeing 3.5ms on my machine
6 Likes