Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue changing configuration at runtime #2993

Open
astrofrog opened this issue Apr 22, 2024 · 1 comment
Open

Issue changing configuration at runtime #2993

astrofrog opened this issue Apr 22, 2024 · 1 comment

Comments

@astrofrog
Copy link
Member

astrofrog commented Apr 22, 2024

The following should work to change e.g. the astrometry.net server:

from astroquery.astrometry_net import AstrometryNet, conf
conf.server = 'http://localhost:8080
ast = AstrometryNet(...)

but does not, because configuration settings are read at class definition time:

class AstrometryNetClass(BaseQuery):
    """
    Perform queries to the astrometry.net service to fit WCS to images
    or source lists.
    """
    URL = conf.server
    TIMEOUT = conf.timeout
    API_URL = url_helpers.join(URL, 'api')

I noticed this on astrometry.net because this is the one that I wanted it to work for, but I noticed this pattern in other classes too. We should instead be reading the configuration at runtime at the last minute when these values are needed.

However, before I open a PR to try and fix this, I wanted to check if there is a deliberate reason why the above was done?

@astrofrog astrofrog changed the title Changing configuration at runtime Issue changing configuration at runtime Apr 22, 2024
@keflavich
Copy link
Contributor

The pattern I've promoted is instead

from astroquery.astrometry_net import AstrometryNet, conf
ast = AstrometryNet(...)
ast.URL = 'http://localhost:8080'

so I designed modules to support that approach, expecting that configuration changes would be done via configuration files, not modified at runtime, while individual modules would have their URLs updated at runtime. This latter approach is useful if you want to use different URLs with different instances of the module, e.g.:

from astroquery.astrometry_net import AstrometryNet, conf
ast1 = AstrometryNet(...)
ast1.URL = host1
ast2 = AstrometryNet(...)
ast2.URL = host2

This latter use case would be more awkward using the conf-only approach.

However, I would be in favor of supporting both approaches.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants