Skip to content

Make the configuration file optional#10877

Merged
pllim merged 17 commits intoastropy:mainfrom
saimn:config-optional
Apr 7, 2021
Merged

Make the configuration file optional#10877
pllim merged 17 commits intoastropy:mainfrom
saimn:config-optional

Conversation

@saimn
Copy link
Contributor

@saimn saimn commented Oct 16, 2020

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_config with a new function create_config_file which 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

@saimn saimn added the config label Oct 16, 2020
Copy link
Member

@astrofrog astrofrog left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

``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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my experience though, if user really comes across this exception, we will have a feature request to ask for option to overwrite... 🤷

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I'm happy to simplify more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I restored update_default_config since other packages use it, and it relies on is_unedited_config_file.

@pllim pllim added this to the v5.0 milestone Oct 16, 2020
@pllim pllim marked this pull request as draft October 16, 2020 15:04
@pllim
Copy link
Member

pllim commented Oct 16, 2020

@saimn , since title says WIP, I converted this PR to draft. FYI.

@pllim pllim requested review from embray and pllim October 16, 2020 15:05
Copy link
Member

@pllim pllim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

``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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my experience though, if user really comes across this exception, we will have a feature request to ask for option to overwrite... 🤷

@saimn
Copy link
Contributor Author

saimn commented Oct 16, 2020

Thanks @pllim, I could not find how to make it a draft PR...

@saimn
Copy link
Contributor Author

saimn commented Oct 16, 2020

@astrofrog - 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)

Yep, I realized after that astroquery may use update_default_config (and it does: https://github.com/astropy/astroquery/blob/master/astroquery/_astropy_init.py#L43). astroquery is probably the only package using the configuration system ?
So we could keep update_default_config longer, or make it do nothing (keeping it as an empty function would stop updating the config file as for astropy core) ?

@pllim
Copy link
Member

pllim commented Oct 16, 2020

astroquery is probably the only package using the configuration system

Actually, a few of my own packages relies on it. For example, synphot and stsynphot.

draft PR

Click the small arrow on the giant green button that says "create PR" and there will be a second option to create draft PR. 😉

@saimn
Copy link
Contributor Author

saimn commented Oct 17, 2020

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.

5.0 seems a bit far way, and I don't think this change would be a big disruption ;)

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.

Sure!

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.

Not sure what you mean with config alias and data type ?
I think the main thing to test is that the generate_config/create_config_file functions work well for other packages. I'm trying with astroquery, and there are some issues ;) (one of the subpackages is listed 3 times in the generated config file), so I will try to fix that.

@astrofrog
Copy link
Member

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?

@saimn
Copy link
Contributor Author

saimn commented Oct 18, 2020

Ref #10893 for a few fixes to get generate_config works correctly with astroquery.

Copy link
Member

@embray embray left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 aside from this one question.

with open(cfgfn, 'rt', encoding='latin-1') as fd:
content = fd.read()

identical = (content == template_content)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

@saimn saimn changed the title WIP: Make the configuration file optional Make the configuration file optional Feb 6, 2021
@saimn saimn marked this pull request as ready for review February 6, 2021 19:37
@saimn saimn modified the milestones: v5.0, v4.3 Feb 6, 2021
@saimn saimn requested review from astrofrog, embray and pllim February 6, 2021 19:38
@pllim pllim dismissed embray’s stale review April 7, 2021 19:06

Original review comments addressed

@saimn
Copy link
Contributor Author

saimn commented Apr 7, 2021

image
😲

@saimn
Copy link
Contributor Author

saimn commented Apr 7, 2021

Oh, that's the master→default rename ...

Copy link
Member

@pllim pllim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's do it! ✔️

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

Projects

None yet

5 participants