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,454 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import json
|
|
4
|
+
import os
|
|
5
|
+
import shutil
|
|
6
|
+
import sys
|
|
7
|
+
from dataclasses import dataclass
|
|
8
|
+
from pathlib import Path
|
|
9
|
+
|
|
10
|
+
from pz_core.runtime.cli._args import PzArgumentParser, json_output_requested, normalize_cli_argv
|
|
11
|
+
from pz_core.runtime.errors import PzError, as_pz_error
|
|
12
|
+
from pz_core.cli_options import add_cli_option, option_shortcuts_help
|
|
13
|
+
|
|
14
|
+
from .orchestration_service import execute_env_init, execute_env_install, execute_env_sync
|
|
15
|
+
from .naming import resolve_project_dir
|
|
16
|
+
from .sync_service import collect_sync_targets, sync_project_targets
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
_OWNER = "pz_core.authoring.env"
|
|
20
|
+
@dataclass(frozen=True, slots=True)
|
|
21
|
+
class ToolStatus:
|
|
22
|
+
name: str
|
|
23
|
+
required: bool
|
|
24
|
+
found: bool
|
|
25
|
+
path: str | None
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
@dataclass(frozen=True, slots=True)
|
|
29
|
+
class EnvReport:
|
|
30
|
+
project_dir: Path
|
|
31
|
+
initialized_project: bool
|
|
32
|
+
tools: tuple[ToolStatus, ...]
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def _program_name() -> str:
|
|
36
|
+
env_name = os.getenv("PZ_PROGRAM_NAME", "").strip().lower()
|
|
37
|
+
if env_name in {"pz", "pz"}:
|
|
38
|
+
return env_name
|
|
39
|
+
candidate = os.path.basename(str(sys.argv[0] or "")).strip().lower()
|
|
40
|
+
if candidate in {"pz", "pz"}:
|
|
41
|
+
return candidate
|
|
42
|
+
return "pz"
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def _usage() -> str:
|
|
46
|
+
program_name = _program_name()
|
|
47
|
+
return f"""{program_name} env
|
|
48
|
+
|
|
49
|
+
Usage:
|
|
50
|
+
{program_name} env doctor [--json] [--project-dir PATH]
|
|
51
|
+
{program_name} env install [--json] [--project-dir PATH] [--group NAME] [--extra NAME] [--reinstall-package NAME] [--project-only]
|
|
52
|
+
{program_name} env init [--json] [--no-sync] [--project-dir PATH]
|
|
53
|
+
{program_name} env sync [--json] [--project-dir PATH] [--group NAME] [--extra NAME] [--reinstall-package NAME] [--project-only]
|
|
54
|
+
|
|
55
|
+
{option_shortcuts_help()}
|
|
56
|
+
"""
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def _resolve_existing_project_dir(raw_project_dir: str | None, *, action: str) -> Path:
|
|
60
|
+
project_dir = resolve_project_dir(raw_project_dir)
|
|
61
|
+
if not project_dir.exists() or not project_dir.is_dir():
|
|
62
|
+
raise PzError(
|
|
63
|
+
code="PZ_ENV_PROJECT_DIR_INVALID",
|
|
64
|
+
message=f"project directory must exist: {project_dir}",
|
|
65
|
+
stage="cli",
|
|
66
|
+
owner=_OWNER,
|
|
67
|
+
action=action,
|
|
68
|
+
)
|
|
69
|
+
return project_dir
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
def _collect_report(project_dir: Path) -> EnvReport:
|
|
73
|
+
tools = (
|
|
74
|
+
ToolStatus(name="python", required=True, found=True, path=sys.executable),
|
|
75
|
+
ToolStatus(
|
|
76
|
+
name="dependency_backend",
|
|
77
|
+
required=True,
|
|
78
|
+
found=bool(shutil.which("uv")),
|
|
79
|
+
path=shutil.which("uv"),
|
|
80
|
+
),
|
|
81
|
+
ToolStatus(name="git", required=True, found=bool(shutil.which("git")), path=shutil.which("git")),
|
|
82
|
+
)
|
|
83
|
+
return EnvReport(
|
|
84
|
+
project_dir=project_dir,
|
|
85
|
+
initialized_project=(project_dir / "pz.jsonc").is_file(),
|
|
86
|
+
tools=tools,
|
|
87
|
+
)
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
def _report_status(report: EnvReport) -> str:
|
|
91
|
+
missing_required = [item.name for item in report.tools if item.required and not item.found]
|
|
92
|
+
return "ok" if not missing_required else "error"
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
def _report_code(report: EnvReport, *, action: str) -> str:
|
|
96
|
+
if _report_status(report) == "ok":
|
|
97
|
+
return f"PZ_ENV_{action.upper()}_OK"
|
|
98
|
+
return "PZ_ENV_PREREQUISITES_MISSING"
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
def _json_payload(
|
|
102
|
+
report: EnvReport,
|
|
103
|
+
*,
|
|
104
|
+
action: str,
|
|
105
|
+
updated_settings_path: str | None = None,
|
|
106
|
+
project_venv: str | None = None,
|
|
107
|
+
project_venv_created: bool = False,
|
|
108
|
+
) -> str:
|
|
109
|
+
sync_targets = collect_sync_targets(report.project_dir)
|
|
110
|
+
return json.dumps(
|
|
111
|
+
{
|
|
112
|
+
"status": _report_status(report),
|
|
113
|
+
"code": _report_code(report, action=action),
|
|
114
|
+
"stage": "cli",
|
|
115
|
+
"owner": _OWNER,
|
|
116
|
+
"action": action,
|
|
117
|
+
"project_dir": str(report.project_dir),
|
|
118
|
+
"project_initialized": report.initialized_project,
|
|
119
|
+
"tools": [
|
|
120
|
+
{
|
|
121
|
+
"name": item.name,
|
|
122
|
+
"required": item.required,
|
|
123
|
+
"found": item.found,
|
|
124
|
+
"path": item.path,
|
|
125
|
+
}
|
|
126
|
+
for item in report.tools
|
|
127
|
+
],
|
|
128
|
+
"sync_targets": [
|
|
129
|
+
{
|
|
130
|
+
"name": item.name,
|
|
131
|
+
"kind": item.kind,
|
|
132
|
+
"path": str(item.path),
|
|
133
|
+
"exists": item.exists,
|
|
134
|
+
"has_pyproject": item.has_pyproject,
|
|
135
|
+
}
|
|
136
|
+
for item in sync_targets
|
|
137
|
+
],
|
|
138
|
+
"project_venv": project_venv,
|
|
139
|
+
"project_venv_created": project_venv_created,
|
|
140
|
+
"updated_settings_path": updated_settings_path,
|
|
141
|
+
},
|
|
142
|
+
ensure_ascii=True,
|
|
143
|
+
sort_keys=True,
|
|
144
|
+
)
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
def _json_error(error: PzError) -> str:
|
|
148
|
+
payload = error.to_dict()
|
|
149
|
+
payload["status"] = "error"
|
|
150
|
+
return json.dumps(payload, ensure_ascii=True, sort_keys=True)
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
def _print_report(
|
|
154
|
+
report: EnvReport,
|
|
155
|
+
*,
|
|
156
|
+
action: str,
|
|
157
|
+
updated_settings_path: str | None = None,
|
|
158
|
+
project_venv: str | None = None,
|
|
159
|
+
) -> None:
|
|
160
|
+
print(f"env {action} {report.project_dir}")
|
|
161
|
+
for item in report.tools:
|
|
162
|
+
if item.found:
|
|
163
|
+
print(f"{item.name}: ok ({item.path})")
|
|
164
|
+
else:
|
|
165
|
+
print(f"{item.name}: missing")
|
|
166
|
+
project_status = "present" if report.initialized_project else "missing"
|
|
167
|
+
print(f"pz.jsonc: {project_status}")
|
|
168
|
+
sync_targets = collect_sync_targets(report.project_dir)
|
|
169
|
+
if sync_targets:
|
|
170
|
+
print("sync targets:")
|
|
171
|
+
for item in sync_targets:
|
|
172
|
+
pyproject_status = "pyproject" if item.has_pyproject else "no-pyproject"
|
|
173
|
+
exists_status = "present" if item.exists else "missing"
|
|
174
|
+
print(f"- {item.kind}:{item.name} {item.path} [{exists_status}, {pyproject_status}]")
|
|
175
|
+
if updated_settings_path is not None:
|
|
176
|
+
print(f"settings: updated ({updated_settings_path})")
|
|
177
|
+
if project_venv is not None:
|
|
178
|
+
print(f"project venv: ready ({project_venv})")
|
|
179
|
+
print(f"status: {_report_status(report)}")
|
|
180
|
+
|
|
181
|
+
|
|
182
|
+
def doctor_main(argv: list[object] | None = None) -> int:
|
|
183
|
+
json_mode = json_output_requested(argv)
|
|
184
|
+
try:
|
|
185
|
+
normalized = normalize_cli_argv(
|
|
186
|
+
argv,
|
|
187
|
+
code="PZ_CLI_ARGV_INVALID",
|
|
188
|
+
stage="cli",
|
|
189
|
+
owner=_OWNER,
|
|
190
|
+
action="doctor",
|
|
191
|
+
)
|
|
192
|
+
parser = PzArgumentParser(
|
|
193
|
+
prog=f"{_program_name()} env doctor",
|
|
194
|
+
description="Check the local pz authoring prerequisites for this project directory.",
|
|
195
|
+
error_code="PZ_ENV_ARGUMENTS_INVALID",
|
|
196
|
+
error_stage="cli",
|
|
197
|
+
error_owner=_OWNER,
|
|
198
|
+
error_action="doctor",
|
|
199
|
+
)
|
|
200
|
+
add_cli_option(parser, "--json", action="store_true", dest="json_output")
|
|
201
|
+
add_cli_option(parser, "--project-dir", dest="project_dir")
|
|
202
|
+
ns = parser.parse_args(normalized)
|
|
203
|
+
report = _collect_report(_resolve_existing_project_dir(ns.project_dir, action="doctor"))
|
|
204
|
+
if ns.json_output:
|
|
205
|
+
print(_json_payload(report, action="doctor"))
|
|
206
|
+
else:
|
|
207
|
+
_print_report(report, action="doctor")
|
|
208
|
+
return 0 if _report_status(report) == "ok" else 1
|
|
209
|
+
except Exception as exc:
|
|
210
|
+
error = as_pz_error(exc, owner=_OWNER, action="doctor", stage="cli")
|
|
211
|
+
if json_mode:
|
|
212
|
+
print(_json_error(error))
|
|
213
|
+
else:
|
|
214
|
+
print(str(error), file=sys.stderr)
|
|
215
|
+
return 1
|
|
216
|
+
|
|
217
|
+
|
|
218
|
+
def init_main(argv: list[object] | None = None) -> int:
|
|
219
|
+
json_mode = json_output_requested(argv)
|
|
220
|
+
try:
|
|
221
|
+
normalized = normalize_cli_argv(
|
|
222
|
+
argv,
|
|
223
|
+
code="PZ_CLI_ARGV_INVALID",
|
|
224
|
+
stage="cli",
|
|
225
|
+
owner=_OWNER,
|
|
226
|
+
action="init",
|
|
227
|
+
)
|
|
228
|
+
parser = PzArgumentParser(
|
|
229
|
+
prog=f"{_program_name()} env init",
|
|
230
|
+
description="Prepare the formal pz project skeleton and refresh managed settings blocks.",
|
|
231
|
+
error_code="PZ_ENV_ARGUMENTS_INVALID",
|
|
232
|
+
error_stage="cli",
|
|
233
|
+
error_owner=_OWNER,
|
|
234
|
+
error_action="init",
|
|
235
|
+
)
|
|
236
|
+
add_cli_option(parser, "--json", action="store_true", dest="json_output")
|
|
237
|
+
add_cli_option(parser, "--no-sync", action="store_true", dest="no_sync")
|
|
238
|
+
add_cli_option(parser, "--project-dir", dest="project_dir")
|
|
239
|
+
ns = parser.parse_args(normalized)
|
|
240
|
+
project_dir = _resolve_existing_project_dir(ns.project_dir, action="init")
|
|
241
|
+
report = _collect_report(project_dir)
|
|
242
|
+
if _report_status(report) != "ok":
|
|
243
|
+
if ns.json_output:
|
|
244
|
+
print(_json_payload(report, action="init"))
|
|
245
|
+
else:
|
|
246
|
+
_print_report(report, action="init")
|
|
247
|
+
return 1
|
|
248
|
+
execution = execute_env_init(
|
|
249
|
+
project_dir,
|
|
250
|
+
action="init",
|
|
251
|
+
no_sync=bool(ns.no_sync),
|
|
252
|
+
)
|
|
253
|
+
final_report = EnvReport(
|
|
254
|
+
project_dir=project_dir,
|
|
255
|
+
initialized_project=((project_dir / "pz.jsonc").is_file()),
|
|
256
|
+
tools=report.tools,
|
|
257
|
+
)
|
|
258
|
+
project_venv = None if execution.project_venv is None else str(execution.project_venv.path)
|
|
259
|
+
project_venv_created = False if execution.project_venv is None else execution.project_venv.created
|
|
260
|
+
if ns.json_output:
|
|
261
|
+
print(
|
|
262
|
+
_json_payload(
|
|
263
|
+
final_report,
|
|
264
|
+
action="init",
|
|
265
|
+
updated_settings_path=str(execution.settings_path),
|
|
266
|
+
project_venv=project_venv,
|
|
267
|
+
project_venv_created=project_venv_created,
|
|
268
|
+
)
|
|
269
|
+
)
|
|
270
|
+
else:
|
|
271
|
+
_print_report(
|
|
272
|
+
final_report,
|
|
273
|
+
action="init",
|
|
274
|
+
updated_settings_path=str(execution.settings_path),
|
|
275
|
+
project_venv=project_venv,
|
|
276
|
+
)
|
|
277
|
+
if execution.initialized_project:
|
|
278
|
+
print("project scaffold: created")
|
|
279
|
+
else:
|
|
280
|
+
print("project scaffold: reused")
|
|
281
|
+
if ns.no_sync:
|
|
282
|
+
print("sync: skipped")
|
|
283
|
+
elif execution.synced_targets:
|
|
284
|
+
print("synced:")
|
|
285
|
+
for item in execution.synced_targets:
|
|
286
|
+
print(f"- {item.kind}:{item.name} {item.path}")
|
|
287
|
+
else:
|
|
288
|
+
print("sync: no pyproject targets found")
|
|
289
|
+
return 0
|
|
290
|
+
except Exception as exc:
|
|
291
|
+
error = as_pz_error(exc, owner=_OWNER, action="init", stage="cli")
|
|
292
|
+
if json_mode:
|
|
293
|
+
print(_json_error(error))
|
|
294
|
+
else:
|
|
295
|
+
print(str(error), file=sys.stderr)
|
|
296
|
+
return 1
|
|
297
|
+
|
|
298
|
+
|
|
299
|
+
def install_main(argv: list[object] | None = None) -> int:
|
|
300
|
+
json_mode = json_output_requested(argv)
|
|
301
|
+
try:
|
|
302
|
+
normalized = normalize_cli_argv(
|
|
303
|
+
argv,
|
|
304
|
+
code="PZ_CLI_ARGV_INVALID",
|
|
305
|
+
stage="cli",
|
|
306
|
+
owner=_OWNER,
|
|
307
|
+
action="install",
|
|
308
|
+
)
|
|
309
|
+
parser = PzArgumentParser(
|
|
310
|
+
prog=f"{_program_name()} env install",
|
|
311
|
+
description="Prepare the project virtualenv and run the first dependency sync for discovered authoring roots.",
|
|
312
|
+
error_code="PZ_ENV_ARGUMENTS_INVALID",
|
|
313
|
+
error_stage="cli",
|
|
314
|
+
error_owner=_OWNER,
|
|
315
|
+
error_action="install",
|
|
316
|
+
)
|
|
317
|
+
add_cli_option(parser, "--json", action="store_true", dest="json_output")
|
|
318
|
+
add_cli_option(parser, "--project-dir", dest="project_dir")
|
|
319
|
+
add_cli_option(parser, "--group", action="append", default=[], dest="groups")
|
|
320
|
+
add_cli_option(parser, "--extra", action="append", default=[], dest="extras")
|
|
321
|
+
add_cli_option(parser, "--reinstall-package", action="append", default=[], dest="reinstall_packages")
|
|
322
|
+
add_cli_option(parser, "--project-only", action="store_true", dest="project_only")
|
|
323
|
+
ns = parser.parse_args(normalized)
|
|
324
|
+
project_dir = _resolve_existing_project_dir(ns.project_dir, action="install")
|
|
325
|
+
report = _collect_report(project_dir)
|
|
326
|
+
if _report_status(report) != "ok":
|
|
327
|
+
if ns.json_output:
|
|
328
|
+
print(_json_payload(report, action="install"))
|
|
329
|
+
else:
|
|
330
|
+
_print_report(report, action="install")
|
|
331
|
+
return 1
|
|
332
|
+
execution = execute_env_install(
|
|
333
|
+
project_dir,
|
|
334
|
+
action="install",
|
|
335
|
+
groups=tuple(str(item).strip() for item in ns.groups if str(item).strip()),
|
|
336
|
+
extras=tuple(str(item).strip() for item in ns.extras if str(item).strip()),
|
|
337
|
+
reinstall_packages=tuple(
|
|
338
|
+
str(item).strip() for item in ns.reinstall_packages if str(item).strip()
|
|
339
|
+
),
|
|
340
|
+
project_only=bool(ns.project_only),
|
|
341
|
+
sync_targets=lambda path, **kwargs: sync_project_targets(path, action="install", **kwargs),
|
|
342
|
+
)
|
|
343
|
+
project_venv = str(execution.project_venv.path)
|
|
344
|
+
if ns.json_output:
|
|
345
|
+
print(
|
|
346
|
+
_json_payload(
|
|
347
|
+
report,
|
|
348
|
+
action="install",
|
|
349
|
+
project_venv=project_venv,
|
|
350
|
+
project_venv_created=execution.project_venv.created,
|
|
351
|
+
)
|
|
352
|
+
)
|
|
353
|
+
else:
|
|
354
|
+
_print_report(report, action="install", project_venv=project_venv)
|
|
355
|
+
if execution.synced_targets:
|
|
356
|
+
print("synced:")
|
|
357
|
+
for item in execution.synced_targets:
|
|
358
|
+
print(f"- {item.kind}:{item.name} {item.path}")
|
|
359
|
+
else:
|
|
360
|
+
print("sync: no pyproject targets found")
|
|
361
|
+
return 0
|
|
362
|
+
except Exception as exc:
|
|
363
|
+
error = as_pz_error(exc, owner=_OWNER, action="install", stage="cli")
|
|
364
|
+
if json_mode:
|
|
365
|
+
print(_json_error(error))
|
|
366
|
+
else:
|
|
367
|
+
print(str(error), file=sys.stderr)
|
|
368
|
+
return 1
|
|
369
|
+
|
|
370
|
+
|
|
371
|
+
def sync_main(argv: list[object] | None = None) -> int:
|
|
372
|
+
json_mode = json_output_requested(argv)
|
|
373
|
+
try:
|
|
374
|
+
normalized = normalize_cli_argv(
|
|
375
|
+
argv,
|
|
376
|
+
code="PZ_CLI_ARGV_INVALID",
|
|
377
|
+
stage="cli",
|
|
378
|
+
owner=_OWNER,
|
|
379
|
+
action="sync",
|
|
380
|
+
)
|
|
381
|
+
parser = PzArgumentParser(
|
|
382
|
+
prog=f"{_program_name()} env sync",
|
|
383
|
+
description="Run dependency sync for the formal project root and discovered authoring roots.",
|
|
384
|
+
error_code="PZ_ENV_ARGUMENTS_INVALID",
|
|
385
|
+
error_stage="cli",
|
|
386
|
+
error_owner=_OWNER,
|
|
387
|
+
error_action="sync",
|
|
388
|
+
)
|
|
389
|
+
add_cli_option(parser, "--json", action="store_true", dest="json_output")
|
|
390
|
+
add_cli_option(parser, "--project-dir", dest="project_dir")
|
|
391
|
+
add_cli_option(parser, "--group", action="append", default=[], dest="groups")
|
|
392
|
+
add_cli_option(parser, "--extra", action="append", default=[], dest="extras")
|
|
393
|
+
add_cli_option(parser, "--reinstall-package", action="append", default=[], dest="reinstall_packages")
|
|
394
|
+
add_cli_option(parser, "--project-only", action="store_true", dest="project_only")
|
|
395
|
+
ns = parser.parse_args(normalized)
|
|
396
|
+
project_dir = _resolve_existing_project_dir(ns.project_dir, action="sync")
|
|
397
|
+
report = _collect_report(project_dir)
|
|
398
|
+
if _report_status(report) != "ok":
|
|
399
|
+
if ns.json_output:
|
|
400
|
+
print(_json_payload(report, action="sync"))
|
|
401
|
+
else:
|
|
402
|
+
_print_report(report, action="sync")
|
|
403
|
+
return 1
|
|
404
|
+
execution = execute_env_sync(
|
|
405
|
+
project_dir,
|
|
406
|
+
groups=tuple(str(item).strip() for item in ns.groups if str(item).strip()),
|
|
407
|
+
extras=tuple(str(item).strip() for item in ns.extras if str(item).strip()),
|
|
408
|
+
reinstall_packages=tuple(
|
|
409
|
+
str(item).strip() for item in ns.reinstall_packages if str(item).strip()
|
|
410
|
+
),
|
|
411
|
+
project_only=bool(ns.project_only),
|
|
412
|
+
sync_targets=lambda path, **kwargs: sync_project_targets(path, action="sync", **kwargs),
|
|
413
|
+
)
|
|
414
|
+
if ns.json_output:
|
|
415
|
+
print(_json_payload(report, action="sync"))
|
|
416
|
+
else:
|
|
417
|
+
_print_report(report, action="sync")
|
|
418
|
+
if execution.synced_targets:
|
|
419
|
+
print("synced:")
|
|
420
|
+
for item in execution.synced_targets:
|
|
421
|
+
print(f"- {item.kind}:{item.name} {item.path}")
|
|
422
|
+
else:
|
|
423
|
+
print("sync: no pyproject targets found")
|
|
424
|
+
return 0
|
|
425
|
+
except Exception as exc:
|
|
426
|
+
error = as_pz_error(exc, owner=_OWNER, action="sync", stage="cli")
|
|
427
|
+
if json_mode:
|
|
428
|
+
print(_json_error(error))
|
|
429
|
+
else:
|
|
430
|
+
print(str(error), file=sys.stderr)
|
|
431
|
+
return 1
|
|
432
|
+
|
|
433
|
+
|
|
434
|
+
def main(argv: list[object] | None = None) -> int:
|
|
435
|
+
args = list(argv or sys.argv[1:])
|
|
436
|
+
if not args or str(args[0]).strip().lower() in {"-h", "--help", "help"}:
|
|
437
|
+
sys.stdout.write(_usage())
|
|
438
|
+
return 0
|
|
439
|
+
|
|
440
|
+
command = str(args.pop(0)).strip().lower()
|
|
441
|
+
if command == "doctor":
|
|
442
|
+
return doctor_main(args)
|
|
443
|
+
if command == "install":
|
|
444
|
+
return install_main(args)
|
|
445
|
+
if command == "init":
|
|
446
|
+
return init_main(args)
|
|
447
|
+
if command == "sync":
|
|
448
|
+
return sync_main(args)
|
|
449
|
+
|
|
450
|
+
sys.stderr.write(f"Unknown command: env {command}\n\n{_usage()}")
|
|
451
|
+
return 2
|
|
452
|
+
|
|
453
|
+
|
|
454
|
+
__all__ = ["doctor_main", "init_main", "install_main", "main", "sync_main"]
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from dataclasses import dataclass
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
|
|
6
|
+
from pz_core.runtime.errors import PzError
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
@dataclass(frozen=True, slots=True)
|
|
10
|
+
class ScaffoldFile:
|
|
11
|
+
path: Path
|
|
12
|
+
content: str
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def ensure_writable_target(path: Path, *, action: str) -> None:
|
|
16
|
+
if path.exists():
|
|
17
|
+
raise PzError(
|
|
18
|
+
code="PZ_SCAFFOLD_TARGET_EXISTS",
|
|
19
|
+
message=f"Refusing to overwrite existing path: {path}",
|
|
20
|
+
stage="cli",
|
|
21
|
+
owner="pz_core.authoring",
|
|
22
|
+
action=action,
|
|
23
|
+
)
|
|
24
|
+
|
|
25
|
+
def validate_writable_targets(entries: list[ScaffoldFile], *, action: str) -> None:
|
|
26
|
+
seen: set[Path] = set()
|
|
27
|
+
for entry in entries:
|
|
28
|
+
if entry.path in seen:
|
|
29
|
+
raise PzError(
|
|
30
|
+
code="PZ_SCAFFOLD_TARGET_DUPLICATE",
|
|
31
|
+
message=f"duplicate scaffold target declared: {entry.path}",
|
|
32
|
+
stage="cli",
|
|
33
|
+
owner="pz_core.authoring",
|
|
34
|
+
action=action,
|
|
35
|
+
)
|
|
36
|
+
seen.add(entry.path)
|
|
37
|
+
ensure_writable_target(entry.path, action=action)
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def write_files(entries: list[ScaffoldFile], *, action: str) -> None:
|
|
41
|
+
validate_writable_targets(entries, action=action)
|
|
42
|
+
for entry in entries:
|
|
43
|
+
entry.path.parent.mkdir(parents=True, exist_ok=True)
|
|
44
|
+
entry.path.write_text(entry.content, encoding="utf-8")
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def append_or_create_file(path: Path, content: str) -> None:
|
|
48
|
+
path.parent.mkdir(parents=True, exist_ok=True)
|
|
49
|
+
if not path.exists():
|
|
50
|
+
path.write_text(content, encoding="utf-8")
|
|
51
|
+
return
|
|
52
|
+
existing = path.read_text(encoding="utf-8")
|
|
53
|
+
if content.strip() in existing:
|
|
54
|
+
return
|
|
55
|
+
suffix = content if existing.endswith("\n\n") or not existing else ("\n\n" + content.lstrip())
|
|
56
|
+
path.write_text(existing + suffix, encoding="utf-8")
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def render_upserted_managed_block(
|
|
60
|
+
existing: str | None,
|
|
61
|
+
*,
|
|
62
|
+
start_marker: str,
|
|
63
|
+
end_marker: str,
|
|
64
|
+
content: str,
|
|
65
|
+
) -> str:
|
|
66
|
+
block = f"{start_marker}\n{content.strip()}\n{end_marker}\n"
|
|
67
|
+
if existing is None:
|
|
68
|
+
return block
|
|
69
|
+
start_index = existing.find(start_marker)
|
|
70
|
+
end_index = existing.find(end_marker)
|
|
71
|
+
if start_index >= 0 and end_index >= start_index:
|
|
72
|
+
replaced = existing[:start_index].rstrip()
|
|
73
|
+
suffix = existing[end_index + len(end_marker) :].lstrip("\n")
|
|
74
|
+
updated = block if not replaced else f"{replaced}\n\n{block}"
|
|
75
|
+
if suffix:
|
|
76
|
+
updated = f"{updated.rstrip()}\n\n{suffix}"
|
|
77
|
+
return updated
|
|
78
|
+
suffix = block if existing.endswith("\n\n") or not existing else ("\n\n" + block.lstrip())
|
|
79
|
+
return existing + suffix
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
def upsert_managed_block(
|
|
83
|
+
path: Path,
|
|
84
|
+
*,
|
|
85
|
+
start_marker: str,
|
|
86
|
+
end_marker: str,
|
|
87
|
+
content: str,
|
|
88
|
+
) -> None:
|
|
89
|
+
path.parent.mkdir(parents=True, exist_ok=True)
|
|
90
|
+
existing = path.read_text(encoding="utf-8") if path.exists() else None
|
|
91
|
+
path.write_text(
|
|
92
|
+
render_upserted_managed_block(
|
|
93
|
+
existing,
|
|
94
|
+
start_marker=start_marker,
|
|
95
|
+
end_marker=end_marker,
|
|
96
|
+
content=content,
|
|
97
|
+
),
|
|
98
|
+
encoding="utf-8",
|
|
99
|
+
)
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
__all__ = [
|
|
103
|
+
"ScaffoldFile",
|
|
104
|
+
"append_or_create_file",
|
|
105
|
+
"render_upserted_managed_block",
|
|
106
|
+
"upsert_managed_block",
|
|
107
|
+
"validate_writable_targets",
|
|
108
|
+
"write_files",
|
|
109
|
+
]
|