Repository navigation
What to do when ~/.astropy is not writeable - #123
Conversation
|
~/.astropy needs to be created upon first import... it should not be part of setup.py at all. Think of the use case of installing in a central location on a multi-user machine. It should resolve this situation, too, unless i'm missing something. |
|
The trouble is deciding when "first import" is - after all, there's an My idea was that for multi-user machines, it will just always look for whatever the correct home is for the current user who's actually running that python process... as it stands right now, any So this could be changed to check for if it's in setup, and if so, not do any of the creating. I think that will break some of the tests, though... Alternatively, we could just have it fail gracefully if it can't access the .astropy directory, and just assume all defaults for the configuration and only fail if someone tries to use the cache stuff (which of course requires a writeable directory). |
|
I think that whatever we do, if |
|
Yep, that definitely makes sense for config files... But what about accessing the cache? One thing that could be done might be to use the |
|
@eteq: Maybe we could have an atexit handler that removes the temporary cache directory if one was created. |
|
@eteq: I think what you propose 3 comments up here seems reasonable. |
|
Why are the tests relying on ~/.astropy in the first place? I would say that |
|
The tests rely on |
|
I still think that in any case, related to the original ticket, astropy should never fail to import if |
|
Agreed - and the code I just attached does exactly that - if |
|
I guess what I'm trying to say is that if ~/.astropy cannot be written/read, it is not crucial to astropy and should not raise an exception. In that case, the default config would be used, and no caching would take place. |
|
@eteq - ok, that sounds sensible. I sent my last comment before seeing yours. |
|
Ok, sounds good - I'll give it a few days for review, and assuming there aren't any big problems I'll merge and close the issue. |
|
When the tests do use |
|
I understand the argument that it is hard to test the configuration system itself without actually accessing the configuration files. However, I think, as @iguananaut suggested, we shouldn't touch those files during setup. I wouldn't expect There is the other issue that we don't want user's settings to impact the tests themselves. We had this issue in matplotlib. Imagine a setting that turns warnings into errors for example (one such setting already exists in As for testing configuration itself, it should be possible to set |
There was a problem hiding this comment.
We could add a sys.atexit handler here so the file is automatically cleared when the interpreter is done.
There was a problem hiding this comment.
In the commit I added, I've added this, controlled by a configuration item (defaulting to delete) - I imagine there are some cases where a user might want to keep the file after it's downloaded. It's maybe a bit silly given that the configuration file itself is probably inacessible in these cases, but ConfigurationItem.set will still work if someone really wants it.
|
I agree with @mdboom's suggestion of setting $HOME to a tmp directory for the tests. There could (and should) still be a test or tests for the function that finds the user's $HOME (the result of such a test would depend entirely on which platform it's run on, but that's fine too). |
|
@iguananaut and @mdboom - I see your point here - and pytest makes this pretty easy, actually, with the Also, perhaps one of you should create this as a separate issue/pull request (or I can - I just want to make sure you aren't attached to it being in this particular PR)? I think we want this pull request regardless, and while related, I think having an inaccessible .astropy fall back to defaults and having the tests run separately are slightly different issues. |
|
@astrofrog - can you confirm that with the changes in this PR, the original issue is actually fixed? |
|
It seems to work fine, and I'm getting two test failures: http://paste.pocoo.org/show/539457 The first one is expected, but is the second one normal? |
|
The second one is happening because if it can't access the astropy directory, it leaves the So what do you think is the best way to deal with this? I could just add extra clauses to ignore OSErrors that include "permission denied" for the first one, and the second I could just check for None and have it do nothing if its None. But that could potentially mask future bugs, I suppose. Or I could just merge this as-is, as the suggestions of @mdboom and @iguananaut would make this problem irrelevant for you once we implemented that (a temporary directory for the config files, that is). |
|
Ok, I agree that the second failed test is not a big issue, so as far as I'm concerned, this is fine to merge for now. |
config and data fallback to defaults when $HOME/.astropy is not writeable
config and data fallback to defaults when $HOME/.astropy is not writeable
…3_inv Adding builtins.object to local python3 inventory to fix broken links ...
Generalize coordinate formatting
Mark galpy as accepted
While trying to run the astropy build on a mac with Jenkins to automate testing with different Python versions, I ran into an issue. The tests are run using the anonymous user, and when Jenkins tries to build astropy, it needs to be able to create the .astropy directory in the home directory. However, in this case, it tries to access
/var/root, which is of course not writeable:Of course, I can fix this by doing:
but this got me thinking that maybe at least (but not necessarily all) of the following should probably happen:
~/.astropyshould be created oninstall, notbuild(in my view,buildshould only affect the local directory, whileinstallcan place files outside the tree)~/.astropyon build for this kind of situation~/.astropycannot be created, a warning should be raised, but this should not be fatal@eteq, @mdboom, and @iguananaut - since you've been involved in the
~/.astropystuff I was wondering whether you have any thoughts regarding how this should behave?