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

Make @service only define a module once #690

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ararslan
Copy link
Member

@ararslan ararslan commented Jul 3, 2024

Currently, @service defines a module every time it's called. That works fine but the downside is that you get module redefinition warnings if you happen to call @service again. The most plausible reason why one would want to redefine the module would be to enable/disable particular features in some region of code. To facilitate that use case while avoiding redefinition warnings, we can make @service check for an existing module, define one if it can't find one, and if it can then modify the feature set associated with the module in place. With this change, @service S3 (e.g.) effectively expands to:

if isdefined(Main, :S3)
    AWS.set_features!(S3.SERVICE_FEATURE_SET)
else
    module S3
        # contents
    end
end

The set_features! call uses the features specified in the macro call as keyword arguments. No arguments uses defaults. Notably this design requires that FeatureSet be made mutable, which seems fine IMO.

Currently, `@service` defines a module every time it's called. That
works fine but the downside is that you get module redefinition warnings
if you happen to call `@service` again. The most plausible reason why
one would want to redefine the module would be to enable/disable
particular features in some region of code. To facilitate that use case
while avoiding redefinition warnings, we can `@service` check for an
existing module, define one if it can't find one, and if it can then
modify the feature set associated with the module in place. With this
change, `@service S3` (e.g.) effectively expands to:

```julia
if isdefined(Main, :S3)
    AWS.set_features!(S3.SERVICE_FEATURE_SET)
else
    module S3
        # contents
    end
end
```

The `set_features!` call uses the features specified in the macro call
as keyword arguments. No arguments uses defaults. Notably this design
requires that `FeatureSet` be made mutable, which seems fine IMO.
Copy link
Member

@quinnj quinnj left a comment

Choose a reason for hiding this comment

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

LGTM

@omus
Copy link
Member

omus commented Jul 4, 2024

Do you have a scenario in which you want to call @service multiple times for the same AWS service? Doing this within a package seems like an anti-pattern and I would be okay with only allowing a single call to @service S3 within a given module (the user must choose the feature flags they want and be consistent within that module).

The only reason I can think of to support multiple @service calls for the same AWS service would be on the REPL where you may want to experiment with different feature flags without restarting your Julia session.

@ararslan
Copy link
Member Author

ararslan commented Jul 8, 2024

Doing this within a package seems like an anti-pattern

I agree that the case this facilitates, dynamically changing the features in use for a given service, seems like an anti-pattern within a package. I'd be surprised if anybody would actually do that. The non-interactive use case I could imagine would be for folks who like to include all of their dependency loading at the top of each file in a package that utilizes those dependencies. (Not particularly common but I have seen it.)

The only reason I can think of to support multiple @service calls for the same AWS service would be on the REPL where you may want to experiment with different feature flags without restarting your Julia session.

I would consider this the primary use case.

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

Successfully merging this pull request may close these issues.

3 participants