crunk 0.1.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.
- crunk/__init__.py +1 -0
- crunk/__main__.py +268 -0
- crunk/app/__init__.py +4 -0
- crunk/app/app.py +1222 -0
- crunk/app/config.py +165 -0
- crunk/cache/__init__.py +22 -0
- crunk/cache/store.py +315 -0
- crunk/fixes/__init__.py +14 -0
- crunk/fixes/io.py +91 -0
- crunk/fixes/plan.py +108 -0
- crunk/ingest/__init__.py +38 -0
- crunk/ingest/jsx.py +606 -0
- crunk/ingest/models.py +214 -0
- crunk/ingest/parse.py +429 -0
- crunk/ingest/tailwind.py +85 -0
- crunk/ingest/walk.py +572 -0
- crunk/logging/__init__.py +3 -0
- crunk/logging/config.toml +30 -0
- crunk/logging/filter.py +21 -0
- crunk/logging/formatter.py +19 -0
- crunk/logging/logger.py +26 -0
- crunk/query/__init__.py +57 -0
- crunk/query/engine.py +812 -0
- crunk/query/models.py +208 -0
- crunk/report/__init__.py +41 -0
- crunk/report/json_out.py +193 -0
- crunk/report/preview_out.py +159 -0
- crunk/report/query_out.py +239 -0
- crunk/report/report_out.py +162 -0
- crunk/report/terminal.py +255 -0
- crunk/rules/__init__.py +10 -0
- crunk/rules/_breakpoints.py +249 -0
- crunk/rules/_color.py +238 -0
- crunk/rules/_contrast.py +67 -0
- crunk/rules/_layers.py +79 -0
- crunk/rules/_org.py +250 -0
- crunk/rules/_scales.py +308 -0
- crunk/rules/_tailwind.py +746 -0
- crunk/rules/_typography.py +151 -0
- crunk/rules/_waive.py +74 -0
- crunk/rules/engine.py +102 -0
- crunk/rules/models.py +47 -0
- crunk/scaffold/__init__.py +8 -0
- crunk/scaffold/presets.py +104 -0
- crunk/scaffold/write.py +108 -0
- crunk/spec/__init__.py +51 -0
- crunk/spec/load.py +501 -0
- crunk/spec/models.py +498 -0
- crunk/spec/naming.py +134 -0
- crunk/tokens/__init__.py +51 -0
- crunk/tokens/io.py +424 -0
- crunk/tokens/render.py +380 -0
- crunk/tokens/tw_defaults.py +632 -0
- crunk/values/__init__.py +9 -0
- crunk/values/color.py +253 -0
- crunk/values/length.py +103 -0
- crunk/values/named.py +160 -0
- crunk-0.1.0.dist-info/METADATA +163 -0
- crunk-0.1.0.dist-info/RECORD +63 -0
- crunk-0.1.0.dist-info/WHEEL +5 -0
- crunk-0.1.0.dist-info/entry_points.txt +3 -0
- crunk-0.1.0.dist-info/licenses/LICENSE +21 -0
- crunk-0.1.0.dist-info/top_level.txt +1 -0
crunk/__init__.py
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# crunk
|
crunk/__main__.py
ADDED
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
"""Entry point: argv -> AppConfig -> App(cfg)() -> exit code."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import argparse
|
|
6
|
+
import importlib.metadata
|
|
7
|
+
import logging
|
|
8
|
+
import sys
|
|
9
|
+
from pathlib import Path
|
|
10
|
+
|
|
11
|
+
from dotenv import load_dotenv
|
|
12
|
+
|
|
13
|
+
from crunk.app import App, AppConfig
|
|
14
|
+
from crunk.logging import get_logger
|
|
15
|
+
|
|
16
|
+
_log = get_logger(__name__)
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
# frob:ticket T-0129
|
|
20
|
+
def _crunk_version() -> str:
|
|
21
|
+
"""Installed `crunk` distribution version, or `"0"` when unresolvable
|
|
22
|
+
(mirrors `App._cache_key_for`'s importlib.metadata fallback)."""
|
|
23
|
+
try:
|
|
24
|
+
return importlib.metadata.version("crunk")
|
|
25
|
+
except importlib.metadata.PackageNotFoundError:
|
|
26
|
+
return "0"
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
# frob:ticket T-0139
|
|
30
|
+
def _resolved_path(raw: str) -> Path:
|
|
31
|
+
"""`--root`'s argparse `type`: resolve against cwd at parse time so a
|
|
32
|
+
relative `--root` (r19, A-092's own `--root frontend` example) behaves
|
|
33
|
+
like the cwd-derived default instead of staying relative through
|
|
34
|
+
downstream `Path.relative_to` calls."""
|
|
35
|
+
return Path(raw).resolve()
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
# frob:waive AFFECT001 reason="README.md/docs/commands/*.md already document the other \
|
|
39
|
+
# four verbs unaffected by T-0052's --format default change; docs/commands/tokens.md \
|
|
40
|
+
# itself was updated in this diff" follow_up="T-0024"
|
|
41
|
+
# frob:waive AFFECT001 reason="docs/design/02-specification.md r14 A-070 already \
|
|
42
|
+
# documents --config; docs/commands/check.md carries the one flag-list entry" \
|
|
43
|
+
# follow_up="T-0024"
|
|
44
|
+
# frob:ticket T-0082
|
|
45
|
+
# frob:ticket T-0083
|
|
46
|
+
# frob:ticket T-0127
|
|
47
|
+
# frob:ticket T-0129
|
|
48
|
+
# frob:ticket T-0136
|
|
49
|
+
# frob:ticket T-0139
|
|
50
|
+
def _build_parser() -> argparse.ArgumentParser:
|
|
51
|
+
"""Build the `crunk` argument parser: global -v/--verbose plus every verb
|
|
52
|
+
(init/check/tokens/fix/map/query, plus r7's explain/preview/diff).
|
|
53
|
+
|
|
54
|
+
r15 (A-072): `--version` (argparse version action, the installed
|
|
55
|
+
distribution version via `importlib.metadata`) prints and exits 0
|
|
56
|
+
without requiring a subcommand; short `-v` stays verbose logging.
|
|
57
|
+
"""
|
|
58
|
+
p = argparse.ArgumentParser(prog="crunk")
|
|
59
|
+
p.add_argument(
|
|
60
|
+
"--version",
|
|
61
|
+
action="version",
|
|
62
|
+
version=_crunk_version(),
|
|
63
|
+
)
|
|
64
|
+
p.add_argument(
|
|
65
|
+
"-v", "--verbose", action="store_true", help="enable debug-level logging"
|
|
66
|
+
)
|
|
67
|
+
sub = p.add_subparsers(dest="command", required=True)
|
|
68
|
+
|
|
69
|
+
init_p = sub.add_parser("init", help="scaffold crunk.toml + skeleton")
|
|
70
|
+
init_p.add_argument("--preset", dest="init_preset", default="default")
|
|
71
|
+
init_p.add_argument(
|
|
72
|
+
"--force", dest="init_force", action="store_true", default=False
|
|
73
|
+
)
|
|
74
|
+
|
|
75
|
+
check_p = sub.add_parser("check", help="lint against the spec")
|
|
76
|
+
check_p.add_argument("paths", nargs="*", default=[], metavar="PATH")
|
|
77
|
+
check_p.add_argument(
|
|
78
|
+
"--json", dest="check_json", action="store_true", default=False
|
|
79
|
+
)
|
|
80
|
+
check_report_group = check_p.add_mutually_exclusive_group()
|
|
81
|
+
check_report_group.add_argument(
|
|
82
|
+
"--contrast", dest="check_contrast", action="store_true", default=False
|
|
83
|
+
)
|
|
84
|
+
check_report_group.add_argument(
|
|
85
|
+
"--report", dest="check_report", action="store_true", default=False
|
|
86
|
+
)
|
|
87
|
+
check_p.add_argument(
|
|
88
|
+
"--no-cache", dest="no_cache", action="store_true", default=False
|
|
89
|
+
)
|
|
90
|
+
check_p.add_argument("--config", dest="config", type=Path, default=None)
|
|
91
|
+
check_p.add_argument("--root", dest="root", type=_resolved_path, default=None)
|
|
92
|
+
|
|
93
|
+
tokens_p = sub.add_parser("tokens", help="export/verify tokens")
|
|
94
|
+
# frob:ticket T-0052
|
|
95
|
+
# default=None is the "no --format given" sentinel: bare `crunk tokens`
|
|
96
|
+
# writes via write_tokens, while an explicit --format previews on stdout.
|
|
97
|
+
tokens_p.add_argument(
|
|
98
|
+
"--format",
|
|
99
|
+
dest="tokens_format",
|
|
100
|
+
choices=["css", "json", "tailwind"],
|
|
101
|
+
default=None,
|
|
102
|
+
)
|
|
103
|
+
tokens_p.add_argument(
|
|
104
|
+
"--check", dest="tokens_check", action="store_true", default=False
|
|
105
|
+
)
|
|
106
|
+
tokens_p.add_argument("--config", dest="config", type=Path, default=None)
|
|
107
|
+
tokens_p.add_argument("--root", dest="root", type=_resolved_path, default=None)
|
|
108
|
+
|
|
109
|
+
fix_p = sub.add_parser("fix", help="deterministic autofix")
|
|
110
|
+
fix_p.add_argument("paths", nargs="*", default=[], metavar="PATH")
|
|
111
|
+
fix_p.add_argument(
|
|
112
|
+
"--dry-run", dest="fix_dry_run", action="store_true", default=False
|
|
113
|
+
)
|
|
114
|
+
fix_p.add_argument(
|
|
115
|
+
"--no-cache", dest="no_cache", action="store_true", default=False
|
|
116
|
+
)
|
|
117
|
+
fix_p.add_argument("--config", dest="config", type=Path, default=None)
|
|
118
|
+
fix_p.add_argument("--root", dest="root", type=_resolved_path, default=None)
|
|
119
|
+
|
|
120
|
+
map_p = sub.add_parser("map", help="organization inventory")
|
|
121
|
+
map_p.add_argument("--json", dest="map_json", action="store_true", default=False)
|
|
122
|
+
map_p.add_argument(
|
|
123
|
+
"--no-cache", dest="no_cache", action="store_true", default=False
|
|
124
|
+
)
|
|
125
|
+
map_p.add_argument("--config", dest="config", type=Path, default=None)
|
|
126
|
+
map_p.add_argument("--root", dest="root", type=_resolved_path, default=None)
|
|
127
|
+
|
|
128
|
+
_build_query_parser(sub)
|
|
129
|
+
|
|
130
|
+
explain_p = sub.add_parser(
|
|
131
|
+
"explain", help="one token: value + every use (r7, CT-32)"
|
|
132
|
+
)
|
|
133
|
+
explain_p.add_argument("name", metavar="NAME")
|
|
134
|
+
explain_p.add_argument(
|
|
135
|
+
"--json", dest="explain_json", action="store_true", default=False
|
|
136
|
+
)
|
|
137
|
+
explain_p.add_argument(
|
|
138
|
+
"--no-cache", dest="no_cache", action="store_true", default=False
|
|
139
|
+
)
|
|
140
|
+
explain_p.add_argument("--config", dest="config", type=Path, default=None)
|
|
141
|
+
explain_p.add_argument("--root", dest="root", type=_resolved_path, default=None)
|
|
142
|
+
|
|
143
|
+
preview_p = sub.add_parser("preview", help="terminal token sheet (r7, CT-31)")
|
|
144
|
+
# frob:ticket T-0088
|
|
145
|
+
preview_p.add_argument(
|
|
146
|
+
"--color", dest="preview_color", action="store_true", default=False
|
|
147
|
+
)
|
|
148
|
+
preview_p.add_argument("--config", dest="config", type=Path, default=None)
|
|
149
|
+
preview_p.add_argument("--root", dest="root", type=_resolved_path, default=None)
|
|
150
|
+
|
|
151
|
+
diff_p = sub.add_parser("diff", help="token-set diff vs another spec (r7, CT-31)")
|
|
152
|
+
diff_p.add_argument("other", metavar="OTHER")
|
|
153
|
+
# frob:ticket T-0088
|
|
154
|
+
diff_p.add_argument(
|
|
155
|
+
"--color", dest="diff_color", action="store_true", default=False
|
|
156
|
+
)
|
|
157
|
+
diff_p.add_argument("--config", dest="config", type=Path, default=None)
|
|
158
|
+
diff_p.add_argument("--root", dest="root", type=_resolved_path, default=None)
|
|
159
|
+
|
|
160
|
+
_build_cache_parser(sub)
|
|
161
|
+
|
|
162
|
+
return p
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
# frob:ticket T-0136
|
|
166
|
+
def _build_cache_parser(sub: argparse._SubParsersAction) -> None:
|
|
167
|
+
"""Add `crunk cache`'s subcommand tree (r18, A-087): `ls`/`prune`."""
|
|
168
|
+
cache_p = sub.add_parser("cache", help="inspect/prune the result cache (r18)")
|
|
169
|
+
cache_sub = cache_p.add_subparsers(dest="cache_kind")
|
|
170
|
+
|
|
171
|
+
cache_sub.add_parser("ls", help="list every store under the cache home")
|
|
172
|
+
|
|
173
|
+
prune_p = cache_sub.add_parser("prune", help="remove dead/stale stores")
|
|
174
|
+
prune_p.add_argument("--age", dest="cache_age", type=int, default=30)
|
|
175
|
+
prune_p.add_argument("--all", dest="cache_all", action="store_true", default=False)
|
|
176
|
+
|
|
177
|
+
|
|
178
|
+
# frob:ticket T-0127
|
|
179
|
+
# frob:ticket T-0139
|
|
180
|
+
def _build_query_parser(sub: argparse._SubParsersAction) -> None:
|
|
181
|
+
"""Add `crunk query`'s subcommand tree (CR-15): find/component/dupes/
|
|
182
|
+
unused/uses/color/violations, each with its own `--json`.
|
|
183
|
+
"""
|
|
184
|
+
query_p = sub.add_parser("query", help="ask the design system (CR-15)")
|
|
185
|
+
query_p.add_argument("--config", dest="config", type=Path, default=None)
|
|
186
|
+
query_p.add_argument("--root", dest="root", type=_resolved_path, default=None)
|
|
187
|
+
query_sub = query_p.add_subparsers(dest="query_kind")
|
|
188
|
+
|
|
189
|
+
find_p = query_sub.add_parser("find", help="ranked search across the codebase")
|
|
190
|
+
find_p.add_argument("term", metavar="TERM")
|
|
191
|
+
find_p.add_argument("--json", dest="query_json", action="store_true", default=False)
|
|
192
|
+
|
|
193
|
+
component_p = query_sub.add_parser("component", help="one component's card")
|
|
194
|
+
component_p.add_argument("name", metavar="NAME")
|
|
195
|
+
component_p.add_argument(
|
|
196
|
+
"--json", dest="query_json", action="store_true", default=False
|
|
197
|
+
)
|
|
198
|
+
|
|
199
|
+
dupes_p = query_sub.add_parser("dupes", help="near-duplicate components")
|
|
200
|
+
dupes_p.add_argument("--threshold", dest="query_threshold", type=float, default=0.6)
|
|
201
|
+
dupes_p.add_argument(
|
|
202
|
+
"--json", dest="query_json", action="store_true", default=False
|
|
203
|
+
)
|
|
204
|
+
|
|
205
|
+
unused_p = query_sub.add_parser("unused", help="tokens no sheet references")
|
|
206
|
+
unused_p.add_argument(
|
|
207
|
+
"--json", dest="query_json", action="store_true", default=False
|
|
208
|
+
)
|
|
209
|
+
|
|
210
|
+
uses_p = query_sub.add_parser("uses", help="every site referencing a token")
|
|
211
|
+
uses_p.add_argument("name", metavar="NAME")
|
|
212
|
+
uses_p.add_argument("--json", dest="query_json", action="store_true", default=False)
|
|
213
|
+
|
|
214
|
+
color_p = query_sub.add_parser("color", help="palette entries nearest a color")
|
|
215
|
+
color_p.add_argument("value", metavar="VALUE")
|
|
216
|
+
color_p.add_argument(
|
|
217
|
+
"--json", dest="query_json", action="store_true", default=False
|
|
218
|
+
)
|
|
219
|
+
|
|
220
|
+
violations_p = query_sub.add_parser("violations", help="filtered check results")
|
|
221
|
+
violations_p.add_argument("--rule", dest="query_rule", default=None)
|
|
222
|
+
violations_p.add_argument("--path", dest="query_path", default=None)
|
|
223
|
+
violations_p.add_argument(
|
|
224
|
+
"--json", dest="query_json", action="store_true", default=False
|
|
225
|
+
)
|
|
226
|
+
|
|
227
|
+
|
|
228
|
+
# frob:ticket T-0082
|
|
229
|
+
# frob:ticket T-0083
|
|
230
|
+
def _extract_paths(args: argparse.Namespace) -> argparse.Namespace:
|
|
231
|
+
"""Move argparse's `paths`/`term`/`name`/`value`/`other` positionals onto
|
|
232
|
+
their per-command field (`*_paths` for check/fix, `query_term` for query,
|
|
233
|
+
`diff_other` for diff).
|
|
234
|
+
"""
|
|
235
|
+
paths = [Path(p) for p in getattr(args, "paths", [])]
|
|
236
|
+
if args.command == "check":
|
|
237
|
+
args.check_paths = paths
|
|
238
|
+
elif args.command == "fix":
|
|
239
|
+
args.fix_paths = paths
|
|
240
|
+
elif args.command == "query":
|
|
241
|
+
for positional in ("term", "name", "value"):
|
|
242
|
+
# frob:waive OPAQUE001 reason="names from the fixed literal tuple above"
|
|
243
|
+
value = getattr(args, positional, None)
|
|
244
|
+
if value is not None:
|
|
245
|
+
args.query_term = value
|
|
246
|
+
break
|
|
247
|
+
elif args.command == "explain":
|
|
248
|
+
args.explain_name = args.name
|
|
249
|
+
elif args.command == "diff":
|
|
250
|
+
args.diff_other = args.other
|
|
251
|
+
return args
|
|
252
|
+
|
|
253
|
+
|
|
254
|
+
# frob:doc docs/index.md#public-api
|
|
255
|
+
# frob:tests tests/unit/test_app.py::test_parser_version_prints_and_exits_0
|
|
256
|
+
# frob:tests tests/system/test_e2e_01_init.py::test_init_default_preset_then_check_clean
|
|
257
|
+
def main() -> None:
|
|
258
|
+
"""Parse argv, build `AppConfig`, run `App(cfg)()`, and exit with its code."""
|
|
259
|
+
load_dotenv()
|
|
260
|
+
args = _extract_paths(_build_parser().parse_args())
|
|
261
|
+
logging.getLogger().setLevel(logging.DEBUG if args.verbose else logging.WARNING)
|
|
262
|
+
cfg = AppConfig.from_external(args)
|
|
263
|
+
_log.debug("main: command=%s root=%s", cfg.command, cfg.root)
|
|
264
|
+
sys.exit(App(cfg)())
|
|
265
|
+
|
|
266
|
+
|
|
267
|
+
if __name__ == "__main__":
|
|
268
|
+
main()
|
crunk/app/__init__.py
ADDED