emmett-framework / granian

A Rust HTTP server for Python applications
BSD 3-Clause "New" or "Revised" License
2.89k stars 84 forks source link

feat: support passing watchfiles.BaseFilter instance #437

Open monosans opened 4 days ago

monosans commented 4 days ago

I think the user should be able to create their own reload filter and pass it this way. The current way of customizing reload filters is very limited, while this way removes all limitations.

import watchfiles
from granian import Granian

reload_filter_instance = watchfiles.PythonFilter(extra_extensions=(".html",))
# Let's call it reload_filter_instance to avoid making breaking changes
Granian(..., reload_filter_instance=reload_filter_instance).serve()

I am willing to submit a PR if you approve this change.

monosans commented 4 days ago

For CLI users, we can add the ability to pass the path to the instance by --reload-filter-instance some_package.some_module:my_reload_filter.