-
Notifications
You must be signed in to change notification settings - Fork 32
♻️ Refactor: migrate more aiohttp app keys to type-safe web.AppKey #8424
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
Merged
Merged
Changes from 25 commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
0b0a12c
final
pcrespov c5b1ba2
🎨 Refactor: Replace string-based app keys with type-safe `web.AppKey`…
pcrespov 7674e6b
web states
pcrespov 577436a
web states
pcrespov 2d6fef3
HEALTHCHECK_APPKEY
pcrespov 97120df
UNIT_REGISTRY_APPKEY
pcrespov 0e35a74
kesy
pcrespov 6f590b4
web appkeys
pcrespov 151472f
refactor: replace references to APP_SETTINGS_KEY from constants to ap…
pcrespov e1c9fc7
renaming
pcrespov 15c1442
fixes mypy and pylint
pcrespov 8f18e7f
refactor: update app key constants to use type-safe web.AppKey and re…
pcrespov 65ed11b
suffix APPKEY
pcrespov b072fcf
cleanup
pcrespov 9924fde
refactor: use Final for application keys to ensure immutability
pcrespov 0955166
refactor: rabbit appkeys
pcrespov db2553d
refactor: monitoservice
pcrespov 51768d1
refactor: monitoservice
pcrespov fa9a445
appsettings
pcrespov bffb9bb
new appkey
pcrespov 0d1c344
new appkey
pcrespov 502f6bc
fix: update LOGIN_SETTINGS_PER_PRODUCT_APPKEY to use web.AppKey
pcrespov 36c6e5c
rename with verb prefix
pcrespov 2db45bf
wallet subscriptions
pcrespov 5f55cbc
fixes tests
pcrespov 7676ad1
Merge branch 'master' into mai/more-app-keys
pcrespov 5de886d
fixes merge
pcrespov 2d612cb
minor
pcrespov File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| --- | ||
| mode: edit | ||
| description: Converts string-based aiohttp app key constants to type-safe web.AppKey | ||
| model: GPT-4.1 | ||
| --- | ||
|
|
||
| Convert all string-based app key constants to use type-safe web.AppKey. | ||
|
|
||
| - Replace patterns like: | ||
| ```python | ||
| CONSTNAME_APPKEY: Final[str] = f"{__name__}.my_key" | ||
| ``` | ||
| with: | ||
| ```python | ||
| from aiohttp import web | ||
| CONSTNAME_APPKEY: Final = web.AppKey("CONSTNAME", ValueType) | ||
| ``` | ||
| (Replace ValueType with the actual type stored under this key.) | ||
|
|
||
| - Update all usages: | ||
| - `app[CONSTNAME_APPKEY] = value` | ||
| - `data = app[CONSTNAME_APPKEY]` or `data = request.app[CONSTNAME_APPKEY]` | ||
|
|
||
| - Key constant MUST be UPPERCASE | ||
| - Key name MUST be suffixed `_APPKEY` | ||
| - Remove any f"{__name__}..." patterns; use a simple string identifier in web.AppKey. | ||
| - Ensure all keys are type-safe and self-documenting. | ||
| - IF you change the original name, you MUST change all the references |
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
services/web/server/src/simcore_service_webserver/activity/settings.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,11 @@ | ||
| from aiohttp import web | ||
| from settings_library.prometheus import PrometheusSettings | ||
|
|
||
| from ..constants import APP_SETTINGS_KEY | ||
| from ..application_keys import APP_SETTINGS_APPKEY | ||
|
|
||
|
|
||
| def get_plugin_settings(app: web.Application) -> PrometheusSettings: | ||
| settings: PrometheusSettings | None = app[APP_SETTINGS_KEY].WEBSERVER_ACTIVITY | ||
| settings: PrometheusSettings | None = app[APP_SETTINGS_APPKEY].WEBSERVER_ACTIVITY | ||
| assert settings, "setup_settings not called?" # nosec | ||
| assert isinstance(settings, PrometheusSettings) # nosec | ||
| return settings |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
services/web/server/src/simcore_service_webserver/application_keys.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| """web.AppKey definitions for simcore_service_webserver""" | ||
|
|
||
| from typing import TYPE_CHECKING, Final | ||
|
|
||
| from aiohttp import web | ||
| from servicelib.aiohttp.application_keys import ( | ||
| APP_AIOPG_ENGINE_KEY, | ||
| APP_CLIENT_SESSION_KEY, | ||
| APP_CONFIG_KEY, | ||
| APP_FIRE_AND_FORGET_TASKS_KEY, | ||
| ) | ||
|
|
||
| if TYPE_CHECKING: | ||
| # Application settings key - defined here to avoid circular imports | ||
| from .application_settings import ApplicationSettings | ||
|
|
||
| APP_SETTINGS_APPKEY: Final[web.AppKey[ApplicationSettings]] = web.AppKey( | ||
| "APP_SETTINGS", ApplicationSettings | ||
| ) | ||
| else: | ||
| APP_SETTINGS_APPKEY: Final[web.AppKey] = web.AppKey("APP_SETTINGS", None) | ||
|
|
||
|
|
||
| __all__: tuple[str, ...] = ( | ||
| "APP_AIOPG_ENGINE_KEY", | ||
| "APP_CLIENT_SESSION_KEY", | ||
| "APP_CONFIG_KEY", | ||
| "APP_FIRE_AND_FORGET_TASKS_KEY", | ||
| "APP_SETTINGS_APPKEY", | ||
| ) | ||
|
|
||
| # nopycln: file |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
services/web/server/src/simcore_service_webserver/catalog/_application_keys.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| from typing import Final | ||
|
|
||
| from aiohttp import web | ||
| from pint import UnitRegistry | ||
|
|
||
| UNIT_REGISTRY_APPKEY: Final = web.AppKey("UNIT_REGISTRY_APPKEY", UnitRegistry) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.