Skip to content

BUG: config and cache dir configured via env variables are not (always) automatically created #18791

Closed

Description

@neutrinoceros

This came up in #17934, specifically #17934 (comment)

The problem is that, if one defines e.g. XDG_CACHE_HOME to an existing dir that's also writable, but missing an astropy subdirectory, the env variable is currently silently ignored.
The user experience is already being improved in #17934, which adds a clear warning that the env var is ignored, and explains why.
However, we could actually try to create the missing subdirectory first, and only fallback to ignoring the env var if that doesn't work.
This issue is a reminder to implement this behavior as early as possible during the next cycle (presumably 8.0), as a follow up to #17934.

Activity

  1. pllim commented on Oct 28, 2025

    @pllim
    Member

    Here is the behavior on main at the time of writing.

    Starting condition: XDG_CACHE_HOME is defined and the directory exists but $XDG_CACHE_HOME/astropy does not exist.

    If ~/.astropy/cache does NOT exist

    Calling astropy.config.paths.get_cache_dir() would create ~/.astropy/cache and also create $XDG_CACHE_HOME/astropy. The latter is a symlink to the former. The function would only return the former.

    If ~/.astropy/cache already exists

    Calling astropy.config.paths.get_cache_dir() would simply return ~/.astropy/cache without worrying about XDG_CACHE_HOME at all, so $XDG_CACHE_HOME/astropy is not created.

    I think this issue is about the second "if" here.

    So the question is: Would anyone actually want $XDG_CACHE_HOME/astropy if ~/.astropy/cache already exist? This question is separate from #17507 .

    I also think this behavior, while confusing, is still consistent the following docs (as per v7.2)?

  2. neutrinoceros commented on Oct 28, 2025

    @neutrinoceros
    ContributorAuthor

    Thanks, I always forget that the existence of $HOME/.astropy also plays a role here...

    Would anyone actually want $XDG_CACHE_HOME/astropy if ~/.astropy/cache already exist?

    I think that'd be the least surprising possible behavior for anyone setting XDG_CACHE_HOME, yes. Env variables usually take precedence over any other global state. I'm saying "usually", but what I really mean is "in all cases I know of, other than this one weird behavior in astropy's config system".

  3. pllim commented on Oct 28, 2025

    @pllim
    Member

    I think for this particular issue, maybe it would be uncontroversial to create that symlink even if ~/.astropy/cache already exists for v8.0

  4. neutrinoceros commented on Oct 28, 2025

    @neutrinoceros
    ContributorAuthor

    maybe it would be uncontroversial to create that symlink

    at the risk of starting a war, I actually don't think we should ever be creating symlinks 😬

  5. pllim commented on Oct 28, 2025

    @pllim
    Member

    I am sure there was a reason (perhaps to prevent accidental multiple or conflicting copies?) but I wasn't part of the project when this module was designed.

  6. changed the title [-]BUG: config and cache dir configured via env variables are not automatically created[/-] [+]BUG: config and cache dir configured via env variables are not (always) automatically created[/+] on Oct 29, 2025
  7. andresgur commented on Jan 27, 2026

    @andresgur

    if I my join this fun party all I can say is that I've wasted like 3h of my life trying to set up a new cache/config directory and not only I failed to do it, I also failed to understand how any of it works

    It's also very confusing that
    a) https://docs.astropy.org/en/stable/environment_variables.html#environment-variables
    Says to create a folder $XDG_CONFIG_HOME/astropy for config, when it would make more sense to have astropy/config (as per the DEFAULT structure $HOME/.astropy/config). Initially I expected $XDG_CONFIG_HOME to be the config directory itself.
    b) astropy.config.paths.get_cache_dir_path("astropy") this little bitch doesn't look for "astropy" it looks for ".astropy", which is not what the docs above say (meaning if you set something/astropy (without .) it won't work and good look figuring it out without any warnings)

    At least that's what I grasped...

  8. pllim commented on Jan 27, 2026

    @pllim
    Member

    @andresgur we apologize for your frustration but please watch your language.

    @neutrinoceros didn't we merge a PR that you wrote a while back to address this?

  9. andresgur commented on Jan 27, 2026

    @andresgur

    apologies @pllim it was a long and frustrating day, and I just need it to vent. I very much appreciate your work and I understand it is by no means an easy issue you are trying to solve

    PD: this was in astropy 7.2.0

  10. neutrinoceros commented on Jan 28, 2026

    @neutrinoceros
    ContributorAuthor

    very sorry to hear that @andresgur
    Let me give you a bit of additional context and maybe some hope for the near future:
    we spent a lot of time digging into the legacy behavior of this system as we worked on astropy 7.2.0, and as the person who championed this effort, I must say I 100% agree with you: it is extremely confusing and in need for an overhaul. Because we didn't want to immediately break anything (or anyone) that was relying on this very old system (even unknowingly, or by accident), we agreed to first introduce (what ended up being a lot of) warnings for as many of these fragile cases as we could. The result is that astropy 7.2.0 is both very noisy and annoying to work with (aka worst of both worlds). But that's only our first step towards salvation: we are actively planning to overhaul this system for a much much simpler one in astropy 8.0.0. I also got fundings to work specifically on this, so there's real guarantees that it will happen. See #18964

  11. andresgur commented on Jan 28, 2026

    @andresgur

    great to hear that @neutrinoceros , keep up the good work 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions