Make the configuration file optional#10877
Conversation
astrofrog
left a comment
There was a problem hiding this comment.
Just a quick comment below and also wanted to say that we should make sure we aren't breaking anything for downstream packages (the change in behaviour is fine, I mean no removal of functions etc that might break downstream)
astropy/config/configuration.py
Outdated
| ``pkg.version.cfg`` as a "template" for the user. | ||
| Create the default configuration file for the specified package. | ||
| If the file already exists, it is updated only if it has not been | ||
| modified. Otherwise the ``force`` flag is needed to overwrite it. |
There was a problem hiding this comment.
We could make it even simpler and just error if the file already exists unless force is given, without checking content? Would simplify the code further...
There was a problem hiding this comment.
In my experience though, if user really comes across this exception, we will have a feature request to ask for option to overwrite... 🤷
There was a problem hiding this comment.
Yes, I'm happy to simplify more.
There was a problem hiding this comment.
Thinking more about this, the problem is that the direct string comparison will fail if a configuration item has been added. So is_unedited_config_file is a nice a simple way to check if the config file has not been customized, whatever the version was used to generate it.
There was a problem hiding this comment.
I restored update_default_config since other packages use it, and it relies on is_unedited_config_file.
|
@saimn , since title says WIP, I converted this PR to draft. FYI. |
There was a problem hiding this comment.
I do like the amount of simplification this introduces, but given the behavior change, this should be in 4.3 or later, at least. I have set the milestone to 5.0 for now, but it is open for discussion.
User facing doc also needs to be written to fully explain what to expect with this change. Perhaps even a section for downstream package maintainers.
This patch should be tested with coordinated packages and a few affiliated ones (I would want to test mine at least) before being merged. The consequences of setting config alias, adding new config, removing old config, or changing existing config data type should also be considered.
astropy/config/configuration.py
Outdated
| ``pkg.version.cfg`` as a "template" for the user. | ||
| Create the default configuration file for the specified package. | ||
| If the file already exists, it is updated only if it has not been | ||
| modified. Otherwise the ``force`` flag is needed to overwrite it. |
There was a problem hiding this comment.
In my experience though, if user really comes across this exception, we will have a feature request to ask for option to overwrite... 🤷
|
Thanks @pllim, I could not find how to make it a draft PR... |
Yep, I realized after that astroquery may use |
Actually, a few of my own packages relies on it. For example,
Click the small arrow on the giant green button that says "create PR" and there will be a second option to create draft PR. 😉 |
df0bdc6 to
886c4ea
Compare
5.0 seems a bit far way, and I don't think this change would be a big disruption ;)
Sure!
Not sure what you mean with config alias and data type ? |
|
What about milestoning for 4.3 and then merging as soon as possible after the 4.2 branching which will give ample time for testing with downstream packages? |
|
Ref #10893 for a few fixes to get |
embray
left a comment
There was a problem hiding this comment.
👍 aside from this one question.
astropy/config/configuration.py
Outdated
| with open(cfgfn, 'rt', encoding='latin-1') as fd: | ||
| content = fd.read() | ||
|
|
||
| identical = (content == template_content) |
There was a problem hiding this comment.
Instead of comparing the config files byte-for-byte, why not just parse the existing config file and compare it to the default configuration?
This might require some refactoring of generate_config to have it generate the actual config data structure first, then a separate method for writing it to a file; probably how it should have been done in the first place.
Unless we really care about ensuring that it is byte-for-byte identical.
There was a problem hiding this comment.
Yes, that's the way it was done. But just after is_unedited_config_file loads the config file and checks if any keys are defined. So, since now this will not be run at import, maybe we can just keep the second check?
886c4ea to
ecacdf7
Compare
|
Oh, that's the master→default rename ... |

Ref discussion in #10738 and #10090 : stop writing/updating the configuration file by default when importing the package, and do nothing when reading if the file is absent.
I also replaced
update_default_configwith a new functioncreate_config_filewhich can be used to create or update the default file. And removed some old stuff for versions < 0.4. And removed the default config file which is present in the package since it can be generated, this will avoid having to update it in the release procedure.cc @astrofrog @pllim @embray
EDIT:
Fix #5899
Close #7290
Close #6511
Close #10090