Works like :meth:`record` but wraps the function in another function that will ensure the function is only called once. If the blueprint is registered a second time on the application, the function passed is not called.
(self, func: DeferredSetupFunction)
| 231 | |
| 232 | @setupmethod |
| 233 | def record_once(self, func: DeferredSetupFunction) -> None: |
| 234 | """Works like :meth:`record` but wraps the function in another |
| 235 | function that will ensure the function is only called once. If the |
| 236 | blueprint is registered a second time on the application, the |
| 237 | function passed is not called. |
| 238 | """ |
| 239 | |
| 240 | def wrapper(state: BlueprintSetupState) -> None: |
| 241 | if state.first_registration: |
| 242 | func(state) |
| 243 | |
| 244 | self.record(update_wrapper(wrapper, func)) |
| 245 | |
| 246 | def make_setup_state( |
| 247 | self, app: App, options: dict[str, t.Any], first_registration: bool = False |
no test coverage detected