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

Should this be called from a config file for easier testing? #74

Open
kjaymiller opened this issue Dec 20, 2022 · 3 comments
Open

Should this be called from a config file for easier testing? #74

kjaymiller opened this issue Dec 20, 2022 · 3 comments
Labels
enhancement New feature or request refactor site
Milestone

Comments

@kjaymiller
Copy link
Collaborator

    # TODO: Should this be called from a config file for easier testing?
    site_vars: dict = {
        "SITE_TITLE": "Untitled Site",
        "SITE_URL": "https://example.com", # TODO: #73 Make this http://localhost:8000
        }

https://github.com/kjaymiller/render_engine/blob/81971b54aca229bc1ee295909f2e874a40759e20/src/render_engine/site.py#L25-28

Currently the site_vars are hard-coded into the site.__init__() so if you pass in any site_vars, it overrides the default.

If these were separate, then you could partially update site_vars and then pass it into the site.__init__().

My suggestions is to store the vars in a config file, and then load them into the site.__init__() along with any manual site_vars (they could also load from config).

Currently thought is to use JSON as it most similar to dictionary which is what the site_vars are.

Future

  • Allow multiple config options including json, cfg, yaml, and pyproject.toml
@kjaymiller kjaymiller added the enhancement New feature or request label Dec 20, 2022
@kjaymiller
Copy link
Collaborator Author

  • Create file to look for: (Default: RENDER_ENGINE.json)
  • Values to look_for:
{
SITE_SETTINGS: {},
SITE_VARS: {},
PLUGINS: []
}
  • site to have logic for from_config

@kjaymiller
Copy link
Collaborator Author

Working example of how to implement this pattern is:

# from https://github.com/kjaymiller/kjaymiller.com/blob/main/routes.py#L18C1-L21C33

from render-engine import Site
import json

app = Site()
with open("settings.json") as json_file:
    settings = json.loads(json_file.read())
app.site_vars.update(**settings)

@kjaymiller
Copy link
Collaborator Author

This would be syntactic sugar that, if documented correctly would automatically be applied when an application is created.

@kjaymiller kjaymiller added this to the Backlog milestone Dec 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request refactor site
Projects
Status: No status
Development

No branches or pull requests

1 participant