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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleaner way to register an extra #63

Closed
arnaudmiribel opened this issue Nov 9, 2022 · 3 comments
Closed

Cleaner way to register an extra #63

arnaudmiribel opened this issue Nov 9, 2022 · 3 comments
Labels
enhancement New feature or request

Comments

@arnaudmiribel
Copy link
Owner

arnaudmiribel commented Nov 9, 2022

Replace this

__func__ = get_streamlit_faker
__title__ = "Streamlit Faker"
__desc__ = "Fake Streamlit commands at the speed of light! Great for prototyping apps."
__icon__ = "馃シ"
__examples__ = [example]
__author__ = "Arnaud Miribel"
__github_repo__ = "arnaudmiribel/streamlit-faker"
__pypi_name__ = "streamlit-faker"
__package_name__ = "streamlit_faker"
__experimental_playground__ = False

With

from common import set_extra_gallery_config

extra_gallery_config: dict = set_extra_gallery_config(
  func=get_streamlit_faker,
  title="Streamlit Faker",
  desc="Fake Streamlit commands at the speed of light! Great for prototyping apps.",
  ...
)

And consume that extra_gallery_config variable in gallery/streamlit_app.py.

Main perks:

  • canonical definition of all potential config keys in set_extra_gallery_config
  • auto-complete unlocked for all extra configs config
  • makes it clear that this part in the init.py is for the gallery and has no impact whatsoever in the inner workings of the extra.
@arnaudmiribel arnaudmiribel added the enhancement New feature or request label Nov 9, 2022
@arnaudmiribel
Copy link
Owner Author

WDYT @blackary?

@blackary
Copy link
Collaborator

blackary commented Nov 9, 2022

@arnaudmiribel To be honest, I like the dunder attributes better because it doesn't actually run anything when you import an extra.

What if you slightly modified this, and make a standardized required method called _get_extra_config() or something like that, which then calls (and returns the output of) set_extra_gallery_config inside of it? Then the gallery app would go through, make sure that _get_extra_config() is defined, and call it. I'm not 100% sure I'm sold on that, but I just would like us to stick to "imports don't have side-effects" as much as possible. WDYT?

@arnaudmiribel
Copy link
Owner Author

Won't do more than the decorator for now

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

No branches or pull requests

2 participants