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,55 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from dataclasses import dataclass
|
|
4
|
+
from typing import Any
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
_FOUNDATION_APP_ID = "pz_foundation"
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def _read_mapping_member(container: Any, key: str) -> Any:
|
|
11
|
+
if container is None:
|
|
12
|
+
return None
|
|
13
|
+
if isinstance(container, dict):
|
|
14
|
+
return container.get(key)
|
|
15
|
+
return getattr(container, key, None)
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def _positive_int(value: Any) -> int | None:
|
|
19
|
+
try:
|
|
20
|
+
parsed = int(value)
|
|
21
|
+
except (TypeError, ValueError):
|
|
22
|
+
return None
|
|
23
|
+
return parsed if parsed > 0 else None
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
@dataclass(frozen=True, slots=True)
|
|
27
|
+
class WorkerReplicaCountResolver:
|
|
28
|
+
"""Resolve managed worker target replica counts from settings center."""
|
|
29
|
+
|
|
30
|
+
plan: Any
|
|
31
|
+
|
|
32
|
+
def target_count(self, spec: Any) -> int:
|
|
33
|
+
setting_name = str(getattr(spec, "replica_count_setting", "") or "").strip()
|
|
34
|
+
if not setting_name:
|
|
35
|
+
return 1
|
|
36
|
+
payload = self.owner_settings(str(getattr(spec, "app_id", "") or ""))
|
|
37
|
+
configured_count = _positive_int(payload.get(setting_name) if isinstance(payload, dict) else None)
|
|
38
|
+
return configured_count if configured_count is not None else self.default_count()
|
|
39
|
+
|
|
40
|
+
def owner_settings(self, app_id: str) -> dict[str, Any]:
|
|
41
|
+
try:
|
|
42
|
+
app_settings = getattr(getattr(self.plan, "settings", None), "app_settings", None)
|
|
43
|
+
payload = app_settings(app_id) if callable(app_settings) else {}
|
|
44
|
+
except Exception:
|
|
45
|
+
return {}
|
|
46
|
+
return payload if isinstance(payload, dict) else {}
|
|
47
|
+
|
|
48
|
+
def default_count(self) -> int:
|
|
49
|
+
foundation_settings = self.owner_settings(_FOUNDATION_APP_ID)
|
|
50
|
+
managed_workers = _read_mapping_member(foundation_settings, "managed_workers")
|
|
51
|
+
configured_count = _positive_int(_read_mapping_member(managed_workers, "default_replica_count"))
|
|
52
|
+
return configured_count if configured_count is not None else 1
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
__all__ = ["WorkerReplicaCountResolver"]
|
|
@@ -0,0 +1,360 @@
|
|
|
1
|
+
"""Runtime override registry owned by the settings center package."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
from typing import Any, Mapping
|
|
7
|
+
|
|
8
|
+
from pz_core.runtime.errors import PzError
|
|
9
|
+
from pz_core.runtime import settings as runtime_settings
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
_RUNTIME_OVERRIDE_REGISTRY: dict[str, dict[str, type[Any]]] = {}
|
|
13
|
+
_RUNTIME_OVERRIDE_VALUES: dict[str | None, dict[str, dict[str, Any]]] = {}
|
|
14
|
+
_RUNTIME_OVERRIDE_SCHEMA_VERSION = 0
|
|
15
|
+
_RUNTIME_OVERRIDE_VALUE_VERSIONS: dict[str | None, int] = {}
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def _invalidate_settings_runtime_caches() -> None:
|
|
19
|
+
invalidate = getattr(runtime_settings, "_invalidate_settings_runtime_caches", None)
|
|
20
|
+
if callable(invalidate):
|
|
21
|
+
invalidate()
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def _bump_runtime_override_schema_version() -> None:
|
|
25
|
+
global _RUNTIME_OVERRIDE_SCHEMA_VERSION
|
|
26
|
+
_RUNTIME_OVERRIDE_SCHEMA_VERSION += 1
|
|
27
|
+
_invalidate_settings_runtime_caches()
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def _bump_runtime_override_value_version(scope_key: str | None) -> None:
|
|
31
|
+
_RUNTIME_OVERRIDE_VALUE_VERSIONS[scope_key] = int(_RUNTIME_OVERRIDE_VALUE_VERSIONS.get(scope_key, 0)) + 1
|
|
32
|
+
_invalidate_settings_runtime_caches()
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def _normalize_project_dir(project_dir: str | Path | None) -> str | None:
|
|
36
|
+
if project_dir is None:
|
|
37
|
+
return None
|
|
38
|
+
return str(Path(project_dir).expanduser().resolve())
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def _normalize_runtime_override_namespace(namespace: object, *, action: str) -> str:
|
|
42
|
+
if not isinstance(namespace, str):
|
|
43
|
+
raise PzError(
|
|
44
|
+
code="PZ_RUNTIME_OVERRIDE_NAMESPACE_INVALID",
|
|
45
|
+
message="Runtime override namespace must be a non-empty app_id string.",
|
|
46
|
+
stage="settings",
|
|
47
|
+
owner="pz_settings_center",
|
|
48
|
+
action=action,
|
|
49
|
+
)
|
|
50
|
+
normalized = namespace.strip()
|
|
51
|
+
if not normalized or any(token in normalized for token in (":", "/", "\\", " ")):
|
|
52
|
+
raise PzError(
|
|
53
|
+
code="PZ_RUNTIME_OVERRIDE_NAMESPACE_INVALID",
|
|
54
|
+
message=f"Runtime override namespace '{namespace}' must be a plain app_id.",
|
|
55
|
+
stage="settings",
|
|
56
|
+
owner="pz_settings_center",
|
|
57
|
+
action=action,
|
|
58
|
+
)
|
|
59
|
+
return normalized
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
def _normalize_runtime_override_schema(
|
|
63
|
+
namespace: str,
|
|
64
|
+
values: Mapping[str, type[Any]],
|
|
65
|
+
*,
|
|
66
|
+
action: str,
|
|
67
|
+
) -> dict[str, type[Any]]:
|
|
68
|
+
if not isinstance(values, Mapping):
|
|
69
|
+
raise PzError(
|
|
70
|
+
code="PZ_RUNTIME_OVERRIDE_SCHEMA_INVALID",
|
|
71
|
+
message=f"Runtime override schema for '{namespace}' must be a mapping.",
|
|
72
|
+
stage="settings",
|
|
73
|
+
owner=namespace,
|
|
74
|
+
action=action,
|
|
75
|
+
)
|
|
76
|
+
out: dict[str, type[Any]] = {}
|
|
77
|
+
for raw_key, raw_type in dict(values or {}).items():
|
|
78
|
+
key = str(raw_key or "").strip()
|
|
79
|
+
if not key or not isinstance(raw_type, type):
|
|
80
|
+
raise PzError(
|
|
81
|
+
code="PZ_RUNTIME_OVERRIDE_SCHEMA_INVALID",
|
|
82
|
+
message=f"Runtime override schema for '{namespace}' contains an invalid field declaration.",
|
|
83
|
+
stage="settings",
|
|
84
|
+
owner=namespace,
|
|
85
|
+
action=action,
|
|
86
|
+
)
|
|
87
|
+
out[key] = raw_type
|
|
88
|
+
return out
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
def _coerce_runtime_override_bool(value: Any) -> bool:
|
|
92
|
+
if isinstance(value, bool):
|
|
93
|
+
return value
|
|
94
|
+
if isinstance(value, str):
|
|
95
|
+
normalized = value.strip().lower()
|
|
96
|
+
if normalized in {"1", "true", "yes", "on"}:
|
|
97
|
+
return True
|
|
98
|
+
if normalized in {"0", "false", "no", "off"}:
|
|
99
|
+
return False
|
|
100
|
+
if isinstance(value, int) and value in {0, 1}:
|
|
101
|
+
return bool(value)
|
|
102
|
+
raise ValueError("expected boolean")
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
def _coerce_runtime_override_int(value: Any) -> int:
|
|
106
|
+
if isinstance(value, bool):
|
|
107
|
+
raise ValueError("expected integer")
|
|
108
|
+
if isinstance(value, int):
|
|
109
|
+
return value
|
|
110
|
+
if isinstance(value, str):
|
|
111
|
+
text = value.strip()
|
|
112
|
+
if text:
|
|
113
|
+
try:
|
|
114
|
+
return int(text, 10)
|
|
115
|
+
except ValueError:
|
|
116
|
+
pass
|
|
117
|
+
raise ValueError("expected integer")
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
def _coerce_runtime_override_float(value: Any) -> float:
|
|
121
|
+
if isinstance(value, bool):
|
|
122
|
+
raise ValueError("expected number")
|
|
123
|
+
if isinstance(value, (int, float)):
|
|
124
|
+
return float(value)
|
|
125
|
+
if isinstance(value, str):
|
|
126
|
+
text = value.strip()
|
|
127
|
+
if text:
|
|
128
|
+
try:
|
|
129
|
+
return float(text)
|
|
130
|
+
except ValueError:
|
|
131
|
+
pass
|
|
132
|
+
raise ValueError("expected number")
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
def _coerce_runtime_override_list(value: Any) -> list[Any]:
|
|
136
|
+
if isinstance(value, list):
|
|
137
|
+
return list(value)
|
|
138
|
+
if isinstance(value, tuple):
|
|
139
|
+
return list(value)
|
|
140
|
+
raise ValueError("expected list")
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
def _coerce_runtime_override_dict(value: Any) -> dict[str, Any]:
|
|
144
|
+
if isinstance(value, Mapping):
|
|
145
|
+
return dict(value)
|
|
146
|
+
raise ValueError("expected object")
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
def _is_runtime_override_model_type(expected_type: type[Any]) -> bool:
|
|
150
|
+
return hasattr(expected_type, "model_validate") or hasattr(expected_type, "parse_obj")
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
def _coerce_runtime_override_model(value: Any, expected_type: type[Any]) -> dict[str, Any]:
|
|
154
|
+
if hasattr(expected_type, "model_validate"):
|
|
155
|
+
model = expected_type.model_validate(value)
|
|
156
|
+
elif hasattr(expected_type, "parse_obj"):
|
|
157
|
+
model = expected_type.parse_obj(value)
|
|
158
|
+
else:
|
|
159
|
+
raise ValueError("expected object")
|
|
160
|
+
dump = getattr(model, "model_dump", None)
|
|
161
|
+
if callable(dump):
|
|
162
|
+
return dict(dump(mode="python"))
|
|
163
|
+
if isinstance(model, Mapping):
|
|
164
|
+
return dict(model)
|
|
165
|
+
raise ValueError("expected object")
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
def _coerce_runtime_override_value(value: Any, expected_type: type[Any]) -> Any:
|
|
169
|
+
if _is_runtime_override_model_type(expected_type):
|
|
170
|
+
return _coerce_runtime_override_model(value, expected_type)
|
|
171
|
+
if expected_type is bool:
|
|
172
|
+
return _coerce_runtime_override_bool(value)
|
|
173
|
+
if expected_type is int:
|
|
174
|
+
return _coerce_runtime_override_int(value)
|
|
175
|
+
if expected_type is float:
|
|
176
|
+
return _coerce_runtime_override_float(value)
|
|
177
|
+
if expected_type is list:
|
|
178
|
+
return _coerce_runtime_override_list(value)
|
|
179
|
+
if expected_type is dict:
|
|
180
|
+
return _coerce_runtime_override_dict(value)
|
|
181
|
+
if expected_type is tuple:
|
|
182
|
+
if isinstance(value, (list, tuple)):
|
|
183
|
+
return tuple(value)
|
|
184
|
+
raise ValueError("expected list")
|
|
185
|
+
if expected_type is set:
|
|
186
|
+
if isinstance(value, (list, tuple, set, frozenset)):
|
|
187
|
+
return set(value)
|
|
188
|
+
raise ValueError("expected list")
|
|
189
|
+
if expected_type is frozenset:
|
|
190
|
+
if isinstance(value, (list, tuple, set, frozenset)):
|
|
191
|
+
return frozenset(value)
|
|
192
|
+
raise ValueError("expected list")
|
|
193
|
+
if expected_type is str:
|
|
194
|
+
if isinstance(value, (dict, list, tuple, set, frozenset)):
|
|
195
|
+
raise ValueError("expected string")
|
|
196
|
+
return "" if value is None else str(value)
|
|
197
|
+
if isinstance(value, expected_type):
|
|
198
|
+
return value
|
|
199
|
+
raise ValueError(f"expected {expected_type.__name__}")
|
|
200
|
+
|
|
201
|
+
|
|
202
|
+
def _coerce_runtime_override_payload(
|
|
203
|
+
namespace: str,
|
|
204
|
+
payload: Mapping[str, Any] | None,
|
|
205
|
+
*,
|
|
206
|
+
action: str,
|
|
207
|
+
) -> dict[str, Any]:
|
|
208
|
+
schema = dict(_RUNTIME_OVERRIDE_REGISTRY.get(namespace, {}) or {})
|
|
209
|
+
if not schema:
|
|
210
|
+
raise PzError(
|
|
211
|
+
code="PZ_RUNTIME_OVERRIDE_NAMESPACE_UNREGISTERED",
|
|
212
|
+
message=f"Runtime override namespace '{namespace}' is not registered.",
|
|
213
|
+
stage="settings",
|
|
214
|
+
owner=namespace,
|
|
215
|
+
action=action,
|
|
216
|
+
)
|
|
217
|
+
values = dict(payload or {})
|
|
218
|
+
out: dict[str, Any] = {}
|
|
219
|
+
for key, value in values.items():
|
|
220
|
+
field_name = str(key or "").strip()
|
|
221
|
+
if field_name not in schema:
|
|
222
|
+
raise PzError(
|
|
223
|
+
code="PZ_RUNTIME_OVERRIDE_KEY_UNDECLARED",
|
|
224
|
+
message=f"Runtime override key '{namespace}.{field_name}' is not declared in schema.",
|
|
225
|
+
stage="settings",
|
|
226
|
+
owner=namespace,
|
|
227
|
+
action=action,
|
|
228
|
+
)
|
|
229
|
+
try:
|
|
230
|
+
out[field_name] = _coerce_runtime_override_value(value, schema[field_name])
|
|
231
|
+
except ValueError as exc:
|
|
232
|
+
raise PzError(
|
|
233
|
+
code="PZ_RUNTIME_OVERRIDE_VALUE_INVALID",
|
|
234
|
+
message=f"Runtime override value for '{namespace}.{field_name}' is invalid: {exc}",
|
|
235
|
+
stage="settings",
|
|
236
|
+
owner=namespace,
|
|
237
|
+
action=action,
|
|
238
|
+
) from exc
|
|
239
|
+
return out
|
|
240
|
+
|
|
241
|
+
|
|
242
|
+
def register_runtime_overrides(namespace: str, values: dict[str, type[Any]]) -> None:
|
|
243
|
+
key = _normalize_runtime_override_namespace(namespace, action="register_runtime_overrides")
|
|
244
|
+
schema = _normalize_runtime_override_schema(key, values, action="register_runtime_overrides")
|
|
245
|
+
if not schema:
|
|
246
|
+
if key in _RUNTIME_OVERRIDE_REGISTRY:
|
|
247
|
+
_RUNTIME_OVERRIDE_REGISTRY.pop(key, None)
|
|
248
|
+
_bump_runtime_override_schema_version()
|
|
249
|
+
return
|
|
250
|
+
if _RUNTIME_OVERRIDE_REGISTRY.get(key) != schema:
|
|
251
|
+
_RUNTIME_OVERRIDE_REGISTRY[key] = schema
|
|
252
|
+
_bump_runtime_override_schema_version()
|
|
253
|
+
|
|
254
|
+
|
|
255
|
+
def unregister_runtime_overrides(namespace: str) -> None:
|
|
256
|
+
key = _normalize_runtime_override_namespace(namespace, action="unregister_runtime_overrides")
|
|
257
|
+
if key in _RUNTIME_OVERRIDE_REGISTRY:
|
|
258
|
+
_RUNTIME_OVERRIDE_REGISTRY.pop(key, None)
|
|
259
|
+
_bump_runtime_override_schema_version()
|
|
260
|
+
|
|
261
|
+
|
|
262
|
+
def get_runtime_overrides_schema() -> dict[str, dict[str, type[Any]]]:
|
|
263
|
+
return {key: dict(value) for key, value in _RUNTIME_OVERRIDE_REGISTRY.items()}
|
|
264
|
+
|
|
265
|
+
|
|
266
|
+
def _override_scope_key(project_dir: str | Path | None = None) -> str | None:
|
|
267
|
+
normalized_project_dir = _normalize_project_dir(project_dir)
|
|
268
|
+
if normalized_project_dir is not None:
|
|
269
|
+
return normalized_project_dir
|
|
270
|
+
return runtime_settings.current_settings_project_dir()
|
|
271
|
+
|
|
272
|
+
|
|
273
|
+
def get_applied_runtime_overrides(project_dir: str | Path | None = None) -> dict[str, dict[str, Any]]:
|
|
274
|
+
scoped = dict(_RUNTIME_OVERRIDE_VALUES.get(None, {}) or {})
|
|
275
|
+
scope_key = _override_scope_key(project_dir)
|
|
276
|
+
if scope_key is not None:
|
|
277
|
+
for namespace, values in dict(_RUNTIME_OVERRIDE_VALUES.get(scope_key, {}) or {}).items():
|
|
278
|
+
merged = dict(scoped.get(str(namespace), {}) or {})
|
|
279
|
+
merged.update(dict(values or {}))
|
|
280
|
+
scoped[str(namespace)] = merged
|
|
281
|
+
return scoped
|
|
282
|
+
|
|
283
|
+
|
|
284
|
+
def get_runtime_overrides_signature(project_dir: str | Path | None = None) -> tuple[int, int, int]:
|
|
285
|
+
scope_key = _override_scope_key(project_dir)
|
|
286
|
+
return (
|
|
287
|
+
int(_RUNTIME_OVERRIDE_SCHEMA_VERSION),
|
|
288
|
+
int(_RUNTIME_OVERRIDE_VALUE_VERSIONS.get(None, 0)),
|
|
289
|
+
int(_RUNTIME_OVERRIDE_VALUE_VERSIONS.get(scope_key, 0)) if scope_key is not None else 0,
|
|
290
|
+
)
|
|
291
|
+
|
|
292
|
+
|
|
293
|
+
def apply_runtime_overrides(
|
|
294
|
+
values: Mapping[str, Mapping[str, Any]],
|
|
295
|
+
*,
|
|
296
|
+
project_dir: str | Path | None = None,
|
|
297
|
+
) -> None:
|
|
298
|
+
scope_key = _override_scope_key(project_dir)
|
|
299
|
+
bucket = dict(_RUNTIME_OVERRIDE_VALUES.get(scope_key, {}) or {})
|
|
300
|
+
normalized_updates: dict[str, dict[str, Any]] = {}
|
|
301
|
+
for namespace, payload in dict(values or {}).items():
|
|
302
|
+
ns = _normalize_runtime_override_namespace(namespace, action="apply_runtime_overrides")
|
|
303
|
+
if payload is not None and not isinstance(payload, Mapping):
|
|
304
|
+
raise PzError(
|
|
305
|
+
code="PZ_RUNTIME_OVERRIDE_PAYLOAD_INVALID",
|
|
306
|
+
message=f"Runtime override payload for '{ns}' must be a mapping.",
|
|
307
|
+
stage="settings",
|
|
308
|
+
owner=ns,
|
|
309
|
+
action="apply_runtime_overrides",
|
|
310
|
+
)
|
|
311
|
+
normalized_updates[ns] = _coerce_runtime_override_payload(ns, payload, action="apply_runtime_overrides")
|
|
312
|
+
for ns, payload in normalized_updates.items():
|
|
313
|
+
merged = dict(bucket.get(ns, {}) or {})
|
|
314
|
+
if payload:
|
|
315
|
+
merged.update(payload)
|
|
316
|
+
bucket[ns] = merged
|
|
317
|
+
_RUNTIME_OVERRIDE_VALUES[scope_key] = bucket
|
|
318
|
+
_bump_runtime_override_value_version(scope_key)
|
|
319
|
+
|
|
320
|
+
|
|
321
|
+
def reset_runtime_overrides(
|
|
322
|
+
namespace: str | None = None,
|
|
323
|
+
*,
|
|
324
|
+
project_dir: str | Path | None = None,
|
|
325
|
+
) -> None:
|
|
326
|
+
scope_key = _override_scope_key(project_dir)
|
|
327
|
+
if namespace is None:
|
|
328
|
+
if project_dir is None and scope_key is None:
|
|
329
|
+
_RUNTIME_OVERRIDE_VALUES.clear()
|
|
330
|
+
_RUNTIME_OVERRIDE_VALUE_VERSIONS.clear()
|
|
331
|
+
_bump_runtime_override_value_version(None)
|
|
332
|
+
return
|
|
333
|
+
_RUNTIME_OVERRIDE_VALUES.pop(scope_key, None)
|
|
334
|
+
_bump_runtime_override_value_version(scope_key)
|
|
335
|
+
return
|
|
336
|
+
key = _normalize_runtime_override_namespace(namespace, action="reset_runtime_overrides")
|
|
337
|
+
if project_dir is None and scope_key is None:
|
|
338
|
+
for values in _RUNTIME_OVERRIDE_VALUES.values():
|
|
339
|
+
values.pop(key, None)
|
|
340
|
+
_RUNTIME_OVERRIDE_VALUE_VERSIONS.clear()
|
|
341
|
+
_bump_runtime_override_value_version(None)
|
|
342
|
+
return
|
|
343
|
+
values = dict(_RUNTIME_OVERRIDE_VALUES.get(scope_key, {}) or {})
|
|
344
|
+
values.pop(key, None)
|
|
345
|
+
if values:
|
|
346
|
+
_RUNTIME_OVERRIDE_VALUES[scope_key] = values
|
|
347
|
+
else:
|
|
348
|
+
_RUNTIME_OVERRIDE_VALUES.pop(scope_key, None)
|
|
349
|
+
_bump_runtime_override_value_version(scope_key)
|
|
350
|
+
|
|
351
|
+
|
|
352
|
+
__all__ = [
|
|
353
|
+
"apply_runtime_overrides",
|
|
354
|
+
"get_applied_runtime_overrides",
|
|
355
|
+
"get_runtime_overrides_signature",
|
|
356
|
+
"get_runtime_overrides_schema",
|
|
357
|
+
"register_runtime_overrides",
|
|
358
|
+
"reset_runtime_overrides",
|
|
359
|
+
"unregister_runtime_overrides",
|
|
360
|
+
]
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from pz_core.core.extensions import SettingsProviderSpec
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class SettingsCenterApp:
|
|
7
|
+
id = "pz_settings_center"
|
|
8
|
+
name = "PZ Settings Center"
|
|
9
|
+
version = "5.0.0"
|
|
10
|
+
required_pz = ">=5.0.0"
|
|
11
|
+
|
|
12
|
+
def extensions(self):
|
|
13
|
+
from .runtime_override_provider import SETTINGS_PROVIDER
|
|
14
|
+
|
|
15
|
+
return (
|
|
16
|
+
SettingsProviderSpec(
|
|
17
|
+
id="pz_settings_center.runtime_overrides.provider",
|
|
18
|
+
owner_app=self.id,
|
|
19
|
+
provider=SETTINGS_PROVIDER,
|
|
20
|
+
priority=10000,
|
|
21
|
+
),
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
app = SettingsCenterApp()
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
__all__ = ["SettingsCenterApp", "app"]
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
# settings_center 能力边界
|
|
2
|
+
|
|
3
|
+
`settings_center` 是统一 `settings` 的正式 contrib 入口。
|
|
4
|
+
|
|
5
|
+
它的职责只有一件事:
|
|
6
|
+
|
|
7
|
+
- 作为应用层读取和操作统一 settings 的正式 surface
|
|
8
|
+
|
|
9
|
+
边界如下:
|
|
10
|
+
|
|
11
|
+
- `legacy_core.runtime.settings`
|
|
12
|
+
- 只保留底层 machinery
|
|
13
|
+
- 包括 snapshot 绑定、runtime 上下文、provider plumbing、typed projection 基础能力
|
|
14
|
+
|
|
15
|
+
- `apps.contrib.settings_center`
|
|
16
|
+
- 作为应用层正式入口
|
|
17
|
+
- 统一暴露 `settings / resolve_settings / get_project_* / read_project_* / runtime override 操作`
|
|
18
|
+
- `public.py` 是唯一正式入口
|
|
19
|
+
- 包根 `__init__.py` 只保留最小 package surface,不再扁平 re-export 全部 runtime helper
|
|
20
|
+
- 内部实现分成:
|
|
21
|
+
- `runtime_surface.py`:对 core machinery 的低层绑定
|
|
22
|
+
- `typed_settings.py`:typed settings / proxy / resolve surface
|
|
23
|
+
- `project_helpers.py`:project helper / read_project_* surface
|
|
24
|
+
|
|
25
|
+
- `pz.authoring`
|
|
26
|
+
- 承载 `pz settings init` / `pz settings update` 的唯一正式 service 与 CLI
|
|
27
|
+
- 维护并消费项目默认骨架,然后写回 `pz.jsonc`
|
|
28
|
+
|
|
29
|
+
- `apps.contrib.settings_operator`
|
|
30
|
+
- 只负责对统一 settings 做运行时操作和管理面
|
|
31
|
+
- 不再承担 settings 的正式读取入口语义
|
|
32
|
+
|
|
33
|
+
- `apps.contrib.module_config`
|
|
34
|
+
- 与 `settings_center` 并列
|
|
35
|
+
- 独立负责 module config / module catalog
|
|
36
|
+
|
|
37
|
+
不允许:
|
|
38
|
+
|
|
39
|
+
- 继续把应用层 settings 正式读取入口塞回 `legacy_core`
|
|
40
|
+
- 把 `settings_operator` 当成泛配置杂货铺
|
|
41
|
+
- 让业务子包自己发明新的项目级 settings 入口
|
|
42
|
+
- 把项目级 `pz.jsonc` 默认骨架和作者面 CLI 再塞回 `settings_center` 或其它 contrib 子包
|
|
43
|
+
|
|
44
|
+
## settings lazy autoload
|
|
45
|
+
|
|
46
|
+
`settings_center.settings` 是应用层唯一正式 settings 入口对象,并支持 settings lazy autoload:
|
|
47
|
+
|
|
48
|
+
```python
|
|
49
|
+
import pz_settings_center.public as settings_center
|
|
50
|
+
|
|
51
|
+
value = settings_center.settings.<app_id>.<field>
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
正式边界:
|
|
55
|
+
|
|
56
|
+
- import `pz_settings_center.public` 只取得 public surface,不得在 import 阶段编译或绑定 `SettingsSnapshot`
|
|
57
|
+
- 第一次读取 `settings_center.settings` 的具体 namespace 或字段时,如果当前进程没有已绑定 snapshot,settings center 才自动解析当前项目并编译 `SettingsSnapshot`
|
|
58
|
+
- 若当前进程已由正式 runtime 入口绑定 snapshot,settings center 必须优先消费该 snapshot
|
|
59
|
+
- 直接脚本通过 `settings_center.settings` 读取时,项目解析顺序固定为:已绑定 runtime snapshot > `PZ_PROJECT_DIR` > 从 cwd 向上查找 `pz.jsonc`
|
|
60
|
+
- 跨项目工具面显式调用 `settings_center.resolve_settings(project_dir=...)` 时,该显式 `project_dir` 只作用于本次解析,并优先于当前进程的默认项目发现
|
|
61
|
+
- 环境选择仍只由 `PZ_ENV` 决定,默认 `develop`
|
|
62
|
+
- lazy autoload 是 settings-only 能力,不启动 Web/CLI/worker,不产出完整 `RuntimePlan`,也不保证 route、middleware、resource、infra 或 lifecycle 已装配
|
|
63
|
+
|
|
64
|
+
settings provider 约束:
|
|
65
|
+
|
|
66
|
+
- provider 必须只依赖 `SettingsSnapshot`、`ProjectContext` 与 `SettingsProviderContext`
|
|
67
|
+
- provider 不得依赖 Web app、route manifest、resource build、数据库连接、Redis 连接、runtime bindings 或 lifecycle startup
|
|
68
|
+
- provider patch 只参与最终 settings 视图,不得反向改写 `SettingsSnapshot`
|
|
69
|
+
|
|
70
|
+
## 请求期 runtime settings snapshot
|
|
71
|
+
|
|
72
|
+
请求期中间件如果需要反复读取同一个 app namespace 的运行态配置,正式只读入口是:
|
|
73
|
+
|
|
74
|
+
- `pz_settings_center.public.get_runtime_namespace_settings_snapshot(app_id)`
|
|
75
|
+
|
|
76
|
+
它返回当前 namespace 的已合并配置值和稳定 `signature`。签名来自编译期 `SettingsSnapshot` 与 settings runtime override 版本;runtime override 变化后签名必须变化,调用方应据此重新编译自己的规则快照。
|
|
77
|
+
|
|
78
|
+
边界固定如下:
|
|
79
|
+
|
|
80
|
+
- `settings_center` 只提供统一 settings 读面和 runtime override 版本信号。
|
|
81
|
+
- `settings_center.public` 不向业务子包公开 `read_runtime_env*` / `has_runtime_env_value` / `iter_runtime_env_items`;环境层只属于 settings 编译链输入,不是 app runtime 可消费 surface。
|
|
82
|
+
- `settings_operator` 仍只负责 runtime override 的治理、写入、L2 refresh 与后台,不是其它中间件的内部依赖面。
|
|
83
|
+
- 访问控制、认证、重定向等中间件可以缓存“按 settings 编译后的规则”,但缓存签名必须来自 `settings_center` 的正式 snapshot surface。
|
|
84
|
+
- 业务子包不得绕过 `settings_center` 直接读取 `settings_operator.settings_runtime.store`。
|
|
85
|
+
|
|
86
|
+
## app 运行时消费边界
|
|
87
|
+
|
|
88
|
+
`settings_center.settings.<app_id>` 是业务运行时唯一可消费的最终配置对象。它暴露的是已经由 settings 编译链处理完成的 typed 值,包括项目配置、环境层、provider patch、runtime override、默认补齐与必要 normalize。
|
|
89
|
+
|
|
90
|
+
业务子包的运行时模块只做消费:
|
|
91
|
+
|
|
92
|
+
- 读取 `settings_center.settings.<app_id>.<field>`
|
|
93
|
+
- 把字段值传给 service、store、worker、middleware、URL builder 等运行时对象
|
|
94
|
+
- 在必要时把多个字段组装成业务对象,但不得改变字段来源、默认值或类型语义
|
|
95
|
+
|
|
96
|
+
业务子包的运行时模块不得再做配置处理:
|
|
97
|
+
|
|
98
|
+
- 不得新增 `runtime_settings.py`、`system_settings.py`、`load_<app>_settings()`、`resolve_<app>_settings()` 等第二读取主链
|
|
99
|
+
- 不得读取 `os.environ`、项目 `.env*`、`pz*.jsonc`、包内 `configs/default.jsonc` / `configs/default.env` 来补配置
|
|
100
|
+
- 不得对 settings 字段做本地 `bool(...)`、`int(...)`、`float(...)`、`str(...)` 类型重解释
|
|
101
|
+
- 不得用本地 dataclass 默认值、硬编码默认值、`or <default>`、`try/except missing -> default` 形成运行时 fallback
|
|
102
|
+
- 不得包装本地 “settings missing” 错误来替代 settings center / `SettingsSnapshot` 的缺失语义
|
|
103
|
+
- 不得通过 `env` 参数、legacy root 字段、历史 namespace 或 helper fallback 形成第二套读取顺序
|
|
104
|
+
|
|
105
|
+
业务子包只在声明层定义配置:
|
|
106
|
+
|
|
107
|
+
- `settings.py` / `settings/` 声明 `AppSettings` 字段类型、校验、必要 normalize 与 `__runtime_overrides__`
|
|
108
|
+
- `configs/default.jsonc` / `configs/default.env` 提供 `pz settings init/update` 的作者面默认模板
|
|
109
|
+
- 子包设计文档说明字段语义、取值范围、运行时影响与 owner 边界
|
|
110
|
+
|
|
111
|
+
需要默认值、类型转换、别名兼容、环境变量覆盖或 runtime override 生效时,必须进入 settings 编译链或 settings runtime owner 的正式链路;业务运行时代码不能补一套本地配置处理逻辑。
|
|
112
|
+
|
|
113
|
+
## 跨项目 snapshot 边界
|
|
114
|
+
|
|
115
|
+
`settings_center.resolve_settings(project_dir=...)` 只允许用于明确的跨项目工具面或 owner 级基础设施探针,例如 `pz settings` 作者面、settings operator 管理面、foundation public probe、detached worker supervisor 对指定项目的状态检查。
|
|
116
|
+
|
|
117
|
+
这类调用的语义是“针对一个显式 project_dir 编译/读取该项目的 `SettingsSnapshot`”,不是业务子包运行时配置消费入口。
|
|
118
|
+
|
|
119
|
+
约束固定如下:
|
|
120
|
+
|
|
121
|
+
- 普通业务运行时、middleware、worker、router、service 不得为了读取自身 app 配置调用 `resolve_settings(project_dir=...)`。
|
|
122
|
+
- 已处于宿主运行时的代码应消费当前绑定的 `settings_center.settings.<app_id>`,或消费启动编译阶段传入的 `RuntimePlan` / `SettingsSnapshot`。
|
|
123
|
+
- 跨项目 probe 如果需要把某个 namespace 组装成内部配置对象,只能从 `SettingsSnapshot` 中取值;不得再叠加本地 env/default/legacy namespace fallback。
|
|
124
|
+
- 这种 helper 不得命名成 `runtime_settings.py`、`system_settings.py`、`load_<app>_settings()` 或 `resolve_<app>_settings()`,避免被业务 runtime 当成第二读取主链复用。
|