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

Auto reload resource files in the a Sanic app #2143

Closed
erickguan opened this issue May 28, 2021 · 3 comments · Fixed by #2167
Closed

Auto reload resource files in the a Sanic app #2143

erickguan opened this issue May 28, 2021 · 3 comments · Fixed by #2167
Assignees

Comments

@erickguan
Copy link

Is your feature request related to a problem? Please describe.
When a Sanic app is in production, I use different configs for development, staging, and production. I use 3 YAML files to implement that. However, they are not tracked by auto_reload in the development environment. I would be happy to be able to see Sanic can restart when I change the config.

Describe the solution you'd like
It can be a helper API to register resources for auto_reload. importlib provides a semantic method importlib.resources.read_text. It does no more than read(, 'r'). It might be nice to hook with readers from importlib.

Additional context
Example app structure:

awesomeapp
| - config
   | - development.yaml
   | - staging.yaml
   | - production.yaml
| app.py
| __init__.py

Potential API signature:
sanic.resources.read_text(package, resource, encoding='utf-8', errors='strict')

@ahopkins ahopkins self-assigned this Jun 16, 2021
@ahopkins
Copy link
Member

ahopkins commented Jun 16, 2021

Can you explain to me the thought process on the read_text?

It seems like what you are really looking for is a way to tell sanic to reload for anything in ./config.

Something like this?

app.run(auto_reload=True, include_dir="./config")

@erickguan
Copy link
Author

You are right about this. Your solution is much simpler!

@ahopkins
Copy link
Member

@erickguan I am really glad that you suggested this. It is something that I think I have thought in my head many times would be really helpful to have.

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 a pull request may close this issue.

2 participants