granian icon indicating copy to clipboard operation
granian copied to clipboard

feat: support passing watchfiles.BaseFilter instance

Open monosans opened this issue 1 year ago • 2 comments

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 avatar Nov 21 '24 12:11 monosans

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.

monosans avatar Nov 21 '24 12:11 monosans

Sounds good to me in regards of the Python interface, but for the CLI maybe an alternative approach could be to add the --reload-only-* counterparts of the existing --reload-ignore-* params? At that point the usage would be smth like --reload-only-patterns *.py --reload-only-patterns *.html..

WDYT @monosans?

gi0baro avatar Nov 26 '24 21:11 gi0baro

Closing as stale

gi0baro avatar Jun 16 '25 14:06 gi0baro