1panel-toolkit 0.3.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.
Files changed (47) hide show
  1. 1panel_toolkit-0.3.0.dist-info/METADATA +407 -0
  2. 1panel_toolkit-0.3.0.dist-info/RECORD +47 -0
  3. 1panel_toolkit-0.3.0.dist-info/WHEEL +4 -0
  4. 1panel_toolkit-0.3.0.dist-info/entry_points.txt +2 -0
  5. 1panel_toolkit-0.3.0.dist-info/licenses/LICENSE +21 -0
  6. p1toolkit/__init__.py +3 -0
  7. p1toolkit/checks/__init__.py +21 -0
  8. p1toolkit/checks/compose.py +188 -0
  9. p1toolkit/checks/forms.py +129 -0
  10. p1toolkit/checks/hygiene.py +73 -0
  11. p1toolkit/checks/i18n.py +140 -0
  12. p1toolkit/checks/lessons.py +111 -0
  13. p1toolkit/checks/structure.py +140 -0
  14. p1toolkit/checks/substance.py +55 -0
  15. p1toolkit/cli.py +890 -0
  16. p1toolkit/config.py +114 -0
  17. p1toolkit/dependencies.py +218 -0
  18. p1toolkit/deploy.py +302 -0
  19. p1toolkit/depth.py +414 -0
  20. p1toolkit/errors.py +18 -0
  21. p1toolkit/evidence.py +523 -0
  22. p1toolkit/fix.py +394 -0
  23. p1toolkit/gen.py +728 -0
  24. p1toolkit/lifecycle.py +143 -0
  25. p1toolkit/loader.py +110 -0
  26. p1toolkit/logo.py +174 -0
  27. p1toolkit/model.py +71 -0
  28. p1toolkit/net.py +81 -0
  29. p1toolkit/panel.py +154 -0
  30. p1toolkit/patterns/__init__.py +250 -0
  31. p1toolkit/patterns/catalog.py +271 -0
  32. p1toolkit/patterns/data/patterns.json +724 -0
  33. p1toolkit/patterns/extract.py +402 -0
  34. p1toolkit/remote.py +554 -0
  35. p1toolkit/report.py +96 -0
  36. p1toolkit/resolve/__init__.py +554 -0
  37. p1toolkit/resolve/analyze.py +329 -0
  38. p1toolkit/resolve/sources.py +306 -0
  39. p1toolkit/rules/__init__.py +99 -0
  40. p1toolkit/rules/data/decisions.yaml +132 -0
  41. p1toolkit/rules/data/dependencies.yaml +113 -0
  42. p1toolkit/rules/data/envkeys.yaml +19 -0
  43. p1toolkit/rules/data/form-design.yaml +59 -0
  44. p1toolkit/rules/data/i18n.yaml +354 -0
  45. p1toolkit/rules/data/lessons.yaml +84 -0
  46. p1toolkit/rules/data/store.yaml +171 -0
  47. p1toolkit/selftest.py +211 -0
@@ -0,0 +1,99 @@
1
+ """Rule data.
2
+
3
+ Every rule that can be expressed as data lives in ``rules/data/*.yaml`` so a
4
+ store-policy change is a data edit, not a code change. Prose explanations stay
5
+ in ``references/``; only machine-checkable facts belong here.
6
+ """
7
+
8
+ from __future__ import annotations
9
+
10
+ import functools
11
+ from pathlib import Path
12
+ from typing import Any
13
+
14
+ import yaml
15
+
16
+ DATA_DIR = Path(__file__).parent / "data"
17
+
18
+
19
+ @functools.lru_cache(maxsize=None)
20
+ def load(name: str) -> dict[str, Any]:
21
+ """Load ``rules/data/<name>.yaml`` (cached)."""
22
+ path = DATA_DIR / f"{name}.yaml"
23
+ if not path.exists():
24
+ raise FileNotFoundError(f"missing rule data: {path}")
25
+ with path.open(encoding="utf-8") as handle:
26
+ return yaml.safe_load(handle) or {}
27
+
28
+
29
+ def store() -> dict[str, Any]:
30
+ return load("store")
31
+
32
+
33
+ def i18n() -> dict[str, Any]:
34
+ return load("i18n")
35
+
36
+
37
+ def envkeys() -> dict[str, Any]:
38
+ return load("envkeys")
39
+
40
+
41
+ def lessons() -> list[dict[str, Any]]:
42
+ return list(load("lessons").get("lessons") or [])
43
+
44
+
45
+ def decisions() -> list[dict[str, Any]]:
46
+ return list(load("decisions").get("decisions") or [])
47
+
48
+
49
+ def blocking_decisions() -> set[str]:
50
+ """Decisions whose missing evidence stops the pipeline (resolve and gen).
51
+
52
+ The set lives in the data file so the generator, the resolver and the docs
53
+ cannot drift apart on which decisions are allowed to be guessed.
54
+ """
55
+ return {str(item["id"]) for item in decisions() if item.get("blocking")}
56
+
57
+
58
+ def decision(decision_id: str) -> dict[str, Any]:
59
+ for item in decisions():
60
+ if item.get("id") == decision_id:
61
+ return item
62
+ return {}
63
+
64
+
65
+ def dependency_kinds() -> list[dict[str, Any]]:
66
+ return list(load("dependencies").get("kinds") or [])
67
+
68
+
69
+ def dependency_kind(key: str) -> dict[str, Any]:
70
+ for item in dependency_kinds():
71
+ if item.get("key") == key:
72
+ return item
73
+ return {}
74
+
75
+
76
+ def dependency_family(name: str) -> dict[str, Any]:
77
+ families = load("dependencies").get("families") or {}
78
+ value = families.get(name) or {}
79
+ return value if isinstance(value, dict) else {}
80
+
81
+
82
+ def dependency_styles() -> dict[str, Any]:
83
+ return dict(load("dependencies").get("styles") or {})
84
+
85
+
86
+ def required_languages() -> list[str]:
87
+ return list(i18n().get("required_languages") or [])
88
+
89
+
90
+ def all_languages() -> list[str]:
91
+ return list(i18n().get("languages") or [])
92
+
93
+
94
+ def allowed_tags() -> set[str]:
95
+ return set(store().get("allowed_tags") or [])
96
+
97
+
98
+ def implicit_envkeys() -> set[str]:
99
+ return set(envkeys().get("implicit") or [])
@@ -0,0 +1,132 @@
1
+ # What a generator must decide per application, ranked by measured diversity.
2
+ #
3
+ # Numbers come from scanning 882 official store apps / 1617 versions
4
+ # (`p1 depth --corpus <apps>`). A dimension with a handful of distinct values
5
+ # can be templated; a dimension with hundreds of values is where a lazy
6
+ # generator produces a reskinned package instead of an adapted one.
7
+ #
8
+ # `blocking: true` means "no evidence, no build": `p1 resolve` refuses to answer
9
+ # and `p1 gen` refuses to generate (see src/p1toolkit/evidence.py). Omitted
10
+ # means the decision may fall back to `if_unknown`, but never silently — the
11
+ # fallback is printed and recorded in the package's decision-audit.json.
12
+
13
+ measurement_date: "2026-09-19"
14
+ corpus_apps: 882
15
+
16
+ decisions:
17
+ - id: D01
18
+ question: 应用自己的环境变量叫什么?
19
+ evidence: 上游 README / docker-compose.yml / .env.example
20
+ distinct_values: 3197
21
+ per_app: 6.0
22
+ common: ["PGID", "PUID", "PASSWORD"]
23
+ if_unknown: 停止,不要发明变量名
24
+ risk: 变量名猜错时容器能起来但不生效,最难排查
25
+ templatable: false
26
+
27
+ - id: D02
28
+ question: 表单要收集哪些变量(envKey)?
29
+ evidence: 上游必需配置项 + 1Panel 面板约定变量
30
+ distinct_values: 2215
31
+ per_app: 6.5
32
+ common: ["PANEL_APP_PORT_HTTP", "TIME_ZONE", "CONFIG_PATH"]
33
+ if_unknown: 先只暴露端口,其余留空并在 README 说明
34
+ risk: 少暴露必需项会导致装完不可用;多暴露安全项会泄露密钥
35
+ templatable: false
36
+
37
+ - id: D03
38
+ question: 数据要挂到容器内哪个路径?
39
+ evidence: 上游 Dockerfile VOLUME / 官方 compose
40
+ distinct_values: 642
41
+ per_app: 1.6
42
+ common: ["/config", "/data", "/app/data"]
43
+ if_unknown: 停止,不要猜挂载点
44
+ risk: 挂错路径时数据不持久,升级即丢
45
+ templatable: false
46
+ blocking: true
47
+
48
+ - id: D04
49
+ question: 持久化数据放在宿主机哪里?
50
+ evidence: 上游 compose / 应用文档
51
+ distinct_values: 570
52
+ per_app: 1.6
53
+ common: ["${CONFIG_PATH}", "${DATA_PATH}", "${APP_DATA_DIR}"]
54
+ if_unknown: "./data/<用途>"
55
+ risk: 路径变了会导致升级后找不到旧数据
56
+ templatable: false
57
+
58
+ - id: D05
59
+ question: 容器内部监听哪个端口?
60
+ evidence: Dockerfile EXPOSE / 官方 compose / 官方文档
61
+ distinct_values: 359
62
+ per_app: 1.3
63
+ common: ["3000", "80", "3001"]
64
+ if_unknown: 停止;抄模板默认端口是已知翻车点(openviking 1933 被写成 8080)
65
+ risk: 容器 running 但端口不通
66
+ templatable: false
67
+ blocking: true
68
+
69
+ - id: D06
70
+ question: 镜像用哪个仓库、哪个标签?
71
+ evidence: 上游 README / 官方镜像页
72
+ distinct_values: 19 # 仓库
73
+ per_app: 1.0
74
+ common: ["docker.io", "ghcr.io"]
75
+ if_unknown: 优先官方镜像;第三方镜像必须用户明确接受并记录风险
76
+ risk: 第三方镜像供应链风险;latest 会随上游变化
77
+ templatable: false
78
+ blocking: true
79
+ note: 标签风格有 196 种取值,其中 latest×722;固定版本更可控,latest 更省维护
80
+
81
+ - id: D07
82
+ question: 上游要求哪些额外运行时字段?
83
+ evidence: 官方 compose / 安装文档
84
+ distinct_values: 35
85
+ per_app: 0.8
86
+ common: ["security_opt", "cap_drop", "user"]
87
+ if_unknown: 先不加,但要在 README 标注未验证
88
+ risk: 少了 privileged / cap_add / devices 会让核心功能不可用;多了会扩大攻击面
89
+ templatable: false
90
+
91
+ - id: D08
92
+ question: README 需要哪些章节?
93
+ evidence: 应用实际的配置项与使用方式
94
+ distinct_values: 419
95
+ per_app: 7.0
96
+ common: ["参考资料", "使用说明", "部署说明"]
97
+ if_unknown: 产品介绍 / 主要功能 / 访问说明 / 安装参数 / 数据持久化
98
+ risk: README 抄模板会让用户找不到本应用独有的必做步骤
99
+ templatable: false
100
+
101
+ - id: D09
102
+ question: 需要哪些生命周期脚本?
103
+ evidence: 应用是否首次启动就必须有配置文件、是否需要迁移
104
+ distinct_values: 14
105
+ per_app: 0.5
106
+ common: ["init.sh + uninstall.sh + upgrade.sh"]
107
+ if_unknown: 无特殊需求就不生成 scripts/
108
+ risk: 缺失 init.sh 是「静态校验通过、容器一起来就退出」的第一大原因(L001)
109
+ templatable: false
110
+
111
+ - id: D10
112
+ question: 依赖怎么接?面板托管还是自带 sidecar?
113
+ evidence: 上游是否支持外部数据库/缓存 + 面板上是否有对应应用
114
+ distinct_values: 2
115
+ common: ["面板托管(PANEL_DB_* / REDIS_*)", "自带 sidecar"]
116
+ if_unknown: 单服务优先,其次面板托管,最后才自带 sidecar
117
+ risk: 自带 sidecar 会让用户失去面板统一备份与升级;面板托管错选 key 会导致装不上
118
+ templatable: false
119
+ note: "两步式(type: apps + child.service)41 个应用 > 单步(type: service)23 个"
120
+
121
+ # 以下维度取值很少,可以直接模板化
122
+ templatable:
123
+ - dimension: 重启策略
124
+ top: "always (719/882)"
125
+ - dimension: 表单字段类型
126
+ top: "number / text / password / select"
127
+ - dimension: 表单校验规则
128
+ top: "paramPort (849) / paramComplexity (332) / paramCommon (108)"
129
+ - dimension: 网络接入
130
+ top: "外部网络 815/882;单服务 794/882"
131
+ - dimension: 脚本组合
132
+ top: "init+upgrade+uninstall 421/882"
@@ -0,0 +1,113 @@
1
+ # 面板托管的依赖:安装表单里让用户指向一个 1Panel 已经跑起来的数据库/缓存。
2
+ # 这是 D10 的落地形态,数字来自官方语料实测(882 应用 / 1617 版本):
3
+ # * 106 个版本、58 个应用用了依赖选择器
4
+ # * 两步式 type: apps + child.type: service 72 个版本(主流)
5
+ # * 一步式 type: service 53 个版本
6
+ # 选择器本身只提供"引擎类型"和"实例主机";其余变量由包自己声明
7
+ # (PANEL_DB_USER 92、PANEL_DB_USER_PASSWORD 92、PANEL_DB_NAME 90、
8
+ # PANEL_DB_PORT 49 个版本,而且几乎都是 required: true)。
9
+ # 所以生成器只为 spec 的 env 映射里真正引用到的变量生成字段,不多给一个输入框。
10
+
11
+ styles:
12
+ apps:
13
+ field_type: apps
14
+ note: 两步式:先选引擎,再选实例(官方 72/125)
15
+ service:
16
+ field_type: service
17
+ note: 一步式:直接选一个已安装的实例(官方 53/125)
18
+
19
+ # 同一个 family 共用一套面板变量名:PANEL_DB_* 被 mysql / mariadb / postgresql
20
+ # 共用(官方就是这么写的),redis 用自己的 REDIS_* / PANEL_REDIS_*。
21
+ families:
22
+ db:
23
+ selector_envkey: PANEL_DB_TYPE
24
+ host_envkey: PANEL_DB_HOST
25
+ selector_label_en: Database Service
26
+ selector_label_zh: 数据库服务
27
+ variables:
28
+ PANEL_DB_PORT:
29
+ type: number
30
+ rule: paramPort
31
+ default: kind_port
32
+ label_en: Database Port
33
+ label_zh: 数据库端口
34
+ PANEL_DB_NAME:
35
+ type: text
36
+ default: app_key
37
+ label_en: Database Name
38
+ label_zh: 数据库名
39
+ PANEL_DB_USER:
40
+ type: text
41
+ default: app_key
42
+ label_en: Database User
43
+ label_zh: 数据库用户
44
+ PANEL_DB_USER_PASSWORD:
45
+ type: password
46
+ label_en: Database Password
47
+ label_zh: 数据库密码
48
+ PANEL_DB_ROOT_USER:
49
+ type: text
50
+ label_en: Database User
51
+ label_zh: 数据库用户
52
+ PANEL_DB_ROOT_PASSWORD:
53
+ type: password
54
+ label_en: Database Password
55
+ label_zh: 数据库密码
56
+ PANEL_DB_PREFIX:
57
+ type: text
58
+ default: app_key
59
+ label_en: Database Prefix
60
+ label_zh: 表前缀
61
+ redis:
62
+ host_envkey: REDIS_HOST
63
+ selector_label_en: Redis Service
64
+ selector_label_zh: Redis 服务
65
+ variables:
66
+ REDIS_PORT:
67
+ type: number
68
+ rule: paramPort
69
+ default: 6379
70
+ label_en: Redis Port
71
+ label_zh: Redis 端口
72
+ REDIS_DB:
73
+ type: number
74
+ default: 0
75
+ label_en: Redis Database
76
+ label_zh: Redis 库
77
+ REDIS_USERNAME:
78
+ type: text
79
+ label_en: Redis Username
80
+ label_zh: Redis 用户名
81
+ REDIS_PASSWORD:
82
+ type: password
83
+ label_en: Redis Password
84
+ label_zh: Redis 密码
85
+ REDIS_PASS:
86
+ type: password
87
+ label_en: Redis Password
88
+ label_zh: Redis 密码
89
+ PANEL_REDIS_ROOT_PASSWORD:
90
+ type: password
91
+ label_en: Redis Password
92
+ label_zh: Redis 密码
93
+
94
+ # `default` 里的两个记号由生成器展开:
95
+ # app_key -> spec 的 key(官方 90/92 个版本就是这么填的)
96
+ # kind_port -> 所选引擎的 default_port
97
+ kinds:
98
+ - key: postgresql
99
+ family: db
100
+ label: PostgreSQL
101
+ default_port: 5432
102
+ - key: mysql
103
+ family: db
104
+ label: MySQL
105
+ default_port: 3306
106
+ - key: mariadb
107
+ family: db
108
+ label: MariaDB
109
+ default_port: 3306
110
+ - key: redis
111
+ family: redis
112
+ label: Redis
113
+ default_port: 6379
@@ -0,0 +1,19 @@
1
+ # Variables that 1Panel or the runtime supplies, so a package does not have to
2
+ # declare them in `formFields`. Everything else referenced in docker-compose.yml
3
+ # must close against a declared envKey (or a formField default).
4
+ #
5
+ # Keep this list short and evidence-backed. Anything a user is expected to fill
6
+ # in belongs in the install form instead.
7
+ implicit:
8
+ # 1Panel injects the container name during install.
9
+ - CONTAINER_NAME
10
+ # Injected by the panel-managed DB/Redis selector when the field is a
11
+ # `type: apps` / `type: service` dependency picker.
12
+ - PANEL_DB_HOST
13
+ # Derived from the selected panel database service, not user input.
14
+ - PANEL_DB_PORT
15
+ # Provided by the panel for linked resources.
16
+ - PANEL_REDIS_ROOT_PASSWORD
17
+ - REDIS_HOST
18
+ - REDIS_PORT
19
+
@@ -0,0 +1,59 @@
1
+ # Install-form design budget.
2
+ #
3
+ # Measured over 1617 official versions (2026-09-20):
4
+ # fields per version: median 5, mean 6.6, p90 11, max 120
5
+ # share of fields marked required: 88%
6
+ # versions with >=6 fields sharing one env-key prefix: 27
7
+ # versions with a required field that has an empty default: 288
8
+ #
9
+ # The failure mode this prevents: exposing every upstream environment variable
10
+ # as a form field, so the user faces thirty boxes where six are required and
11
+ # twenty-four are not. The reference offender is this project's own hindsight
12
+ # package (30 fields, 6 required / 24 optional) against an official median of 5.
13
+
14
+ measurement_date: "2026-09-20"
15
+ corpus_versions: 1617
16
+
17
+ budget:
18
+ fields_median_official: 5
19
+ fields_p90_official: 11
20
+ # Above p90 the form stops being a decision list and becomes a config dump.
21
+ fields_warn: 11
22
+ fields_fail: 20
23
+ # Official forms are overwhelmingly required; a low ratio means the author
24
+ # exposed optional knobs nobody asked for.
25
+ min_required_ratio: 0.6
26
+ # A cluster this large is a provider matrix that should collapse to one
27
+ # select plus defaults, not one box per variant.
28
+ max_fields_per_prefix: 5
29
+ max_prefix_official: 18
30
+
31
+ # envKey fragments that mean "this is a secret the user must supply".
32
+ secret_fragments:
33
+ - PASSWORD
34
+ - PASSWD
35
+ - SECRET
36
+ - TOKEN
37
+ - API_KEY
38
+ - APIKEY
39
+ - ACCESS_KEY
40
+ - PRIVATE_KEY
41
+ - CREDENTIAL
42
+
43
+ # Field kinds that are always worth exposing, because the user decides them.
44
+ always_expose:
45
+ - "PANEL_APP_PORT_*"
46
+ - TZ
47
+ - "*_URL / *_DOMAIN when the app publishes links"
48
+
49
+ # Everything else follows this rule (enforced by the generator, checked here):
50
+ # give the compose a working default via ${VAR:-default} and do NOT expose it.
51
+ rule: |
52
+ 一个字段只有满足下列之一才出现在表单里:
53
+ 1. 用户必须决定(端口、对外域名/URL)
54
+ 2. 用户必须提供(密钥类,没有默认值)
55
+ 其余所有上游变量都写进 compose 的默认值(${VAR:-default}),
56
+ 需要时在 README 的「高级配置」里说明怎么改。
57
+
58
+ 必填语义必须一致:必填 = 不给就用不了。可选字段只用于真正可选的功能开关,
59
+ 而且必须有可用默认值。