pubrules 0.48.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 (79) hide show
  1. pubrules/__init__.py +14 -0
  2. pubrules/audit.py +116 -0
  3. pubrules/audit_draft.py +295 -0
  4. pubrules/audit_prepare.py +1128 -0
  5. pubrules/cache.py +319 -0
  6. pubrules/cbor.py +45 -0
  7. pubrules/ci.py +910 -0
  8. pubrules/cli.py +1069 -0
  9. pubrules/conform.py +295 -0
  10. pubrules/doc_coverage.py +235 -0
  11. pubrules/freshness.py +75 -0
  12. pubrules/gherkin.py +348 -0
  13. pubrules/hooks.py +59 -0
  14. pubrules/hosting.py +372 -0
  15. pubrules/ignores.py +86 -0
  16. pubrules/new.py +242 -0
  17. pubrules/nightly.py +1002 -0
  18. pubrules/paths.py +32 -0
  19. pubrules/protect.py +596 -0
  20. pubrules/providers.py +129 -0
  21. pubrules/refs.py +213 -0
  22. pubrules/release-commit +1 -0
  23. pubrules/releases.py +107 -0
  24. pubrules/repos.py +67 -0
  25. pubrules/ruleset.json +43 -0
  26. pubrules/secrets_config.py +165 -0
  27. pubrules/security.py +134 -0
  28. pubrules/service_needs.py +467 -0
  29. pubrules/standard.json +635 -0
  30. pubrules/standard.py +266 -0
  31. pubrules/supply_chain.py +188 -0
  32. pubrules/tag-ruleset.json +14 -0
  33. pubrules/templates/common/AGENTS.md +32 -0
  34. pubrules/templates/common/pubrules +26 -0
  35. pubrules/templates/common/tests/features/repository.feature +11 -0
  36. pubrules/templates/common/tests/install-lock +65 -0
  37. pubrules/templates/common/tests/pytest.ini +4 -0
  38. pubrules/templates/common/tests/requirements-pubrules.txt +17 -0
  39. pubrules/templates/common/tests/requirements.txt +3 -0
  40. pubrules/templates/common/tests/steps/test_repository.py +14 -0
  41. pubrules/templates/deploy/pubdeploy +28 -0
  42. pubrules/templates/new-rust/CHANGELOG.md +3 -0
  43. pubrules/templates/new-rust/Cargo.toml +46 -0
  44. pubrules/templates/new-rust/LICENSE +202 -0
  45. pubrules/templates/new-rust/Makefile +18 -0
  46. pubrules/templates/new-rust/README.md +34 -0
  47. pubrules/templates/new-rust/SECURITY.md +26 -0
  48. pubrules/templates/new-rust/corpus/corpus.json +11 -0
  49. pubrules/templates/new-rust/deny.toml +32 -0
  50. pubrules/templates/new-rust/fuzz/Cargo.toml +23 -0
  51. pubrules/templates/new-rust/fuzz/fuzz_targets/greet.rs +8 -0
  52. pubrules/templates/new-rust/fuzz/gitignore +4 -0
  53. pubrules/templates/new-rust/fuzz/regressions/README.md +4 -0
  54. pubrules/templates/new-rust/gitignore +10 -0
  55. pubrules/templates/new-rust/src/lib.rs +91 -0
  56. pubrules/templates/new-rust/src/main.rs +19 -0
  57. pubrules/templates/new-rust/supply-chain/audits.toml +4 -0
  58. pubrules/templates/new-rust/supply-chain/config.toml +23 -0
  59. pubrules/templates/new-rust/supply-chain/imports.lock +2 -0
  60. pubrules/templates/new-rust/tests/conftest.py +9 -0
  61. pubrules/templates/new-rust/tests/features/cli.feature +14 -0
  62. pubrules/templates/new-rust/tests/steps/test_cli.py +15 -0
  63. pubrules/templates/new-rust/tests/vectors.rs +30 -0
  64. pubrules/templates/new-rust/tools/vectors/generate.py +24 -0
  65. pubrules/templates/python/Makefile +5 -0
  66. pubrules/templates/python/pubrules-python.mk +47 -0
  67. pubrules/templates/rust/Makefile +9 -0
  68. pubrules/templates/rust/pubrules.mk +138 -0
  69. pubrules/templates/rust/rust-toolchain.toml +8 -0
  70. pubrules/templates/service/pubsec +27 -0
  71. pubrules/templates/service/with-secrets +20 -0
  72. pubrules/templates/service/with-secrets.json +8 -0
  73. pubrules/variables.py +45 -0
  74. pubrules-0.48.0.dist-info/METADATA +1241 -0
  75. pubrules-0.48.0.dist-info/RECORD +79 -0
  76. pubrules-0.48.0.dist-info/WHEEL +5 -0
  77. pubrules-0.48.0.dist-info/entry_points.txt +2 -0
  78. pubrules-0.48.0.dist-info/licenses/LICENSE +202 -0
  79. pubrules-0.48.0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,30 @@
1
+ //! The test vectors in `testdata/`, run against this crate. Their expected
2
+ //! values come from `tools/vectors/generate.py`, not from this crate.
3
+ #![allow(clippy::unwrap_used, clippy::indexing_slicing, clippy::panic)]
4
+
5
+ /// The `"input"` and `"output"` strings of each case. The generator writes
6
+ /// one case per line and no escapes, so this needs no JSON library.
7
+ fn cases() -> Vec<(String, String)> {
8
+ let text = include_str!("../testdata/greetings.json");
9
+ text.lines()
10
+ .filter(|l| l.contains("\"input\""))
11
+ .map(|l| {
12
+ let field = |key: &str| {
13
+ let start = l.find(&format!("\"{key}\": \"")).unwrap() + key.len() + 5;
14
+ let end = start + l[start..].find('"').unwrap();
15
+ l[start..end].to_owned()
16
+ };
17
+ (field("input"), field("output"))
18
+ })
19
+ .collect()
20
+ }
21
+
22
+ // covers: greet
23
+ #[test]
24
+ fn greetings_match_the_vectors() {
25
+ let cases = cases();
26
+ assert!(!cases.is_empty());
27
+ for (input, output) in cases {
28
+ assert_eq!({crate}::greet(&input), output, "{input}");
29
+ }
30
+ }
@@ -0,0 +1,24 @@
1
+ #!/usr/bin/env python3
2
+ """Generate testdata/ from a source independent of the crate.
3
+
4
+ Replace this with the real independent source for the crate's behaviour:
5
+ a specification, another implementation, a published test suite. Each
6
+ vector file names its source. Run from the repository root.
7
+ """
8
+
9
+ import json
10
+ from pathlib import Path
11
+
12
+ ROOT = Path(__file__).resolve().parents[2]
13
+ CASES = [("world", "hello, world"), ("publet", "hello, publet")]
14
+
15
+ lines = ['{', ' "description": "Greetings.",',
16
+ ' "source": "the greeting format, written out by hand",', ' "cases": [']
17
+ lines += [f' {{"input": "{i}", "output": "{o}"}}' + ("," if n < len(CASES) - 1 else "")
18
+ for n, (i, o) in enumerate(CASES)]
19
+ lines += [' ]', '}']
20
+ text = "\n".join(lines) + "\n"
21
+ json.loads(text)
22
+ (ROOT / "testdata").mkdir(exist_ok=True)
23
+ (ROOT / "testdata" / "greetings.json").write_text(text)
24
+ print("wrote testdata/greetings.json")
@@ -0,0 +1,5 @@
1
+ include pubrules-python.mk
2
+
3
+ .PHONY: check
4
+
5
+ check: sync-check functional ## Everything CI runs
@@ -0,0 +1,47 @@
1
+ # Managed by pubrules {version}: `pubrules sync` rewrites this file, and
2
+ # `pubrules sync --check` fails when it differs. Include it from the Makefile,
3
+ # and set the variables below there, before the include; targets of your own
4
+ # go there too. It is the same in every Python package, so a rule set here
5
+ # (the suite on every core, its coverage in coverage/coverage.xml) holds in each.
6
+ SHELL := /bin/bash
7
+ .SHELLFLAGS := -eu -o pipefail -c
8
+ .DEFAULT_GOAL := help
9
+ export PATH := $(CURDIR)/.venv/bin:$(PATH)
10
+
11
+ # Arguments to pytest: the suite runs on every core (pytest-xdist, which
12
+ # tests/requirements-pubrules.txt pins); PYTEST_ARGS = runs it on one.
13
+ PYTEST_ARGS ?= -n auto
14
+ # Variables the suite needs, as NAME=value words, such as
15
+ # PYTHONPATH=$(CURDIR)/src for a package that is not installed.
16
+ FUNCTIONAL_ENV ?=
17
+ # What venv installs editable, with no dependencies: the checkout, or nothing.
18
+ EDITABLE ?= .
19
+
20
+ .PHONY: help venv functional lock sync-check wheel clean
21
+
22
+ help: ## Available targets
23
+ @grep -hE '^[a-z-]+:.*?## ' $(MAKEFILE_LIST) | awk -F':.*?## ' '{printf " %-12s %s\n", $$1, $$2}'
24
+
25
+ venv: ## Hash-locked environment, with this checkout installed editable
26
+ python3 -m venv .venv
27
+ tests/install-lock .venv/bin/pip
28
+ $(if $(EDITABLE),.venv/bin/pip install --quiet --no-deps -e $(EDITABLE))
29
+
30
+ functional: ## The Gherkin suite on every core, with its coverage in coverage/coverage.xml
31
+ rm -rf coverage && mkdir coverage
32
+ cd tests && $(FUNCTIONAL_ENV) COVERAGE_RCFILE=$(CURDIR)/pyproject.toml COVERAGE_FILE=$(CURDIR)/coverage/.coverage \
33
+ ../.venv/bin/coverage run -m pytest -q $(PYTEST_ARGS)
34
+ COVERAGE_FILE=coverage/.coverage .venv/bin/coverage combine -q
35
+ COVERAGE_FILE=coverage/.coverage .venv/bin/coverage xml -q
36
+
37
+ lock: ## Pin tests/requirements.txt, with hashes, in tests/requirements.lock
38
+ ./pubrules lock
39
+
40
+ sync-check: ## Fail if pubrules' managed files differ from the pinned version's
41
+ ./pubrules sync --check
42
+
43
+ wheel: ## Build the wheel a release carries
44
+ .venv/bin/pip wheel --quiet --no-deps . -w dist
45
+
46
+ clean: ## Remove build artifacts
47
+ rm -rf build dist coverage src/*.egg-info .pytest_cache tests/.pytest_cache
@@ -0,0 +1,9 @@
1
+ include pubrules.mk
2
+
3
+ # Binaries under test, by <NAME>_BIN_DIR.
4
+ export {bin_var} ?= $(CURDIR)/target/debug
5
+
6
+ .DEFAULT_GOAL := help
7
+ .PHONY: check
8
+
9
+ check: sync-check fmt-check lint test doc functional ## Everything CI runs
@@ -0,0 +1,138 @@
1
+ # Managed by pubrules {version}: `pubrules sync` rewrites this file, and
2
+ # `pubrules sync --check` fails when it differs. Include it from the Makefile,
3
+ # and override the variables below there; targets of your own go there too.
4
+ SHELL := /bin/bash
5
+ .SHELLFLAGS := -eu -o pipefail -c
6
+ export PATH := $(HOME)/.cargo/bin:$(CURDIR)/.venv/bin:$(PATH)
7
+
8
+ CARGO ?= cargo
9
+ CARGO_SCOPE ?= --workspace
10
+ # The Gherkin suite runs on every core (pytest-xdist, which tests/requirements.lock
11
+ # pins); set PYTEST_ARGS = (empty) in the Makefile to run it on one.
12
+ PYTEST_ARGS ?= -n auto
13
+ # The crates published to crates.io. Each gets a SUPPLY-CHAIN.md, each
14
+ # library among them a TESTING.md, and each is packaged by publish-check and
15
+ # built by msrv.
16
+ SUPPLY_CHAIN_CRATES ?=
17
+ PUBLISHED_CRATES ?= $(SUPPLY_CHAIN_CRATES)
18
+ # The generator of testdata/, and the directories it writes.
19
+ VECTORS_GENERATE ?= ./tools/vectors/generate.py
20
+ VECTORS_DIRS ?= $(wildcard testdata crates/*/testdata)
21
+ # fuzz/fuzz_targets/*.rs, and how long each runs in fuzz-smoke.
22
+ FUZZ_TARGETS ?= $(notdir $(basename $(wildcard fuzz/fuzz_targets/*.rs)))
23
+ FUZZ_SECONDS ?= 60
24
+ # The oldest Rust promised: CI passes the lowest rust-version any package
25
+ # states.
26
+ MSRV ?= $(shell sed -n 's/^rust-version = "\(.*\)"/\1/p' Cargo.toml | head -1)
27
+
28
+ .PHONY: help venv lock sync-check fmt fmt-check lint test doc build functional coverage supply-chain supply-chain-check \
29
+ doc-coverage doc-coverage-check vectors vectors-check publish-check msrv fuzz-smoke deny vet required
30
+
31
+ help: ## Show available targets
32
+ @grep -hE '^[a-z-]+:.*?## ' $(MAKEFILE_LIST) \
33
+ | awk -F':.*?## ' '{printf " %-14s %s\n", $$1, $$2}'
34
+
35
+ # The lock .venv was last built from. Each target that runs a tool from
36
+ # .venv depends on it, so a moved pin rebuilds .venv before the target runs
37
+ # an older pubrules than the repository pins.
38
+ VENV := .venv/requirements.lock
39
+
40
+ venv:: ## Python environment for the functional suite, hash-locked
41
+ python3 -m venv .venv
42
+ @# Tried three times, then from pubrules.json's wheel mirror: a release download can time out.
43
+ tests/install-lock .venv/bin/pip
44
+ cp tests/requirements.lock $(VENV)
45
+
46
+ $(VENV): $(wildcard tests/requirements.lock)
47
+ $(MAKE) --no-print-directory venv
48
+
49
+ lock: $(VENV) ## Pin tests/requirements.txt, with hashes, in tests/requirements.lock
50
+ .venv/bin/pubrules lock
51
+
52
+ sync-check: $(VENV) ## Fail if pubrules' managed files differ from the pinned version's
53
+ .venv/bin/pubrules sync --check
54
+
55
+ fmt: ## Format Rust sources
56
+ $(CARGO) fmt --all
57
+
58
+ fmt-check: ## Verify formatting without modifying
59
+ $(CARGO) fmt --all -- --check
60
+
61
+ lint: ## Clippy, warnings are errors
62
+ $(CARGO) clippy $(CARGO_SCOPE) --all-targets -- -D warnings
63
+
64
+ test: ## Rust unit tests
65
+ $(CARGO) test $(CARGO_SCOPE)
66
+
67
+ doc: ## Documentation, warnings are errors
68
+ RUSTDOCFLAGS="-D warnings" $(CARGO) doc $(CARGO_SCOPE) --no-deps
69
+
70
+ build: ## Debug build
71
+ $(CARGO) build $(CARGO_SCOPE)
72
+
73
+ functional: build $(VENV) ## The Gherkin suite against the built binaries
74
+ cd tests && pytest -q $(PYTEST_ARGS)
75
+
76
+ # Everything `functional` runs, and the Rust tests, on a build instrumented
77
+ # by cargo-llvm-cov, so the suite's runs of the binaries count too. Paths in
78
+ # the report are relative to the repository, for SonarQube Cloud.
79
+ coverage: $(VENV) ## The Rust tests and the Gherkin suite on an instrumented build; LCOV in coverage/lcov.info (needs cargo-llvm-cov)
80
+ rm -rf coverage && mkdir coverage
81
+ source <($(CARGO) llvm-cov show-env --sh) \
82
+ && $(CARGO) llvm-cov clean --workspace \
83
+ && $(CARGO) build $(CARGO_SCOPE) \
84
+ && $(CARGO) test $(CARGO_SCOPE) \
85
+ && (cd tests && pytest -q $(PYTEST_ARGS)) \
86
+ && $(CARGO) llvm-cov report --lcov --output-path coverage/lcov.info
87
+ sed -i.bak 's|^SF:$(CURDIR)/|SF:|' coverage/lcov.info && rm coverage/lcov.info.bak
88
+
89
+ supply-chain: $(VENV) ## Regenerate SUPPLY-CHAIN.md for each of SUPPLY_CHAIN_CRATES from supply-chain/
90
+ .venv/bin/pubrules supply-chain $(SUPPLY_CHAIN_CRATES)
91
+
92
+ supply-chain-check: $(VENV) ## Fail if a committed SUPPLY-CHAIN.md is stale
93
+ .venv/bin/pubrules supply-chain --check $(SUPPLY_CHAIN_CRATES)
94
+
95
+ # The targets below enforce the Rust crate standard's checked rules; `pubrules
96
+ # required` lists which each CI job runs here.
97
+
98
+ doc-coverage: $(VENV) ## Regenerate each published library's TESTING.md
99
+ .venv/bin/pubrules doc-coverage $(PUBLISHED_CRATES)
100
+
101
+ doc-coverage-check: $(VENV) ## Fail if a public function has no example, a test covers no real item, or TESTING.md is stale
102
+ .venv/bin/pubrules doc-coverage --check $(PUBLISHED_CRATES)
103
+
104
+ vectors: ## Regenerate the test vectors from their independent sources
105
+ $(VECTORS_GENERATE)
106
+
107
+ vectors-check: vectors ## Fail if the committed test vectors differ from what the sources give
108
+ @test -n "$(VECTORS_DIRS)" || { echo "no testdata/ here: the standard asks for test vectors (RS-TEST-01)"; exit 1; }
109
+ git diff --exit-code -- $(VECTORS_DIRS)
110
+
111
+ # The verify build gets a target directory of its own. Sharing target/
112
+ # leaves dep-info naming the packaged copy's sources, after which cargo
113
+ # reports the crate Fresh however src/ changes, and tests run a stale binary.
114
+ publish-check: ## Package each published crate and verify it builds as published
115
+ for crate in $(PUBLISHED_CRATES); do \
116
+ CARGO_TARGET_DIR=$(CURDIR)/target/publish-check $(CARGO) publish --dry-run --locked -p $$crate; \
117
+ done
118
+
119
+ msrv: ## Build the published crates on their minimum Rust version (rustup toolchain install $(MSRV))
120
+ $(CARGO) +$(MSRV) check --locked $(foreach crate,$(PUBLISHED_CRATES),-p $(crate))
121
+
122
+ fuzz-smoke: ## Replay fuzz regressions, then fuzz each target briefly (needs nightly and cargo-fuzz)
123
+ @test -n "$(FUZZ_TARGETS)" || { echo "no fuzz/fuzz_targets/ here: the standard asks for fuzzing (RS-FUZZ-01)"; exit 1; }
124
+ cd fuzz && cargo +nightly fuzz build
125
+ cd fuzz && for target in $(FUZZ_TARGETS); do \
126
+ mkdir -p corpus/$$target regressions/$$target; \
127
+ cargo +nightly fuzz run $$target corpus/$$target regressions/$$target -- \
128
+ -max_total_time=$(FUZZ_SECONDS) -timeout=10 || exit 1; \
129
+ done
130
+
131
+ deny: ## Licence, advisory, ban and source audit
132
+ $(CARGO) deny --locked check
133
+
134
+ vet: ## Every dependency is audited, trusted, or exempt with its evidence
135
+ cargo vet --locked
136
+
137
+ required: $(VENV) ## The targets each CI job runs here, from the standard
138
+ .venv/bin/pubrules required
@@ -0,0 +1,8 @@
1
+ # Pinned so every machine and CI runner resolves the identical compiler.
2
+ # rustup reads this automatically on any cargo/rustc invocation in the tree,
3
+ # installing the toolchain and components on first use. Do not rely on the
4
+ # ambient `rustc` on any developer machine.
5
+ [toolchain]
6
+ channel = "1.98.1"
7
+ components = ["clippy", "rustfmt"]
8
+ profile = "minimal"
@@ -0,0 +1,27 @@
1
+ #!/usr/bin/env bash
2
+ # Managed by pubrules {version}: `pubrules sync` rewrites this file, and
3
+ # `pubrules sync --check` fails when it differs.
4
+ #
5
+ # Run this repository's pinned pubsec, which holds what pubrules does not: a
6
+ # secret's value, a write token, a private key. ./with-secrets runs it, and
7
+ # the deploy walk loads its need types.
8
+ #
9
+ # ./pubsec run -- terraform plan
10
+ # ./pubsec --version
11
+ #
12
+ # The release is deploy.providers' pubsec, or where it lists none the one
13
+ # this file fetched when sync first wrote it; the nightly moves it.
14
+ # Its wheel is fetched once into the user's cache (from the wheel mirror,
15
+ # when pubrules.json names one and GitHub fails) and checked against its
16
+ # sha256 on every run, and uvx runs that file; nothing is installed into the
17
+ # repository or the system. pubsec runs in the repository's root, where
18
+ # with-secrets.json is, from whichever directory this is called.
19
+ set -euo pipefail
20
+
21
+ if ! command -v uvx >/dev/null 2>&1; then
22
+ echo "pubsec: ./pubsec runs pubsec with uv, which is not installed: curl -LsSf https://astral.sh/uv/install.sh | sh" >&2
23
+ exit 127
24
+ fi
25
+
26
+ cd "$(dirname "$0")"
27
+ {pubsec}exec uvx --from "$fetched" pubsec "$@"
@@ -0,0 +1,20 @@
1
+ #!/usr/bin/env bash
2
+ # Managed by pubrules {version}: `pubrules sync` rewrites this file, and
3
+ # `pubrules sync --check` fails when it differs. This repository's settings are
4
+ # in with-secrets.json, which is its own.
5
+ #
6
+ # Run one command with this repository's secrets in its environment:
7
+ #
8
+ # ./with-secrets terraform plan
9
+ # ./with-secrets scripts/some-setup.sh
10
+ #
11
+ # It runs `pubsec run` from this repository's pinned pubsec (./pubsec, which
12
+ # pubrules writes beside ./pubrules), in the directory it is called from. The secrets are read from a Bitwarden
13
+ # Secrets Manager project with the bws CLI, using a read-only machine account's
14
+ # access token: BWS_ACCESS_TOKEN if set, else the line BWS_ACCESS_TOKEN=... in
15
+ # the repository's .env, which git must ignore. They exist only in this
16
+ # command's process and what it starts: nothing is written to disk, and the
17
+ # calling shell never holds them. pubsec's README, "Services: ./with-secrets",
18
+ # explains with-secrets.json.
19
+ set -euo pipefail
20
+ exec "$(cd "$(dirname "$0")" && pwd)/pubsec" run --cwd "$PWD" -- "$@"
@@ -0,0 +1,8 @@
1
+ {
2
+ "comment": "Settings for ./with-secrets, which runs ./pubsec run (pubsec's README, \"Services: ./with-secrets\", explains each). project: the Bitwarden Secrets Manager project's name or id. terraform.secrets: \"declared\" sends a secret named like a declared variable as its TF_VAR_; \"map\" sends the names terraform.names_from lists as TF_VAR_secret_values and TF_VAR_secret_revisions. Remove terraform if there is none. aliases (optional): files, each {\"aliases\": {\"NAME\": \"secret\"}}, that also export a secret under the name a tool expects; keep each next to the code that needs it.",
3
+ "project": "{project}",
4
+ "terraform": {
5
+ "dir": ".",
6
+ "secrets": "declared"
7
+ }
8
+ }
pubrules/variables.py ADDED
@@ -0,0 +1,45 @@
1
+ """The variables block of a repository's pubrules.json: the names of the GitHub
2
+ variables it reads, never their values, and maybe the workflow that takes
3
+ them in, to run once one changes:
4
+
5
+ "variables": {"names": ["SOME_SETTING", "SOME_MAP"], "deploy": "deploy.yml"}
6
+
7
+ `pubrules sync --check` refuses a block of the wrong shape. The values live in
8
+ the owner's state file, which a control plane keeps GitHub to; pubrules holds
9
+ none of them.
10
+ """
11
+
12
+ from __future__ import annotations
13
+
14
+ import json
15
+ import re
16
+ from typing import Any
17
+
18
+ BLOCK = "variables"
19
+ NAME = re.compile(r"[A-Z_][A-Z0-9_]*")
20
+ WORKFLOW = re.compile(r"[A-Za-z0-9_.-]+\.ya?ml")
21
+
22
+
23
+ def name_problem(name: Any) -> str | None:
24
+ if not isinstance(name, str) or not NAME.fullmatch(name) or name.startswith("GITHUB_"):
25
+ return f"{json.dumps(name)} is not a variable's name: upper case letters, digits and _, " \
26
+ f"not starting GITHUB_"
27
+ return None
28
+
29
+
30
+ def block_problems(block: Any) -> list[str]:
31
+ """What is wrong with a pubrules.json's variables block: one phrase each."""
32
+ if not isinstance(block, dict):
33
+ return ['it must be an object, with "names" and maybe "deploy"']
34
+ out = [f"{key} is not a setting; it takes names and deploy"
35
+ for key in sorted(block.keys() - {"names", "deploy"})]
36
+ names = block.get("names")
37
+ if not isinstance(names, list) or not names:
38
+ out.append('"names" must list at least one variable')
39
+ else:
40
+ out += [p for n in names if (p := name_problem(n))]
41
+ if len(set(map(json.dumps, names))) != len(names):
42
+ out.append('"names" lists a variable twice')
43
+ if "deploy" in block and not (isinstance(block["deploy"], str) and WORKFLOW.fullmatch(block["deploy"])):
44
+ out.append('"deploy" must be a workflow\'s file name, such as deploy.yml')
45
+ return out