pz-cli 5.0.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pz_cli-5.0.0.dist-info/METADATA +51 -0
- pz_cli-5.0.0.dist-info/RECORD +399 -0
- pz_cli-5.0.0.dist-info/WHEEL +4 -0
- pz_cli-5.0.0.dist-info/entry_points.txt +5 -0
- pz_core/__init__.py +64 -0
- pz_core/__main__.py +7 -0
- pz_core/app.py +45 -0
- pz_core/assembly/__init__.py +17 -0
- pz_core/assembly/app_discovery.py +1240 -0
- pz_core/assembly/apps/__init__.py +25 -0
- pz_core/assembly/apps/compiler.py +824 -0
- pz_core/assembly/apps/providers.py +188 -0
- pz_core/assembly/cli/__init__.py +9 -0
- pz_core/assembly/cli/compiler.py +166 -0
- pz_core/assembly/diagnostics/__init__.py +21 -0
- pz_core/assembly/diagnostics/checks.py +257 -0
- pz_core/assembly/diagnostics/dev_sources.py +569 -0
- pz_core/assembly/events/__init__.py +5 -0
- pz_core/assembly/events/compiler.py +219 -0
- pz_core/assembly/extensions/__init__.py +5 -0
- pz_core/assembly/extensions/compiler.py +696 -0
- pz_core/assembly/infra/__init__.py +6 -0
- pz_core/assembly/infra/compiler.py +272 -0
- pz_core/assembly/lifecycle/__init__.py +5 -0
- pz_core/assembly/lifecycle/compiler.py +95 -0
- pz_core/assembly/middlewares/__init__.py +19 -0
- pz_core/assembly/middlewares/compiler.py +508 -0
- pz_core/assembly/project/__init__.py +7 -0
- pz_core/assembly/project/compiler.py +9 -0
- pz_core/assembly/project/context.py +17 -0
- pz_core/assembly/project/discovery.py +227 -0
- pz_core/assembly/resources/__init__.py +19 -0
- pz_core/assembly/resources/compiler.py +310 -0
- pz_core/assembly/resources/settings.py +129 -0
- pz_core/assembly/routes/__init__.py +7 -0
- pz_core/assembly/routes/compiler.py +400 -0
- pz_core/assembly/runtime_manifests/__init__.py +13 -0
- pz_core/assembly/runtime_manifests/compiler.py +159 -0
- pz_core/assembly/settings/__init__.py +17 -0
- pz_core/assembly/settings/compiler.py +786 -0
- pz_core/assembly/settings/host_project_overrides.py +82 -0
- pz_core/assembly/settings/host_runtime_endpoint.py +207 -0
- pz_core/authoring/__init__.py +79 -0
- pz_core/authoring/app_init_service.py +946 -0
- pz_core/authoring/app_versions.py +814 -0
- pz_core/authoring/cli.py +192 -0
- pz_core/authoring/commands.py +1810 -0
- pz_core/authoring/conflicts.py +180 -0
- pz_core/authoring/dev_bindings.py +916 -0
- pz_core/authoring/dev_git.py +1087 -0
- pz_core/authoring/dev_import.py +1061 -0
- pz_core/authoring/dev_manifest.py +522 -0
- pz_core/authoring/dev_sources.py +1638 -0
- pz_core/authoring/env_cli.py +454 -0
- pz_core/authoring/files.py +109 -0
- pz_core/authoring/ide_projection.py +1129 -0
- pz_core/authoring/naming.py +58 -0
- pz_core/authoring/official_dev_sources.py +432 -0
- pz_core/authoring/official_sources.json +156 -0
- pz_core/authoring/orchestration_service.py +558 -0
- pz_core/authoring/project_default.jsonc +53 -0
- pz_core/authoring/project_defaults.py +88 -0
- pz_core/authoring/project_metadata_service.py +199 -0
- pz_core/authoring/project_settings_checks.py +51 -0
- pz_core/authoring/project_settings_cli.py +299 -0
- pz_core/authoring/project_settings_service.py +1700 -0
- pz_core/authoring/project_state.py +399 -0
- pz_core/authoring/publish_git.py +423 -0
- pz_core/authoring/publish_lock.py +188 -0
- pz_core/authoring/publish_source.py +195 -0
- pz_core/authoring/release.py +1382 -0
- pz_core/authoring/repo_keys.py +29 -0
- pz_core/authoring/root_cli.py +28 -0
- pz_core/authoring/scaffold_service.py +325 -0
- pz_core/authoring/sync_service.py +787 -0
- pz_core/authoring/templates/app/__init__.py +1 -0
- pz_core/authoring/templates/app/api.py +25 -0
- pz_core/authoring/templates/app/apps.py +31 -0
- pz_core/authoring/templates/app/auth_package_init.py +14 -0
- pz_core/authoring/templates/app/auth_readme.py +29 -0
- pz_core/authoring/templates/app/configs_package_init.py +14 -0
- pz_core/authoring/templates/app/default_env.py +18 -0
- pz_core/authoring/templates/app/default_jsonc.py +25 -0
- pz_core/authoring/templates/app/locales_readme.py +25 -0
- pz_core/authoring/templates/app/migrations_readme.py +19 -0
- pz_core/authoring/templates/app/models.py +14 -0
- pz_core/authoring/templates/app/package_init.py +8 -0
- pz_core/authoring/templates/app/pages_base.py +161 -0
- pz_core/authoring/templates/app/pages_readme.py +25 -0
- pz_core/authoring/templates/app/public.py +31 -0
- pz_core/authoring/templates/app/pyproject.py +77 -0
- pz_core/authoring/templates/app/readme.py +74 -0
- pz_core/authoring/templates/app/settings.py +46 -0
- pz_core/authoring/templates/app/static_app_js.py +24 -0
- pz_core/authoring/templates/app/static_readme.py +31 -0
- pz_core/authoring/templates/app/template_config_page.py +23 -0
- pz_core/authoring/templates/app/template_index_html.py +28 -0
- pz_core/authoring/templates/app/templates_readme.py +32 -0
- pz_core/authoring/templates/app/urls.py +36 -0
- pz_core/authoring/templates/app/views.py +36 -0
- pz_core/authoring/templates/project/__init__.py +1 -0
- pz_core/authoring/templates/project/agents.py +51 -0
- pz_core/authoring/templates/project/apps_container_readme.py +37 -0
- pz_core/authoring/templates/project/main_py.py +59 -0
- pz_core/authoring/templates/project/project_env.py +19 -0
- pz_core/authoring/templates/project/pyproject.py +26 -0
- pz_core/authoring/templates/project/pz_env_env.py +65 -0
- pz_core/authoring/templates/project/pz_env_jsonc.py +69 -0
- pz_core/authoring/templates/project/pz_jsonc.py +12 -0
- pz_core/authoring/templates/project/readme.py +94 -0
- pz_core/authoring/templates/project/root_gitkeep.py +8 -0
- pz_core/authoring/templates/shared/__init__.py +5 -0
- pz_core/authoring/templates/shared/text.py +10 -0
- pz_core/authoring/venv_service.py +87 -0
- pz_core/authoring/workspace.py +167 -0
- pz_core/cli.py +291 -0
- pz_core/cli_options.py +74 -0
- pz_core/core/__init__.py +3 -0
- pz_core/core/errors/__init__.py +5 -0
- pz_core/core/errors/models.py +117 -0
- pz_core/core/events/__init__.py +5 -0
- pz_core/core/events/registry.py +54 -0
- pz_core/core/extensions/__init__.py +51 -0
- pz_core/core/extensions/registry.py +790 -0
- pz_core/core/health/__init__.py +6 -0
- pz_core/core/health/contracts.py +10 -0
- pz_core/core/middlewares/__init__.py +6 -0
- pz_core/core/middlewares/models.py +24 -0
- pz_core/core/routing/__init__.py +5 -0
- pz_core/core/routing/models.py +21 -0
- pz_core/core/settings_contracts.py +25 -0
- pz_core/docs/README.md +20 -0
- pz_core/docs/distribution-README.md +438 -0
- pz_core/docs/pz/345/221/275/344/273/244/346/200/273/350/247/210.md +1011 -0
- pz_core/docs/pz/350/247/204/350/214/203/344/270/216/344/275/277/347/224/250/00-pz/346/236/266/346/236/204/346/200/273/347/272/262.md +240 -0
- pz_core/docs/pz/350/247/204/350/214/203/344/270/216/344/275/277/347/224/250/01-/347/233/256/345/275/225/344/270/216/345/210/206/345/261/202/350/247/204/350/214/203.md +216 -0
- pz_core/docs/pz/350/247/204/350/214/203/344/270/216/344/275/277/347/224/250/02-/345/214/205/344/270/216/345/210/206/345/217/221/350/247/204/350/214/203.md +403 -0
- pz_core/docs/pz/350/247/204/350/214/203/344/270/216/344/275/277/347/224/250/03-App/346/234/200/345/260/217/345/255/220/345/214/205/350/247/204/350/214/203.md +571 -0
- pz_core/docs/pz/350/247/204/350/214/203/344/270/216/344/275/277/347/224/250/04-Settings/344/270/216/351/205/215/347/275/256/350/247/204/350/214/203.md +1177 -0
- pz_core/docs/pz/350/247/204/350/214/203/344/270/216/344/275/277/347/224/250/05-/350/265/204/346/272/220/344/270/216/350/277/220/350/241/214/347/233/256/345/275/225/350/247/204/350/214/203.md +575 -0
- pz_core/docs/pz/350/247/204/350/214/203/344/270/216/344/275/277/347/224/250/06-/346/225/260/346/215/256/345/272/223/344/270/216/345/217/257/351/200/211/345/237/272/347/241/200/350/256/276/346/226/275/350/247/204/350/214/203.md +499 -0
- pz_core/docs/pz/350/247/204/350/214/203/344/270/216/344/275/277/347/224/250/07-App/346/233/277/346/215/242/350/247/204/350/214/203.md +206 -0
- pz_core/docs/pz/350/247/204/350/214/203/344/270/216/344/275/277/347/224/250/08-/345/271/263/345/217/260/347/272/247App/344/270/216/350/277/220/350/241/214/346/227/266/345/215/225/344/276/213/350/247/204/350/214/203.md +445 -0
- pz_core/docs/pz/350/247/204/350/214/203/344/270/216/344/275/277/347/224/250/09-CLI/344/270/216Worker/345/205/245/345/217/243/350/247/204/350/214/203.md +950 -0
- pz_core/docs/pz/350/247/204/350/214/203/344/270/216/344/275/277/347/224/250/10-/346/265/213/350/257/225/344/270/216/345/245/221/347/272/246/350/247/204/350/214/203.md +1001 -0
- pz_core/docs/pz/350/247/204/350/214/203/344/270/216/344/275/277/347/224/250/11-/344/273/223/345/272/223/347/234/237/347/233/270/346/272/220/345/234/260/345/233/276.md +102 -0
- pz_core/docs/pz/350/247/204/350/214/203/344/270/216/344/275/277/347/224/250/12-/346/236/204/345/273/272/344/270/216/345/217/221/345/270/203/346/243/200/346/237/245/346/270/205/345/215/225.md +171 -0
- pz_core/docs/pz/350/247/204/350/214/203/344/270/216/344/275/277/347/224/250/13-/346/255/243/345/274/217Facade/346/200/273/350/241/250.md +402 -0
- pz_core/docs/pz/350/247/204/350/214/203/344/270/216/344/275/277/347/224/250/14-/345/210/206/345/261/202/344/270/216/346/211/251/345/261/225/350/247/204/350/214/203.md +550 -0
- pz_core/docs/pz/350/247/204/350/214/203/344/270/216/344/275/277/347/224/250/15-/345/255/220/345/214/205/345/274/200/345/217/221/344/275/277/347/224/250/346/211/213/345/206/214.md +1004 -0
- pz_core/docs/pz/350/247/204/350/214/203/344/270/216/344/275/277/347/224/250/16-/346/211/251/345/261/225/347/202/271/346/255/243/345/274/217/345/215/217/350/256/256/346/270/205/345/215/225.md +352 -0
- pz_core/docs/pz/350/247/204/350/214/203/344/270/216/344/275/277/347/224/250/17-pz.protocols.v1/346/255/243/345/274/217/345/215/217/350/256/256.md +266 -0
- pz_core/docs/pz/350/247/204/350/214/203/344/270/216/344/275/277/347/224/250/18-/346/211/251/345/261/225/347/202/271/345/206/262/347/252/201/350/243/201/345/206/263/346/200/273/350/241/250.md +131 -0
- pz_core/docs/pz/350/247/204/350/214/203/344/270/216/344/275/277/347/224/250/19-/351/224/231/350/257/257/347/240/201/344/270/216/350/257/212/346/226/255/345/215/217/350/256/256.md +176 -0
- pz_core/docs/pz/350/247/204/350/214/203/344/270/216/344/275/277/347/224/250/20-/347/247/201/346/234/211/345/214/205/344/273/223/344/270/216/347/273/237/344/270/200/350/256/244/350/257/201/351/203/250/347/275/262/350/247/204/350/214/203.md +243 -0
- pz_core/docs/pz/350/247/204/350/214/203/344/270/216/344/275/277/347/224/250/21-contrib/347/272/246/345/256/232/344/270/216Provider/346/216/245/345/205/245/350/247/204/350/214/203.md +365 -0
- pz_core/docs/pz/350/247/204/350/214/203/344/270/216/344/275/277/347/224/250/22-/345/244/232/345/233/275/350/257/255/350/250/200/350/265/204/346/272/220/346/262/273/347/220/206/344/270/216/346/214/211/351/234/200/345/212/240/350/275/275/350/247/204/350/214/203.md +912 -0
- pz_core/docs/pz/350/247/204/350/214/203/344/270/216/344/275/277/347/224/250/23-/351/246/226/345/261/217/345/261/225/347/244/272/344/270/216/351/246/226/345/270/247/347/250/263/345/256/232/350/247/204/350/214/203.md +269 -0
- pz_core/docs/pz/350/247/204/350/214/203/344/270/216/344/275/277/347/224/250/24-pz/345/220/257/345/212/250/344/270/216/350/277/220/350/241/214/346/227/266/347/274/226/350/257/221/346/265/201/347/250/213.md +245 -0
- pz_core/docs/pz/350/247/204/350/214/203/344/270/216/344/275/277/347/224/250/25-/351/235/242/345/220/221/345/257/271/350/261/241/345/274/200/345/217/221/350/247/204/350/214/203.md +300 -0
- pz_core/docs/pz/350/247/204/350/214/203/344/270/216/344/275/277/347/224/250/README.md +98 -0
- pz_core/docs/pz/350/247/204/350/214/203/344/270/216/344/275/277/347/224/250/archive//344/270/255/351/227/264/346/200/201/00-legacy_core/346/240/207/345/207/206pip/345/214/205/345/214/226/351/207/215/346/236/204/346/200/273/347/272/262.md +1073 -0
- pz_core/docs/pz/350/247/204/350/214/203/344/270/216/344/275/277/347/224/250/archive//344/270/255/351/227/264/346/200/201/01-/347/233/256/345/275/225/344/270/216/345/210/206/345/261/202/351/207/215/346/236/204/346/211/247/350/241/214/346/226/271/346/241/210.md +224 -0
- pz_core/docs/pz/350/247/204/350/214/203/344/270/216/344/275/277/347/224/250/archive//344/270/255/351/227/264/346/200/201/02-/345/214/205/344/270/216/345/210/206/345/217/221/350/247/204/350/214/203-/345/220/253/345/216/206/345/217/262/345/217/243/345/276/204.md +671 -0
- pz_core/docs/pz/350/247/204/350/214/203/344/270/216/344/275/277/347/224/250/archive//344/270/255/351/227/264/346/200/201/13-/344/270/200/346/254/241/346/200/247/345/256/236/346/226/275/346/270/205/345/215/225.md +387 -0
- pz_core/docs/pz/350/247/204/350/214/203/344/270/216/344/275/277/347/224/250/archive//344/270/255/351/227/264/346/200/201/14-/345/255/220/345/214/205/351/200/202/351/205/215/346/224/271/351/200/240/346/270/205/345/215/225.md +592 -0
- pz_core/docs/pz/350/247/204/350/214/203/344/270/216/344/275/277/347/224/250/archive//344/270/255/351/227/264/346/200/201/15-infra/350/243/201/345/211/252/344/270/216/350/220/275/344/275/215/346/270/205/345/215/225.md +81 -0
- pz_core/docs/pz/350/247/204/350/214/203/344/270/216/344/275/277/347/224/250/archive//344/270/255/351/227/264/346/200/201/19-core/345/215/225/344/270/200/346/255/243/345/274/217/346/226/271/346/241/210/346/224/266/346/225/233/346/211/247/350/241/214/346/270/205/345/215/225.md +161 -0
- pz_core/docs/pz/350/247/204/350/214/203/344/270/216/344/275/277/347/224/250/archive//344/270/255/351/227/264/346/200/201/25-/345/215/217/350/256/256/345/210/260/346/272/220/347/240/201/345/267/256/350/267/235/346/270/205/345/215/225.md +377 -0
- pz_core/docs/pz/350/247/204/350/214/203/344/270/216/344/275/277/347/224/250/archive//344/270/255/351/227/264/346/200/201/26-cutover/345/256/214/345/267/245/346/243/200/346/237/245/346/270/205/345/215/225.md +117 -0
- pz_core/docs/pz/350/247/204/350/214/203/344/270/216/344/275/277/347/224/250/archive//344/270/255/351/227/264/346/200/201/29-/345/244/232/345/233/275/350/257/255/350/250/200/350/265/204/346/272/220/346/262/273/347/220/206/344/270/216/346/214/211/351/234/200/345/212/240/350/275/275/350/247/204/350/214/203-/345/220/253/350/277/201/347/247/273/347/255/226/347/225/245.md +956 -0
- pz_core/docs/pz/350/247/204/350/214/203/344/270/216/344/275/277/347/224/250/archive//344/270/255/351/227/264/346/200/201/99-/350/265/204/346/272/220/346/224/266/345/217/243/345/220/216/347/273/255TODO.md +84 -0
- pz_core/docs//345/217/221/347/211/210/345/211/215/346/270/205/345/215/225-4.0.11.md +84 -0
- pz_core/docs//346/226/260/346/211/213/346/214/207/345/215/227.md +422 -0
- pz_core/infra/__init__.py +17 -0
- pz_core/infra/db/__init__.py +23 -0
- pz_core/infra/db/contracts.py +73 -0
- pz_core/infra/health/__init__.py +5 -0
- pz_core/infra/health/contracts.py +8 -0
- pz_core/infra/kv/__init__.py +5 -0
- pz_core/infra/kv/contracts.py +17 -0
- pz_core/infra/observability/__init__.py +23 -0
- pz_core/infra/observability/contracts.py +142 -0
- pz_core/infra/resilience/__init__.py +5 -0
- pz_core/infra/resilience/contracts.py +17 -0
- pz_core/infra/resources/__init__.py +5 -0
- pz_core/infra/resources/contracts.py +16 -0
- pz_core/infra/settings/__init__.py +17 -0
- pz_core/infra/settings/models.py +81 -0
- pz_core/infra/storage/__init__.py +5 -0
- pz_core/infra/storage/ports.py +27 -0
- pz_core/project_root_commands.py +282 -0
- pz_core/project_runtime_cli.py +344 -0
- pz_core/project_sources.py +253 -0
- pz_core/pz_launcher.py +209 -0
- pz_core/root_cli.py +70 -0
- pz_core/runtime/__init__.py +229 -0
- pz_core/runtime/access.py +86 -0
- pz_core/runtime/adapters/__init__.py +5 -0
- pz_core/runtime/adapters/base.py +18 -0
- pz_core/runtime/asyncio_bridge.py +18 -0
- pz_core/runtime/bindings/__init__.py +5 -0
- pz_core/runtime/bindings/container.py +50 -0
- pz_core/runtime/cli/__init__.py +5 -0
- pz_core/runtime/cli/_args.py +67 -0
- pz_core/runtime/cli/app_commands.py +417 -0
- pz_core/runtime/cli/check.py +214 -0
- pz_core/runtime/cli/db.py +297 -0
- pz_core/runtime/cli/main.py +89 -0
- pz_core/runtime/cli/resources.py +280 -0
- pz_core/runtime/discovery.py +23 -0
- pz_core/runtime/environment_integrity.py +157 -0
- pz_core/runtime/errors.py +5 -0
- pz_core/runtime/events.py +87 -0
- pz_core/runtime/facades/__init__.py +38 -0
- pz_core/runtime/facades/_capabilities.py +46 -0
- pz_core/runtime/facades/cache.py +103 -0
- pz_core/runtime/facades/database.py +71 -0
- pz_core/runtime/facades/events.py +380 -0
- pz_core/runtime/facades/health.py +101 -0
- pz_core/runtime/facades/mail.py +121 -0
- pz_core/runtime/facades/observability.py +102 -0
- pz_core/runtime/facades/providers.py +75 -0
- pz_core/runtime/facades/resources.py +52 -0
- pz_core/runtime/facades/storage.py +296 -0
- pz_core/runtime/health/__init__.py +5 -0
- pz_core/runtime/health/service.py +102 -0
- pz_core/runtime/host.py +188 -0
- pz_core/runtime/host_runner.py +282 -0
- pz_core/runtime/http/__init__.py +20 -0
- pz_core/runtime/http/app.py +576 -0
- pz_core/runtime/http_timing.py +173 -0
- pz_core/runtime/invocation.py +29 -0
- pz_core/runtime/json_safe.py +47 -0
- pz_core/runtime/lifecycle/__init__.py +25 -0
- pz_core/runtime/lifecycle/manager.py +533 -0
- pz_core/runtime/plan.py +214 -0
- pz_core/runtime/plan_context.py +33 -0
- pz_core/runtime/plan_snapshot.py +177 -0
- pz_core/runtime/registries/__init__.py +27 -0
- pz_core/runtime/registries/capabilities.py +101 -0
- pz_core/runtime/registries/providers.py +396 -0
- pz_core/runtime/resource_assets.py +344 -0
- pz_core/runtime/run_cli.py +211 -0
- pz_core/runtime/settings.py +888 -0
- pz_core/runtime/worker/__init__.py +21 -0
- pz_core/runtime/worker/engine.py +921 -0
- pz_core/runtime/worker/runtime.py +25 -0
- pz_core/testing/__init__.py +15 -0
- pz_core/testing/doc_route_contracts.py +305 -0
- pz_core/utils/__init__.py +44 -0
- pz_core/utils/env.py +65 -0
- pz_core/utils/project_jsonc/__init__.py +29 -0
- pz_core/utils/project_jsonc/document.py +420 -0
- pz_core/utils/project_settings.py +99 -0
- pz_foundation/__init__.py +50 -0
- pz_foundation/_contracts.py +81 -0
- pz_foundation/_errors.py +34 -0
- pz_foundation/api.py +14 -0
- pz_foundation/apps.py +127 -0
- pz_foundation/auth/__init__.py +1 -0
- pz_foundation/cache_control.py +233 -0
- pz_foundation/cli/__init__.py +2 -0
- pz_foundation/cli/workers.py +565 -0
- pz_foundation/configs/__init__.py +0 -0
- pz_foundation/configs/default.env +15 -0
- pz_foundation/configs/default.jsonc +452 -0
- pz_foundation/db/__init__.py +94 -0
- pz_foundation/db/aerich_executor.py +664 -0
- pz_foundation/db/config.py +358 -0
- pz_foundation/db/connection_manager.py +689 -0
- pz_foundation/db/connection_probe.py +204 -0
- pz_foundation/db/database.py +1291 -0
- pz_foundation/db/deps.py +47 -0
- pz_foundation/db/lifecycle_status.py +85 -0
- pz_foundation/db/migrations.py +477 -0
- pz_foundation/db/mysql.py +57 -0
- pz_foundation/db/postgresql.py +409 -0
- pz_foundation/db/production_pool_fallback.py +143 -0
- pz_foundation/db/public.py +45 -0
- pz_foundation/db/session.py +369 -0
- pz_foundation/db/sqlite.py +15 -0
- pz_foundation/db/tortoise_manager.py +724 -0
- pz_foundation/db/tortoise_psycopg.py +148 -0
- pz_foundation/docs/README.md +18 -0
- pz_foundation/docs/distribution-README.md +319 -0
- pz_foundation/docs/infra/350/243/201/345/211/252/344/270/216/350/220/275/344/275/215/350/257/264/346/230/216.md +39 -0
- pz_foundation/docs//345/205/254/345/274/200/345/205/215/350/264/271/346/216/245/345/217/243/351/230/262/346/273/245/347/224/250/344/270/216/344/272/272/346/234/272/346/240/241/351/252/214.md +680 -0
- pz_foundation/docs//350/256/276/350/256/241/346/226/207/346/241/243.md +288 -0
- pz_foundation/docs//350/267/257/347/224/261/344/270/216URL/345/244/204/347/220/206/350/247/204/350/214/203.md +119 -0
- pz_foundation/health.py +105 -0
- pz_foundation/host/__init__.py +11 -0
- pz_foundation/host/builder.py +34 -0
- pz_foundation/host/cache_runtime.py +44 -0
- pz_foundation/host/db/__init__.py +17 -0
- pz_foundation/host/db/aerich_config.py +36 -0
- pz_foundation/host/db/config.py +106 -0
- pz_foundation/host/db/connection_manager.py +48 -0
- pz_foundation/host/db/deps.py +5 -0
- pz_foundation/host/db/orm_retry_patch.py +566 -0
- pz_foundation/host/db/request_adapter.py +325 -0
- pz_foundation/host/db/router.py +28 -0
- pz_foundation/host/db/session.py +284 -0
- pz_foundation/host/db/tortoise_manager.py +10 -0
- pz_foundation/host/idempotency.py +132 -0
- pz_foundation/host/lifespan.py +247 -0
- pz_foundation/host/redis_runtime.py +100 -0
- pz_foundation/host/web.py +790 -0
- pz_foundation/infra_provider.py +236 -0
- pz_foundation/kv/__init__.py +25 -0
- pz_foundation/kv/cache.py +1166 -0
- pz_foundation/kv/deps.py +84 -0
- pz_foundation/kv/public.py +25 -0
- pz_foundation/kv/redis_manager.py +1531 -0
- pz_foundation/lazy_exports.py +43 -0
- pz_foundation/lazy_imports.py +124 -0
- pz_foundation/lifecycle.py +392 -0
- pz_foundation/managed_workers.py +1117 -0
- pz_foundation/middlewares/__init__.py +26 -0
- pz_foundation/middlewares/_settings.py +250 -0
- pz_foundation/middlewares/analytics.py +124 -0
- pz_foundation/middlewares/cache_control.py +156 -0
- pz_foundation/middlewares/compression.py +202 -0
- pz_foundation/middlewares/cors.py +62 -0
- pz_foundation/middlewares/geo_country.py +44 -0
- pz_foundation/middlewares/inner_router.py +50 -0
- pz_foundation/middlewares/rate_limited/__init__.py +3 -0
- pz_foundation/middlewares/rate_limited/key_limiter.py +115 -0
- pz_foundation/middlewares/request_logging.py +104 -0
- pz_foundation/middlewares/route_owner.py +309 -0
- pz_foundation/middlewares/security_csrf.py +44 -0
- pz_foundation/middlewares/security_headers/__init__.py +4 -0
- pz_foundation/middlewares/security_headers/conflicts.py +44 -0
- pz_foundation/middlewares/security_headers/csp_nonce.py +200 -0
- pz_foundation/middlewares/security_headers/security_headers.py +44 -0
- pz_foundation/migrations/__init__.py +1 -0
- pz_foundation/migrations/pz_foundation/__init__.py +1 -0
- pz_foundation/models.py +22 -0
- pz_foundation/notifications/__init__.py +23 -0
- pz_foundation/notifications/email.py +542 -0
- pz_foundation/notifications/public.py +31 -0
- pz_foundation/observability/__init__.py +71 -0
- pz_foundation/observability/http.py +34 -0
- pz_foundation/observability/logger/__init__.py +49 -0
- pz_foundation/observability/logger/_bot_settings.py +126 -0
- pz_foundation/observability/logger/bot_message.py +592 -0
- pz_foundation/observability/logger/core.py +385 -0
- pz_foundation/observability/logger/delivery_audit.py +84 -0
- pz_foundation/observability/logger/feishu_bot.py +199 -0
- pz_foundation/observability/logger/telegram_bot.py +194 -0
- pz_foundation/observability/metrics.py +365 -0
- pz_foundation/observability/runtime.py +68 -0
- pz_foundation/public.py +405 -0
- pz_foundation/resources/__init__.py +12 -0
- pz_foundation/resources/builder.py +900 -0
- pz_foundation/resources/images.py +363 -0
- pz_foundation/root_cli.py +20 -0
- pz_foundation/routing/__init__.py +203 -0
- pz_foundation/routing/canonical.py +486 -0
- pz_foundation/routing/convertors.py +82 -0
- pz_foundation/routing/declarations.py +843 -0
- pz_foundation/routing/exports.py +148 -0
- pz_foundation/routing/loaders.py +138 -0
- pz_foundation/routing/manifest.py +215 -0
- pz_foundation/routing/manifest_provider.py +47 -0
- pz_foundation/routing/mounts.py +101 -0
- pz_foundation/routing/ordering.py +172 -0
- pz_foundation/routing/registry.py +133 -0
- pz_foundation/routing/utils.py +28 -0
- pz_foundation/runtime.py +234 -0
- pz_foundation/settings.py +253 -0
- pz_foundation/settings_normalization.py +130 -0
- pz_foundation/storage/__init__.py +25 -0
- pz_foundation/storage/local.py +209 -0
- pz_foundation/storage/public.py +106 -0
- pz_foundation/storage/s3.py +116 -0
- pz_foundation/storage/service.py +234 -0
- pz_foundation/urls.py +19 -0
- pz_foundation/utils/__init__.py +6 -0
- pz_foundation/utils/merge.py +160 -0
- pz_foundation/worker_replicas.py +55 -0
- pz_settings_center/__init__.py +5 -0
- pz_settings_center/api/__init__.py +5 -0
- pz_settings_center/api/runtime_overrides.py +360 -0
- pz_settings_center/apps.py +28 -0
- pz_settings_center/configs/__init__.py +0 -0
- pz_settings_center/configs/default.env +2 -0
- pz_settings_center/configs/default.jsonc +1 -0
- pz_settings_center/docs/01-settings_center/350/203/275/345/212/233/350/276/271/347/225/214.md +124 -0
- pz_settings_center/docs/README.md +12 -0
- pz_settings_center/docs/distribution-README.md +150 -0
- pz_settings_center/docs//350/256/276/350/256/241/346/226/207/346/241/243.md +48 -0
- pz_settings_center/integration_payload.py +18 -0
- pz_settings_center/project_helpers.py +405 -0
- pz_settings_center/public.py +139 -0
- pz_settings_center/routing_helpers.py +73 -0
- pz_settings_center/runtime_override_provider.py +61 -0
- pz_settings_center/typed_settings.py +324 -0
- pz_settings_center/urls.py +9 -0
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"""Formal minimal helper surface for package-level lazy exports."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from collections.abc import Mapping
|
|
6
|
+
from importlib import import_module
|
|
7
|
+
from typing import Any
|
|
8
|
+
|
|
9
|
+
LazyExportTarget = str | tuple[str, str]
|
|
10
|
+
LazyExportMap = Mapping[str, LazyExportTarget]
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def resolve_lazy_export(
|
|
14
|
+
module_name: str,
|
|
15
|
+
name: str,
|
|
16
|
+
export_map: LazyExportMap,
|
|
17
|
+
namespace: dict[str, Any],
|
|
18
|
+
) -> Any:
|
|
19
|
+
try:
|
|
20
|
+
target = export_map[name]
|
|
21
|
+
except KeyError as exc:
|
|
22
|
+
raise AttributeError(f"module {module_name!r} has no attribute {name!r}") from exc
|
|
23
|
+
|
|
24
|
+
if isinstance(target, tuple):
|
|
25
|
+
target_module, attr_name = target
|
|
26
|
+
else:
|
|
27
|
+
target_module, attr_name = target, name
|
|
28
|
+
|
|
29
|
+
if target_module.startswith("."):
|
|
30
|
+
imported = import_module(target_module, package=module_name)
|
|
31
|
+
else:
|
|
32
|
+
imported = import_module(target_module)
|
|
33
|
+
|
|
34
|
+
value = getattr(imported, attr_name)
|
|
35
|
+
namespace[name] = value
|
|
36
|
+
return value
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def export_dir(namespace: Mapping[str, Any], exported_names: list[str]) -> list[str]:
|
|
40
|
+
return sorted(set(namespace).union(exported_names))
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
__all__ = ["LazyExportMap", "LazyExportTarget", "export_dir", "resolve_lazy_export"]
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from functools import lru_cache
|
|
4
|
+
from importlib import import_module
|
|
5
|
+
from typing import Any, Callable
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
@lru_cache(maxsize=None)
|
|
9
|
+
def _import_module(module_name: str):
|
|
10
|
+
return import_module(module_name)
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class LazyImportProxy:
|
|
14
|
+
def __init__(
|
|
15
|
+
self,
|
|
16
|
+
resolver: Callable[[], Any],
|
|
17
|
+
label: str,
|
|
18
|
+
*,
|
|
19
|
+
module_name: str = "",
|
|
20
|
+
attr_name: str = "",
|
|
21
|
+
call_factory: bool = False,
|
|
22
|
+
) -> None:
|
|
23
|
+
self._resolver = resolver
|
|
24
|
+
self._label = label
|
|
25
|
+
self._module_name = str(module_name or "")
|
|
26
|
+
self._attr_name = str(attr_name or "")
|
|
27
|
+
self._call_factory = bool(call_factory)
|
|
28
|
+
|
|
29
|
+
def _resolve(self) -> Any:
|
|
30
|
+
if "_resolved" not in self.__dict__:
|
|
31
|
+
self.__dict__["_resolved"] = self._resolver()
|
|
32
|
+
return self.__dict__["_resolved"]
|
|
33
|
+
|
|
34
|
+
def __getattr__(self, name: str) -> Any:
|
|
35
|
+
return getattr(self._resolve(), name)
|
|
36
|
+
|
|
37
|
+
def __call__(self, *args: Any, **kwargs: Any) -> Any:
|
|
38
|
+
return self._resolve()(*args, **kwargs)
|
|
39
|
+
|
|
40
|
+
def __repr__(self) -> str:
|
|
41
|
+
return f"<LazyImportProxy {self._label}>"
|
|
42
|
+
|
|
43
|
+
def __reduce__(self):
|
|
44
|
+
if not self._module_name or not self._attr_name:
|
|
45
|
+
raise TypeError(f"{self.__class__.__name__} '{self._label}' is not serializable")
|
|
46
|
+
return (
|
|
47
|
+
_rebuild_lazy_import_proxy,
|
|
48
|
+
(self._module_name, self._attr_name, self._call_factory),
|
|
49
|
+
)
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
class LazyCallableProxy:
|
|
53
|
+
__slots__ = ("_module_name", "_attr_name", "_resolved")
|
|
54
|
+
|
|
55
|
+
def __init__(self, module_name: str, attr_name: str) -> None:
|
|
56
|
+
self._module_name = str(module_name)
|
|
57
|
+
self._attr_name = str(attr_name)
|
|
58
|
+
self._resolved: Callable[..., Any] | None = None
|
|
59
|
+
|
|
60
|
+
def _resolve(self) -> Callable[..., Any]:
|
|
61
|
+
if self._resolved is not None:
|
|
62
|
+
return self._resolved
|
|
63
|
+
value = getattr(_import_module(self._module_name), self._attr_name)
|
|
64
|
+
if not callable(value):
|
|
65
|
+
raise TypeError(f"{self._module_name}.{self._attr_name} must be callable")
|
|
66
|
+
self._resolved = value
|
|
67
|
+
return value
|
|
68
|
+
|
|
69
|
+
def __call__(self, *args: Any, **kwargs: Any) -> Any:
|
|
70
|
+
return self._resolve()(*args, **kwargs)
|
|
71
|
+
|
|
72
|
+
def __getattr__(self, name: str) -> Any:
|
|
73
|
+
return getattr(self._resolve(), name)
|
|
74
|
+
|
|
75
|
+
def __repr__(self) -> str:
|
|
76
|
+
return f"<LazyCallableProxy {self._module_name}.{self._attr_name}>"
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
def lazy_import_attr(module_name: str, attr_name: str) -> LazyImportProxy:
|
|
80
|
+
return LazyImportProxy(
|
|
81
|
+
resolver=lambda: getattr(_import_module(module_name), attr_name),
|
|
82
|
+
label=f"{module_name}.{attr_name}",
|
|
83
|
+
module_name=module_name,
|
|
84
|
+
attr_name=attr_name,
|
|
85
|
+
)
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
def lazy_import_factory(module_name: str, attr_name: str) -> LazyImportProxy:
|
|
89
|
+
def _resolve() -> Any:
|
|
90
|
+
factory = getattr(_import_module(module_name), attr_name)
|
|
91
|
+
return factory()
|
|
92
|
+
|
|
93
|
+
return LazyImportProxy(
|
|
94
|
+
resolver=_resolve,
|
|
95
|
+
label=f"{module_name}.{attr_name}()",
|
|
96
|
+
module_name=module_name,
|
|
97
|
+
attr_name=attr_name,
|
|
98
|
+
call_factory=True,
|
|
99
|
+
)
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
def _rebuild_lazy_import_proxy(module_name: str, attr_name: str, call_factory: bool) -> LazyImportProxy:
|
|
103
|
+
if call_factory:
|
|
104
|
+
return lazy_import_factory(module_name, attr_name)
|
|
105
|
+
return lazy_import_attr(module_name, attr_name)
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
def install_lazy_callables(
|
|
109
|
+
*,
|
|
110
|
+
module_name: str,
|
|
111
|
+
names: tuple[str, ...],
|
|
112
|
+
namespace: dict[str, Any],
|
|
113
|
+
) -> None:
|
|
114
|
+
for name in names:
|
|
115
|
+
namespace.setdefault(name, LazyCallableProxy(module_name, name))
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
__all__ = [
|
|
119
|
+
"LazyCallableProxy",
|
|
120
|
+
"LazyImportProxy",
|
|
121
|
+
"install_lazy_callables",
|
|
122
|
+
"lazy_import_attr",
|
|
123
|
+
"lazy_import_factory",
|
|
124
|
+
]
|
|
@@ -0,0 +1,392 @@
|
|
|
1
|
+
"""Foundation runtime lifecycle assembly."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from typing import Any
|
|
6
|
+
|
|
7
|
+
from pz_core.core.extensions import HostBuilderSpec
|
|
8
|
+
from pz_core.core.middlewares import MiddlewareDecl
|
|
9
|
+
import pz_settings_center.public as settings_center
|
|
10
|
+
|
|
11
|
+
from .db import FoundationDatabaseSettings, load_foundation_database_settings, probe_foundation_database_binding
|
|
12
|
+
from .health import probe_foundation_health
|
|
13
|
+
from .host.builder import FoundationWebHostBuilder
|
|
14
|
+
from .host.lifespan import InfraContext, setup_infra, shutdown_infra
|
|
15
|
+
from .kv import FoundationRedisSettings, get_required_foundation_cache, load_foundation_redis_settings
|
|
16
|
+
from .notifications import describe_email_backend_binding
|
|
17
|
+
from .observability import metrics, probe_observability
|
|
18
|
+
from .runtime import bind_runtime_state, reset_runtime_state
|
|
19
|
+
from .storage import probe_foundation_storage
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
MIDDLEWARES: tuple[MiddlewareDecl, ...] = (
|
|
23
|
+
MiddlewareDecl(
|
|
24
|
+
id="pz_foundation.geo_country",
|
|
25
|
+
factory="pz_foundation.middlewares:GeoCountryMiddleware",
|
|
26
|
+
owner="pz_foundation",
|
|
27
|
+
priority=10,
|
|
28
|
+
),
|
|
29
|
+
MiddlewareDecl(
|
|
30
|
+
id="pz_foundation.cors",
|
|
31
|
+
factory="pz_foundation.middlewares:ConfigurableCORSMiddleware",
|
|
32
|
+
owner="pz_foundation",
|
|
33
|
+
priority=20,
|
|
34
|
+
),
|
|
35
|
+
MiddlewareDecl(
|
|
36
|
+
id="pz_foundation.route_owner",
|
|
37
|
+
factory="pz_foundation.middlewares:DefaultLanguageRouteOwnerMiddleware",
|
|
38
|
+
owner="pz_foundation",
|
|
39
|
+
priority=58,
|
|
40
|
+
),
|
|
41
|
+
MiddlewareDecl(
|
|
42
|
+
id="pz_foundation.security_csrf",
|
|
43
|
+
factory="pz_foundation.middlewares:SecurityCSRFMiddleware",
|
|
44
|
+
owner="pz_foundation",
|
|
45
|
+
priority=120,
|
|
46
|
+
),
|
|
47
|
+
MiddlewareDecl(
|
|
48
|
+
id="pz_foundation.cache_control",
|
|
49
|
+
factory="pz_foundation.middlewares:CacheControlMiddleware",
|
|
50
|
+
owner="pz_foundation",
|
|
51
|
+
priority=160,
|
|
52
|
+
),
|
|
53
|
+
MiddlewareDecl(
|
|
54
|
+
id="pz_foundation.compression",
|
|
55
|
+
factory="pz_foundation.middlewares:CompressionMiddleware",
|
|
56
|
+
owner="pz_foundation",
|
|
57
|
+
priority=165,
|
|
58
|
+
),
|
|
59
|
+
MiddlewareDecl(
|
|
60
|
+
id="pz_foundation.analytics",
|
|
61
|
+
factory="pz_foundation.middlewares:AnalyticsMiddleware",
|
|
62
|
+
owner="pz_foundation",
|
|
63
|
+
priority=170,
|
|
64
|
+
),
|
|
65
|
+
MiddlewareDecl(
|
|
66
|
+
id="pz_foundation.csp_nonce",
|
|
67
|
+
factory="pz_foundation.middlewares.security_headers.csp_nonce:CSPNonceSecurityHeadersMiddleware",
|
|
68
|
+
owner="pz_foundation",
|
|
69
|
+
priority=180,
|
|
70
|
+
),
|
|
71
|
+
)
|
|
72
|
+
|
|
73
|
+
EXTENSIONS: tuple[HostBuilderSpec, ...] = (
|
|
74
|
+
HostBuilderSpec(
|
|
75
|
+
id="pz_foundation.host.builder.web",
|
|
76
|
+
owner_app="pz_foundation",
|
|
77
|
+
title="Foundation Web Host Builder",
|
|
78
|
+
priority=100,
|
|
79
|
+
builder=FoundationWebHostBuilder(),
|
|
80
|
+
),
|
|
81
|
+
)
|
|
82
|
+
|
|
83
|
+
PROVIDERS: tuple[dict[str, object], ...] = (
|
|
84
|
+
{
|
|
85
|
+
"id": "foundation-resource-builder",
|
|
86
|
+
"capability": "resources",
|
|
87
|
+
"owner": "pz_foundation",
|
|
88
|
+
"provider_path": "pz_foundation.resources.builder:build_resource_provider",
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
"id": "foundation-db-migrations",
|
|
92
|
+
"capability": "database.migrations",
|
|
93
|
+
"owner": "pz_foundation",
|
|
94
|
+
"provider_path": "pz_foundation.db.migrations:build_migration_provider",
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
"id": "foundation-storage",
|
|
98
|
+
"capability": "storage",
|
|
99
|
+
"owner": "pz_foundation",
|
|
100
|
+
"provider_path": "pz_foundation.storage.service:build_storage_provider",
|
|
101
|
+
},
|
|
102
|
+
)
|
|
103
|
+
|
|
104
|
+
_LIFECYCLE_INFRA_CONTEXTS: dict[str, InfraContext] = {}
|
|
105
|
+
|
|
106
|
+
def _safe_assign_runtime_state(state: object | None, **values: Any) -> None:
|
|
107
|
+
if state is None:
|
|
108
|
+
return
|
|
109
|
+
for key, value in values.items():
|
|
110
|
+
try:
|
|
111
|
+
setattr(state, key, value)
|
|
112
|
+
except (AttributeError, TypeError):
|
|
113
|
+
continue
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
def _host_state(host: object | None) -> object | None:
|
|
117
|
+
state = getattr(host, "state", None)
|
|
118
|
+
if state is None or state.__class__.__module__.startswith("pz_core.runtime"):
|
|
119
|
+
return None
|
|
120
|
+
return state
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
def _runtime_owner_key(app_id: str, host: object | None, context: object | None) -> str:
|
|
124
|
+
if _host_state(host) is not None:
|
|
125
|
+
return f"{app_id}:host:{id(host)}"
|
|
126
|
+
plan = getattr(context, "plan", None) if context is not None else None
|
|
127
|
+
if plan is not None:
|
|
128
|
+
return f"{app_id}:plan:{id(plan)}"
|
|
129
|
+
return f"{app_id}:host:{id(host)}"
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
async def _setup_lifecycle_infra(
|
|
133
|
+
*,
|
|
134
|
+
context: object,
|
|
135
|
+
project_dir: object,
|
|
136
|
+
) -> InfraContext:
|
|
137
|
+
settings_snapshot = getattr(getattr(context, "plan", None), "settings", None)
|
|
138
|
+
return await setup_infra(
|
|
139
|
+
settings_snapshot,
|
|
140
|
+
project_dir=str(project_dir) if project_dir is not None else None,
|
|
141
|
+
start_background_tasks=False,
|
|
142
|
+
)
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
async def _shutdown_lifecycle_infra(
|
|
146
|
+
host: object | None,
|
|
147
|
+
context: object | None,
|
|
148
|
+
*,
|
|
149
|
+
owner: str | None,
|
|
150
|
+
) -> None:
|
|
151
|
+
state = _host_state(host)
|
|
152
|
+
ctx = getattr(state, "pz_foundation_lifecycle_infra_context", None) if state is not None else None
|
|
153
|
+
if ctx is None and owner is not None:
|
|
154
|
+
ctx = _LIFECYCLE_INFRA_CONTEXTS.pop(owner, None)
|
|
155
|
+
elif owner is not None:
|
|
156
|
+
_LIFECYCLE_INFRA_CONTEXTS.pop(owner, None)
|
|
157
|
+
if ctx is not None:
|
|
158
|
+
await shutdown_infra(ctx)
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
def _resolve_component_capability_status(default_state: str, status: dict[str, Any] | None) -> str:
|
|
162
|
+
payload = dict(status or {})
|
|
163
|
+
if not bool(payload.get("enabled")):
|
|
164
|
+
return "disabled"
|
|
165
|
+
if bool(payload.get("probe_deferred")) and not str(payload.get("error") or "").strip():
|
|
166
|
+
return default_state if default_state in {"enabled", "ready"} else "enabled"
|
|
167
|
+
if bool(payload.get("ready")):
|
|
168
|
+
return "ready"
|
|
169
|
+
if str(payload.get("error") or "").strip() or not bool(payload.get("configured")) or bool(payload.get("enabled")):
|
|
170
|
+
return "unavailable"
|
|
171
|
+
return default_state if default_state in {"enabled", "ready"} else "enabled"
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
def _resolve_cache_capability_status(default_state: str, status: dict[str, Any] | None) -> str:
|
|
175
|
+
return _resolve_component_capability_status(default_state, status)
|
|
176
|
+
|
|
177
|
+
|
|
178
|
+
def _resolve_health_capability_status(default_state: str, status: dict[str, Any] | None) -> str:
|
|
179
|
+
payload = dict(status or {})
|
|
180
|
+
if not bool(payload.get("enabled", True)):
|
|
181
|
+
return "disabled"
|
|
182
|
+
if bool(payload.get("ready")):
|
|
183
|
+
return "ready"
|
|
184
|
+
if payload.get("issues") or str(payload.get("error") or "").strip() or bool(payload.get("enabled", True)):
|
|
185
|
+
return "unavailable"
|
|
186
|
+
return default_state if default_state in {"enabled", "ready"} else "enabled"
|
|
187
|
+
|
|
188
|
+
|
|
189
|
+
def _database_is_configured(db_settings: Any) -> bool:
|
|
190
|
+
if not bool(getattr(db_settings, "enabled", False)):
|
|
191
|
+
return False
|
|
192
|
+
driver = str(getattr(db_settings, "driver", "") or "").strip().lower() or "sqlite"
|
|
193
|
+
urls = tuple(getattr(db_settings, "urls", ()) or ())
|
|
194
|
+
if driver == "sqlite":
|
|
195
|
+
return bool(str(getattr(db_settings, "path", "") or (urls[0] if urls else "") or "").strip())
|
|
196
|
+
return bool(urls or str(getattr(db_settings, "host", "") or "").strip())
|
|
197
|
+
|
|
198
|
+
|
|
199
|
+
def _redis_is_configured(redis_settings: Any) -> bool:
|
|
200
|
+
if not bool(getattr(redis_settings, "enabled", False)):
|
|
201
|
+
return False
|
|
202
|
+
return bool(str(getattr(redis_settings, "url", "") or getattr(redis_settings, "host", "") or "").strip())
|
|
203
|
+
|
|
204
|
+
|
|
205
|
+
async def startup_foundation(host: object, context: object, *, app_id: str = "foundation") -> None:
|
|
206
|
+
settings_obj = settings_center.settings.pz_foundation
|
|
207
|
+
if not settings_obj.enabled:
|
|
208
|
+
return
|
|
209
|
+
project = getattr(getattr(context, "plan", None), "project", None)
|
|
210
|
+
project_dir = getattr(project, "project_dir", None)
|
|
211
|
+
owner = _runtime_owner_key(app_id, host, context)
|
|
212
|
+
infra_ctx = await _setup_lifecycle_infra(context=context, project_dir=project_dir)
|
|
213
|
+
_LIFECYCLE_INFRA_CONTEXTS[owner] = infra_ctx
|
|
214
|
+
database_status = _bind_database(project_dir, settings_obj)
|
|
215
|
+
kv_status = _bind_kv(project_dir, settings_obj)
|
|
216
|
+
mail_status = _bind_mail(project_dir, settings_obj)
|
|
217
|
+
storage_status = _bind_storage(project_dir, settings_obj)
|
|
218
|
+
observability_status = _bind_observability(project_dir, settings_obj)
|
|
219
|
+
health_status = _bind_health(
|
|
220
|
+
project_dir,
|
|
221
|
+
settings_obj,
|
|
222
|
+
database_status=database_status,
|
|
223
|
+
kv_status=kv_status,
|
|
224
|
+
mail_status=mail_status,
|
|
225
|
+
storage_status=storage_status,
|
|
226
|
+
observability_status=observability_status,
|
|
227
|
+
)
|
|
228
|
+
capability_statuses = {
|
|
229
|
+
"cache": _resolve_cache_capability_status(settings_obj.cache.state, kv_status),
|
|
230
|
+
"database": _resolve_component_capability_status("enabled", database_status),
|
|
231
|
+
"health": _resolve_health_capability_status(settings_obj.health.state, health_status),
|
|
232
|
+
"mail": _resolve_component_capability_status(settings_obj.mail.state, mail_status),
|
|
233
|
+
"observability": _resolve_component_capability_status(
|
|
234
|
+
settings_obj.observability.state,
|
|
235
|
+
observability_status,
|
|
236
|
+
),
|
|
237
|
+
"storage": _resolve_component_capability_status(settings_obj.storage.state, storage_status),
|
|
238
|
+
}
|
|
239
|
+
runtime_state = bind_runtime_state(
|
|
240
|
+
capability_statuses=capability_statuses,
|
|
241
|
+
database_status=database_status,
|
|
242
|
+
kv_status=kv_status,
|
|
243
|
+
mail_status=mail_status,
|
|
244
|
+
storage_status=storage_status,
|
|
245
|
+
observability_status=observability_status,
|
|
246
|
+
health_status=health_status,
|
|
247
|
+
project_dir=project_dir,
|
|
248
|
+
owner=owner,
|
|
249
|
+
)
|
|
250
|
+
metrics.foundation_runtime_ready.set(1.0 if health_status.get("ready") else 0.0)
|
|
251
|
+
state = _host_state(host)
|
|
252
|
+
_safe_assign_runtime_state(
|
|
253
|
+
state,
|
|
254
|
+
pz_foundation_owner=owner,
|
|
255
|
+
pz_foundation_lifecycle_infra_context=infra_ctx,
|
|
256
|
+
pz_foundation_runtime=runtime_state,
|
|
257
|
+
pz_foundation_database=database_status,
|
|
258
|
+
pz_foundation_kv=kv_status,
|
|
259
|
+
pz_foundation_mail=mail_status,
|
|
260
|
+
pz_foundation_storage=storage_status,
|
|
261
|
+
pz_foundation_observability=observability_status,
|
|
262
|
+
pz_foundation_health=health_status,
|
|
263
|
+
)
|
|
264
|
+
|
|
265
|
+
|
|
266
|
+
async def shutdown_foundation(host: object, context: object | None = None, *, app_id: str = "foundation") -> None:
|
|
267
|
+
state = _host_state(host)
|
|
268
|
+
owner = getattr(state, "pz_foundation_owner", None) if state is not None else _runtime_owner_key(app_id, host, context)
|
|
269
|
+
await _shutdown_lifecycle_infra(host, context, owner=owner)
|
|
270
|
+
reset_runtime_state(owner=owner)
|
|
271
|
+
metrics.foundation_runtime_ready.set(0.0)
|
|
272
|
+
_safe_assign_runtime_state(
|
|
273
|
+
state,
|
|
274
|
+
pz_foundation_owner=None,
|
|
275
|
+
pz_foundation_lifecycle_infra_context=None,
|
|
276
|
+
pz_foundation_runtime=None,
|
|
277
|
+
pz_foundation_database=None,
|
|
278
|
+
pz_foundation_kv=None,
|
|
279
|
+
pz_foundation_mail=None,
|
|
280
|
+
pz_foundation_storage=None,
|
|
281
|
+
pz_foundation_observability=None,
|
|
282
|
+
pz_foundation_health=None,
|
|
283
|
+
)
|
|
284
|
+
|
|
285
|
+
|
|
286
|
+
def _bind_database(project_dir: object, settings_obj: object) -> dict[str, Any]:
|
|
287
|
+
del settings_obj
|
|
288
|
+
db_settings = _database_settings(project_dir)
|
|
289
|
+
return probe_foundation_database_binding(project_dir=project_dir, settings=db_settings)
|
|
290
|
+
|
|
291
|
+
|
|
292
|
+
def _bind_kv(project_dir: object, settings_obj: object) -> dict[str, Any]:
|
|
293
|
+
if not settings_obj.cache.enabled:
|
|
294
|
+
return {
|
|
295
|
+
"enabled": False,
|
|
296
|
+
"configured": False,
|
|
297
|
+
"backend": None,
|
|
298
|
+
"operational": False,
|
|
299
|
+
"degraded": False,
|
|
300
|
+
"ready": False,
|
|
301
|
+
"error": None,
|
|
302
|
+
}
|
|
303
|
+
redis_settings = _redis_settings(project_dir)
|
|
304
|
+
status: dict[str, Any] = {
|
|
305
|
+
"enabled": bool(redis_settings.enabled),
|
|
306
|
+
"configured": _redis_is_configured(redis_settings),
|
|
307
|
+
"backend": None,
|
|
308
|
+
"operational": False,
|
|
309
|
+
"degraded": False,
|
|
310
|
+
"ready": False,
|
|
311
|
+
"error": None,
|
|
312
|
+
"host": redis_settings.host or None,
|
|
313
|
+
"port": redis_settings.port,
|
|
314
|
+
"db": redis_settings.db,
|
|
315
|
+
"url": redis_settings.url or None,
|
|
316
|
+
}
|
|
317
|
+
if not redis_settings.enabled:
|
|
318
|
+
return status
|
|
319
|
+
try:
|
|
320
|
+
cache = get_required_foundation_cache(
|
|
321
|
+
project_dir=project_dir,
|
|
322
|
+
settings=redis_settings,
|
|
323
|
+
capability_name="foundation redis",
|
|
324
|
+
)
|
|
325
|
+
probe_key = "__foundation_probe__"
|
|
326
|
+
cache.set(probe_key, "1", ex=1)
|
|
327
|
+
operational = cache.get(probe_key) == "1"
|
|
328
|
+
status["backend"] = "redis"
|
|
329
|
+
status["operational"] = operational
|
|
330
|
+
status["degraded"] = False
|
|
331
|
+
status["ready"] = bool(redis_settings.enabled) and operational
|
|
332
|
+
try:
|
|
333
|
+
cache.delete(probe_key)
|
|
334
|
+
except Exception:
|
|
335
|
+
pass
|
|
336
|
+
except Exception as exc:
|
|
337
|
+
status["degraded"] = True
|
|
338
|
+
status["error"] = f"{type(exc).__name__}: {exc}"
|
|
339
|
+
return status
|
|
340
|
+
|
|
341
|
+
|
|
342
|
+
def _database_settings(project_dir: object) -> FoundationDatabaseSettings:
|
|
343
|
+
return load_foundation_database_settings(
|
|
344
|
+
project_dir=str(project_dir) if project_dir is not None else None,
|
|
345
|
+
)
|
|
346
|
+
|
|
347
|
+
|
|
348
|
+
def _redis_settings(project_dir: object) -> FoundationRedisSettings:
|
|
349
|
+
return load_foundation_redis_settings(
|
|
350
|
+
project_dir=str(project_dir) if project_dir is not None else None,
|
|
351
|
+
)
|
|
352
|
+
|
|
353
|
+
def _read_float(value: object, default: float) -> float:
|
|
354
|
+
try:
|
|
355
|
+
return float(value if value is not None else default)
|
|
356
|
+
except Exception:
|
|
357
|
+
return default
|
|
358
|
+
|
|
359
|
+
|
|
360
|
+
def _bind_mail(project_dir: object, settings_obj: object) -> dict[str, Any]:
|
|
361
|
+
if not settings_obj.mail.enabled:
|
|
362
|
+
return {"enabled": False, "configured": False, "ready": False, "error": None, "probe_deferred": False}
|
|
363
|
+
return describe_email_backend_binding(project_dir=project_dir)
|
|
364
|
+
|
|
365
|
+
|
|
366
|
+
def _bind_storage(project_dir: object, settings_obj: object) -> dict[str, Any]:
|
|
367
|
+
if not settings_obj.storage.enabled:
|
|
368
|
+
return {"enabled": False, "configured": False, "ready": False, "error": None}
|
|
369
|
+
metrics.foundation_storage_probes_total.inc()
|
|
370
|
+
return probe_foundation_storage(project_dir=project_dir)
|
|
371
|
+
|
|
372
|
+
|
|
373
|
+
def _bind_observability(project_dir: object, settings_obj: object) -> dict[str, Any]:
|
|
374
|
+
if not settings_obj.observability.enabled:
|
|
375
|
+
return {"enabled": False, "configured": False, "ready": False, "error": None}
|
|
376
|
+
return probe_observability(project_dir=project_dir)
|
|
377
|
+
|
|
378
|
+
|
|
379
|
+
def _bind_health(project_dir: object, settings_obj: object, **statuses: Any) -> dict[str, Any]:
|
|
380
|
+
if not settings_obj.health.enabled:
|
|
381
|
+
return {"enabled": False, "configured": False, "ready": False, "error": None}
|
|
382
|
+
metrics.foundation_health_checks_total.inc()
|
|
383
|
+
return probe_foundation_health(project_dir=project_dir, **statuses)
|
|
384
|
+
|
|
385
|
+
|
|
386
|
+
__all__ = [
|
|
387
|
+
"EXTENSIONS",
|
|
388
|
+
"MIDDLEWARES",
|
|
389
|
+
"PROVIDERS",
|
|
390
|
+
"shutdown_foundation",
|
|
391
|
+
"startup_foundation",
|
|
392
|
+
]
|