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

feat: better reload options #362

Merged
merged 12 commits into from
Aug 22, 2024
Merged

Conversation

iamkhav
Copy link
Contributor

@iamkhav iamkhav commented Jul 31, 2024

Hey all,
I based this PR off of @Andrew-Chen-Wang's work and included his original commit from #225.

Additionally to the rebase, I made a few changes to the descriptions (as required in the previous PR) and added the capability to pass a reload_filter from the Python API.

The reload_filter should be an obj based on watchfiles' BaseClass.

Closes #353 and #225.

granian/server.py Outdated Show resolved Hide resolved
@gi0baro gi0baro added this to the 1.6 milestone Aug 1, 2024
Copy link
Member

@gi0baro gi0baro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left some comments; vast majority of them are nits.

granian/server.py Outdated Show resolved Hide resolved
granian/cli.py Outdated Show resolved Hide resolved
granian/cli.py Outdated Show resolved Hide resolved
granian/cli.py Outdated Show resolved Hide resolved
granian/server.py Outdated Show resolved Hide resolved
granian/server.py Outdated Show resolved Hide resolved
@iamkhav
Copy link
Contributor Author

iamkhav commented Aug 2, 2024

Thank you very much for your review :)

I'll have to make another manual testing round later on, haven't spent a lot of time on that after the last two commits.

@gi0baro, should we speak about unit tests for some functionalities? I could cover reload options in an early iteration.
I sent you an email with contact info a few days ago.

@gi0baro
Copy link
Member

gi0baro commented Aug 5, 2024

I'll have to make another manual testing round later on, haven't spent a lot of time on that after the last two commits.

Gonna make another code review ASAP.

@gi0baro, should we speak about unit tests for some functionalities? I could cover reload options in an early iteration.

If you figure out a smart way to unit-test reload options, then yes please, go ahead. In general it's hard to unit-test Granian for everything which regards actual HTTP requests/application interaction (given also how the codebase is structured right now), maybe with some huge refactoring we can change this, but at the moment it feels too costly to be worth (especially considering there are 0 contributors on the Rust side at the moment except for myself). But again, given the context, I think it is a good candidate for unit.

I sent you an email with contact info a few days ago.

Yep, I see it. I just need to find some time to proper reply :)

Copy link
Member

@gi0baro gi0baro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left some suggestions/comments.
Also, probably changes to README.md need an update too.

granian/_imports.py Outdated Show resolved Hide resolved
granian/cli.py Outdated Show resolved Hide resolved
granian/cli.py Outdated Show resolved Hide resolved
granian/server.py Outdated Show resolved Hide resolved
@iamkhav
Copy link
Contributor Author

iamkhav commented Aug 15, 2024

I'm sorry for the delay on this PR @gi0baro!

Meanwhile, I was thinking a bit about tests.

  1. Launch Granian instance with certain reload params
  2. Confirm default behaviour for a route (optional)
  3. Replace a source file to make that route respond with a specific body
  4. Send a request to Granian instance and check if app successfully reloaded by asserting the specific modified body

E.g. 2. could be an assert for the response body not to be the later modified one.

I think we could pull that off with minimal changes to tests/apps.
Happy to attempt this either here or in a subsequent PR (but probably before 1.6).

WDYT?

@gi0baro
Copy link
Member

gi0baro commented Aug 16, 2024

I'm sorry for the delay on this PR @gi0baro!

np at all, there's no need to rush here :)

Meanwhile, I was thinking a bit about tests.

  1. Launch Granian instance with certain reload params
  2. Confirm default behaviour for a route (optional)
  3. Replace a source file to make that route respond with a specific body
  4. Send a request to Granian instance and check if app successfully reloaded by asserting the specific modified body

E.g. 2. could be an assert for the response body not to be the later modified one.

This sounds more like testing watchfiles itself rather than Granian to me.
I would probably approach this with a different strategy, unit-testing specifically:

  • the final merged params are indeed what we expect in Granian instance
  • the change trigger works
    I think we can implement those tests without the need of making a request/response flow, as refactoring Granian class to mock the startup and the reload trigger should be relatively easy.

Happy to attempt this either here or in a subsequent PR (but probably before 1.6).

I'm definitely more up to a separate PR for tests, planning to review and merge this one in the near future.
I don't have any specific ETA for 1.6, so feel free to take your time; we can discuss the single PRs individually for 1.6 inclusion :)

@gi0baro gi0baro merged commit ecde815 into emmett-framework:master Aug 22, 2024
19 checks passed
),
multiple=True,
)
@option(
'--reload-ignore-patterns',
help=(
'Entity patterns (regex) to ignore changes for. '
'Extends the default list of patterns to ignore in watchfiles.filters.DefaultFilter.'
'Path patterns (regex) to ignore changes for. '
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Quick note because I stumbled over this while testing the feature.

I had also assumed that this will regex match on the full path of something that triggered the reload. However, this only matches the last part of the path, meaning the exact file/dir that triggered the reload, not the entire path.

https://watchfiles.helpmanual.io/api/filters/#watchfiles.DefaultFilter.ignore_entity_patterns

"Entity" isn't a much better description 😛 but "Path" might be suggesting a different behaviour altogether. WDYT?

I want to avoid issues where users report this to be broken.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I missed that. Would Relative path patterns make sense to you?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the late answer.

I think being fully explicit could help.

Suggested change
'Path patterns (regex) to ignore changes for. '
'File/directory name patterns (regex) to ignore changes for. '

WDYT?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks perfect. Can you open a PR for this? otherwise I'll do it by myself later

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No worries, will do!

@iamkhav iamkhav deleted the reload-options branch August 28, 2024 14:49
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 this pull request may close these issues.

Add Granian extended reloading options
3 participants