crunk 0.1.0__tar.gz

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 (68) hide show
  1. crunk-0.1.0/LICENSE +21 -0
  2. crunk-0.1.0/PKG-INFO +163 -0
  3. crunk-0.1.0/README.md +150 -0
  4. crunk-0.1.0/pyproject.toml +55 -0
  5. crunk-0.1.0/setup.cfg +4 -0
  6. crunk-0.1.0/src/crunk/__init__.py +1 -0
  7. crunk-0.1.0/src/crunk/__main__.py +268 -0
  8. crunk-0.1.0/src/crunk/app/__init__.py +4 -0
  9. crunk-0.1.0/src/crunk/app/app.py +1222 -0
  10. crunk-0.1.0/src/crunk/app/config.py +165 -0
  11. crunk-0.1.0/src/crunk/cache/__init__.py +22 -0
  12. crunk-0.1.0/src/crunk/cache/store.py +315 -0
  13. crunk-0.1.0/src/crunk/fixes/__init__.py +14 -0
  14. crunk-0.1.0/src/crunk/fixes/io.py +91 -0
  15. crunk-0.1.0/src/crunk/fixes/plan.py +108 -0
  16. crunk-0.1.0/src/crunk/ingest/__init__.py +38 -0
  17. crunk-0.1.0/src/crunk/ingest/jsx.py +606 -0
  18. crunk-0.1.0/src/crunk/ingest/models.py +214 -0
  19. crunk-0.1.0/src/crunk/ingest/parse.py +429 -0
  20. crunk-0.1.0/src/crunk/ingest/tailwind.py +85 -0
  21. crunk-0.1.0/src/crunk/ingest/walk.py +572 -0
  22. crunk-0.1.0/src/crunk/logging/__init__.py +3 -0
  23. crunk-0.1.0/src/crunk/logging/config.toml +30 -0
  24. crunk-0.1.0/src/crunk/logging/filter.py +21 -0
  25. crunk-0.1.0/src/crunk/logging/formatter.py +19 -0
  26. crunk-0.1.0/src/crunk/logging/logger.py +26 -0
  27. crunk-0.1.0/src/crunk/query/__init__.py +57 -0
  28. crunk-0.1.0/src/crunk/query/engine.py +812 -0
  29. crunk-0.1.0/src/crunk/query/models.py +208 -0
  30. crunk-0.1.0/src/crunk/report/__init__.py +41 -0
  31. crunk-0.1.0/src/crunk/report/json_out.py +193 -0
  32. crunk-0.1.0/src/crunk/report/preview_out.py +159 -0
  33. crunk-0.1.0/src/crunk/report/query_out.py +239 -0
  34. crunk-0.1.0/src/crunk/report/report_out.py +162 -0
  35. crunk-0.1.0/src/crunk/report/terminal.py +255 -0
  36. crunk-0.1.0/src/crunk/rules/__init__.py +10 -0
  37. crunk-0.1.0/src/crunk/rules/_breakpoints.py +249 -0
  38. crunk-0.1.0/src/crunk/rules/_color.py +238 -0
  39. crunk-0.1.0/src/crunk/rules/_contrast.py +67 -0
  40. crunk-0.1.0/src/crunk/rules/_layers.py +79 -0
  41. crunk-0.1.0/src/crunk/rules/_org.py +250 -0
  42. crunk-0.1.0/src/crunk/rules/_scales.py +308 -0
  43. crunk-0.1.0/src/crunk/rules/_tailwind.py +746 -0
  44. crunk-0.1.0/src/crunk/rules/_typography.py +151 -0
  45. crunk-0.1.0/src/crunk/rules/_waive.py +74 -0
  46. crunk-0.1.0/src/crunk/rules/engine.py +102 -0
  47. crunk-0.1.0/src/crunk/rules/models.py +47 -0
  48. crunk-0.1.0/src/crunk/scaffold/__init__.py +8 -0
  49. crunk-0.1.0/src/crunk/scaffold/presets.py +104 -0
  50. crunk-0.1.0/src/crunk/scaffold/write.py +108 -0
  51. crunk-0.1.0/src/crunk/spec/__init__.py +51 -0
  52. crunk-0.1.0/src/crunk/spec/load.py +501 -0
  53. crunk-0.1.0/src/crunk/spec/models.py +498 -0
  54. crunk-0.1.0/src/crunk/spec/naming.py +134 -0
  55. crunk-0.1.0/src/crunk/tokens/__init__.py +51 -0
  56. crunk-0.1.0/src/crunk/tokens/io.py +424 -0
  57. crunk-0.1.0/src/crunk/tokens/render.py +380 -0
  58. crunk-0.1.0/src/crunk/tokens/tw_defaults.py +632 -0
  59. crunk-0.1.0/src/crunk/values/__init__.py +9 -0
  60. crunk-0.1.0/src/crunk/values/color.py +253 -0
  61. crunk-0.1.0/src/crunk/values/length.py +103 -0
  62. crunk-0.1.0/src/crunk/values/named.py +160 -0
  63. crunk-0.1.0/src/crunk.egg-info/PKG-INFO +163 -0
  64. crunk-0.1.0/src/crunk.egg-info/SOURCES.txt +66 -0
  65. crunk-0.1.0/src/crunk.egg-info/dependency_links.txt +1 -0
  66. crunk-0.1.0/src/crunk.egg-info/entry_points.txt +3 -0
  67. crunk-0.1.0/src/crunk.egg-info/requires.txt +4 -0
  68. crunk-0.1.0/src/crunk.egg-info/top_level.txt +1 -0
crunk-0.1.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Logan Dapp
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
crunk-0.1.0/PKG-INFO ADDED
@@ -0,0 +1,163 @@
1
+ Metadata-Version: 2.4
2
+ Name: crunk
3
+ Version: 0.1.0
4
+ License: MIT
5
+ Requires-Python: >=3.11
6
+ Description-Content-Type: text/markdown
7
+ License-File: LICENSE
8
+ Requires-Dist: typani>=0.0.3
9
+ Requires-Dist: pydantic>=2.12.0
10
+ Requires-Dist: python-dotenv>=1.0
11
+ Requires-Dist: tinycss2>=1.5.1
12
+ Dynamic: license-file
13
+
14
+ <p align="center">
15
+ <img src="docs/assets/crunk-banner.svg" alt="crunk: declare your design system once; crunk exports it, lints against it, and fixes the drift." width="100%"/>
16
+ </p>
17
+
18
+ <p align="center">
19
+ <a href="https://pypi.org/project/crunk/"><img src="https://img.shields.io/pypi/v/crunk.svg" alt="PyPI version"></a>
20
+ <a href="https://pypi.org/project/crunk/"><img src="https://img.shields.io/badge/python-3.11%2B-blue.svg" alt="Python 3.11+"></a>
21
+ <a href="LICENSE"><img src="https://img.shields.io/badge/license-MIT-blue.svg" alt="License: MIT"></a>
22
+ <a href="https://github.com/lognd/crunk/actions/workflows/ci.yml"><img src="https://github.com/lognd/crunk/actions/workflows/ci.yml/badge.svg" alt="CI status"></a>
23
+ </p>
24
+
25
+ # crunk
26
+
27
+ crunk brings Figma-style design discipline to front-end code: declare
28
+ your palette, scales, and file organization once in `crunk.toml`, and
29
+ crunk exports the tokens, lints your CSS against them, auto-fixes the
30
+ drift, and enforces the organization -- deterministically, in CI, with
31
+ no browser in the loop.
32
+
33
+ ## Highlights
34
+
35
+ - **One source of truth.** Palette, type/spacing scales, and
36
+ organization rules live in a single declarative `crunk.toml`; every
37
+ other artifact (CSS custom properties, Tailwind theme, docs) is
38
+ generated from it, never hand-maintained.
39
+ - **A linter, not a style guide.** `crunk check` fails on any color,
40
+ size, or shadow that is not in the declared system -- including
41
+ role-pair contrast ratios (`--contrast`) -- so drift is a red build,
42
+ not a review-time opinion.
43
+ - **Deterministic autofix.** `crunk fix` applies the mechanical
44
+ remediations `check` found (nearest-token rewrites, organization
45
+ moves), with `--dry-run` to preview.
46
+ - **Reuse before rebuild.** `crunk query find button` asks the design
47
+ system whether a component already exists before you write a second,
48
+ slightly different one.
49
+ - **Terminal-native.** `crunk preview` prints the token sheet and
50
+ `crunk diff` compares two token sets, both straight to the terminal.
51
+
52
+ ## Install
53
+
54
+ ```bash
55
+ uv tool install crunk
56
+ # or
57
+ pip install crunk
58
+ ```
59
+
60
+ The package installs two equivalent binaries on PATH: `crunk` and the
61
+ short alias `crk`.
62
+
63
+ ## Quickstart
64
+
65
+ ```bash
66
+ crunk init --preset default # scaffold crunk.toml + a skeleton project
67
+ crunk check # lint tracked CSS against crunk.toml
68
+ crunk tokens # export the declared tokens as CSS
69
+ crunk fix --dry-run # preview the mechanical fixes check found
70
+ crunk map # print the organization inventory
71
+ crunk check --contrast # print role-pair contrast ratios, PASS/FAIL
72
+ crunk query find button # is there already a button component?
73
+ crunk preview # print the terminal token sheet
74
+ crunk diff ../other-project # diff two crunk.toml token sets
75
+ ```
76
+
77
+ Customize the design system by editing the scaffolded `crunk.toml`
78
+ (palette, scales, organization rules) -- see
79
+ [docs/design/02-specification.md](docs/design/02-specification.md) for
80
+ the full schema and rule catalog.
81
+
82
+ ## Commands
83
+
84
+ <!-- frob:describes src/crunk/__main__.py::_build_parser -->
85
+
86
+ | Command | What it does |
87
+ | --- | --- |
88
+ | `crunk init` | scaffold `crunk.toml` + skeleton |
89
+ | `crunk check` | lint against the spec |
90
+ | `crunk tokens` | export/verify tokens |
91
+ | `crunk fix` | deterministic autofix |
92
+ | `crunk map` | organization inventory |
93
+ | `crunk query` | ask the design system: reuse before rebuild |
94
+ | `crunk preview` | terminal token sheet, no browser needed |
95
+ | `crunk diff OTHER` | token-set diff vs another spec |
96
+
97
+ 8 commands. See `docs/commands/` for each one's flags and exit codes:
98
+ [init](docs/commands/init.md), [check](docs/commands/check.md),
99
+ [tokens](docs/commands/tokens.md), [fix](docs/commands/fix.md),
100
+ [map](docs/commands/map.md), [query](docs/commands/query.md),
101
+ [preview](docs/commands/preview.md) (also covers `diff`).
102
+ `check`/`fix`/`map`/`query` accept `--no-cache` to bypass the result
103
+ cache (see [docs/design/subsystems/cache.md](docs/design/subsystems/cache.md)).
104
+
105
+ ## Tailwind integration
106
+
107
+ To expose a declared sizes scale as real utility classes
108
+ (`min-h-size-44` etc.) rather than one-off arbitrary values, adopt the
109
+ generated `tailwind.tokens.json` wholesale --
110
+ `theme: { extend: require("./tailwind.tokens.json") }` with
111
+ `namespace_keys` on -- instead of hand-wiring only some categories into
112
+ `theme.extend`: the generated file carries all six sizing categories,
113
+ and hand-picking a subset silently drops the rest. See
114
+ [docs/commands/tokens.md](docs/commands/tokens.md) for the full mapping.
115
+
116
+ ## Documentation
117
+
118
+ The design docs are a waterfall under
119
+ [docs/design/](docs/design/): requirements, specification, system
120
+ design, subsystems, components -- each layer with its test plan.
121
+ Per-command references live under [docs/commands/](docs/commands/).
122
+
123
+ ## Development
124
+
125
+ ```bash
126
+ git clone https://github.com/lognd/crunk.git
127
+ cd crunk
128
+ make install # stamp-guarded uv sync
129
+ ```
130
+
131
+ This is a [frob](https://github.com/lognd/frob)-enabled project: `frob
132
+ <verb>` is the interface for everything past install, not a `make`
133
+ wrapper around it.
134
+
135
+ ```bash
136
+ frob test # select and run tests for the touched set (or --all)
137
+ frob format # ruff check --fix + ruff format
138
+ frob coverage # refresh coverage.xml / the coverage stamp
139
+ frob check # the aggregate gate: ruff, ty, frob cycle/dup/arch/...
140
+ ```
141
+
142
+ `make install`/`make clean`/`make upload` remain (bootstrap and
143
+ build/publish -- see the Makefile's own comment on this split). You do
144
+ not need frob installed to contribute; `uv run pytest -q` covers the
145
+ test suite and CONTRIBUTING.md covers the rest.
146
+
147
+ ## Contributing
148
+
149
+ Contributions are welcome, from a typo fix to a new feature. Read
150
+ [CONTRIBUTING.md](CONTRIBUTING.md) before opening a pull request; it
151
+ covers the local dev setup, the commit format, and the
152
+ AI-assisted-contributions policy in particular. Everyone participating
153
+ in this project is expected to follow the
154
+ [Code of Conduct](CODE_OF_CONDUCT.md).
155
+
156
+ ## Security
157
+
158
+ See [SECURITY.md](SECURITY.md) for how to report a vulnerability;
159
+ please do not file a public issue for one.
160
+
161
+ ## License
162
+
163
+ MIT, see [LICENSE](LICENSE).
crunk-0.1.0/README.md ADDED
@@ -0,0 +1,150 @@
1
+ <p align="center">
2
+ <img src="docs/assets/crunk-banner.svg" alt="crunk: declare your design system once; crunk exports it, lints against it, and fixes the drift." width="100%"/>
3
+ </p>
4
+
5
+ <p align="center">
6
+ <a href="https://pypi.org/project/crunk/"><img src="https://img.shields.io/pypi/v/crunk.svg" alt="PyPI version"></a>
7
+ <a href="https://pypi.org/project/crunk/"><img src="https://img.shields.io/badge/python-3.11%2B-blue.svg" alt="Python 3.11+"></a>
8
+ <a href="LICENSE"><img src="https://img.shields.io/badge/license-MIT-blue.svg" alt="License: MIT"></a>
9
+ <a href="https://github.com/lognd/crunk/actions/workflows/ci.yml"><img src="https://github.com/lognd/crunk/actions/workflows/ci.yml/badge.svg" alt="CI status"></a>
10
+ </p>
11
+
12
+ # crunk
13
+
14
+ crunk brings Figma-style design discipline to front-end code: declare
15
+ your palette, scales, and file organization once in `crunk.toml`, and
16
+ crunk exports the tokens, lints your CSS against them, auto-fixes the
17
+ drift, and enforces the organization -- deterministically, in CI, with
18
+ no browser in the loop.
19
+
20
+ ## Highlights
21
+
22
+ - **One source of truth.** Palette, type/spacing scales, and
23
+ organization rules live in a single declarative `crunk.toml`; every
24
+ other artifact (CSS custom properties, Tailwind theme, docs) is
25
+ generated from it, never hand-maintained.
26
+ - **A linter, not a style guide.** `crunk check` fails on any color,
27
+ size, or shadow that is not in the declared system -- including
28
+ role-pair contrast ratios (`--contrast`) -- so drift is a red build,
29
+ not a review-time opinion.
30
+ - **Deterministic autofix.** `crunk fix` applies the mechanical
31
+ remediations `check` found (nearest-token rewrites, organization
32
+ moves), with `--dry-run` to preview.
33
+ - **Reuse before rebuild.** `crunk query find button` asks the design
34
+ system whether a component already exists before you write a second,
35
+ slightly different one.
36
+ - **Terminal-native.** `crunk preview` prints the token sheet and
37
+ `crunk diff` compares two token sets, both straight to the terminal.
38
+
39
+ ## Install
40
+
41
+ ```bash
42
+ uv tool install crunk
43
+ # or
44
+ pip install crunk
45
+ ```
46
+
47
+ The package installs two equivalent binaries on PATH: `crunk` and the
48
+ short alias `crk`.
49
+
50
+ ## Quickstart
51
+
52
+ ```bash
53
+ crunk init --preset default # scaffold crunk.toml + a skeleton project
54
+ crunk check # lint tracked CSS against crunk.toml
55
+ crunk tokens # export the declared tokens as CSS
56
+ crunk fix --dry-run # preview the mechanical fixes check found
57
+ crunk map # print the organization inventory
58
+ crunk check --contrast # print role-pair contrast ratios, PASS/FAIL
59
+ crunk query find button # is there already a button component?
60
+ crunk preview # print the terminal token sheet
61
+ crunk diff ../other-project # diff two crunk.toml token sets
62
+ ```
63
+
64
+ Customize the design system by editing the scaffolded `crunk.toml`
65
+ (palette, scales, organization rules) -- see
66
+ [docs/design/02-specification.md](docs/design/02-specification.md) for
67
+ the full schema and rule catalog.
68
+
69
+ ## Commands
70
+
71
+ <!-- frob:describes src/crunk/__main__.py::_build_parser -->
72
+
73
+ | Command | What it does |
74
+ | --- | --- |
75
+ | `crunk init` | scaffold `crunk.toml` + skeleton |
76
+ | `crunk check` | lint against the spec |
77
+ | `crunk tokens` | export/verify tokens |
78
+ | `crunk fix` | deterministic autofix |
79
+ | `crunk map` | organization inventory |
80
+ | `crunk query` | ask the design system: reuse before rebuild |
81
+ | `crunk preview` | terminal token sheet, no browser needed |
82
+ | `crunk diff OTHER` | token-set diff vs another spec |
83
+
84
+ 8 commands. See `docs/commands/` for each one's flags and exit codes:
85
+ [init](docs/commands/init.md), [check](docs/commands/check.md),
86
+ [tokens](docs/commands/tokens.md), [fix](docs/commands/fix.md),
87
+ [map](docs/commands/map.md), [query](docs/commands/query.md),
88
+ [preview](docs/commands/preview.md) (also covers `diff`).
89
+ `check`/`fix`/`map`/`query` accept `--no-cache` to bypass the result
90
+ cache (see [docs/design/subsystems/cache.md](docs/design/subsystems/cache.md)).
91
+
92
+ ## Tailwind integration
93
+
94
+ To expose a declared sizes scale as real utility classes
95
+ (`min-h-size-44` etc.) rather than one-off arbitrary values, adopt the
96
+ generated `tailwind.tokens.json` wholesale --
97
+ `theme: { extend: require("./tailwind.tokens.json") }` with
98
+ `namespace_keys` on -- instead of hand-wiring only some categories into
99
+ `theme.extend`: the generated file carries all six sizing categories,
100
+ and hand-picking a subset silently drops the rest. See
101
+ [docs/commands/tokens.md](docs/commands/tokens.md) for the full mapping.
102
+
103
+ ## Documentation
104
+
105
+ The design docs are a waterfall under
106
+ [docs/design/](docs/design/): requirements, specification, system
107
+ design, subsystems, components -- each layer with its test plan.
108
+ Per-command references live under [docs/commands/](docs/commands/).
109
+
110
+ ## Development
111
+
112
+ ```bash
113
+ git clone https://github.com/lognd/crunk.git
114
+ cd crunk
115
+ make install # stamp-guarded uv sync
116
+ ```
117
+
118
+ This is a [frob](https://github.com/lognd/frob)-enabled project: `frob
119
+ <verb>` is the interface for everything past install, not a `make`
120
+ wrapper around it.
121
+
122
+ ```bash
123
+ frob test # select and run tests for the touched set (or --all)
124
+ frob format # ruff check --fix + ruff format
125
+ frob coverage # refresh coverage.xml / the coverage stamp
126
+ frob check # the aggregate gate: ruff, ty, frob cycle/dup/arch/...
127
+ ```
128
+
129
+ `make install`/`make clean`/`make upload` remain (bootstrap and
130
+ build/publish -- see the Makefile's own comment on this split). You do
131
+ not need frob installed to contribute; `uv run pytest -q` covers the
132
+ test suite and CONTRIBUTING.md covers the rest.
133
+
134
+ ## Contributing
135
+
136
+ Contributions are welcome, from a typo fix to a new feature. Read
137
+ [CONTRIBUTING.md](CONTRIBUTING.md) before opening a pull request; it
138
+ covers the local dev setup, the commit format, and the
139
+ AI-assisted-contributions policy in particular. Everyone participating
140
+ in this project is expected to follow the
141
+ [Code of Conduct](CODE_OF_CONDUCT.md).
142
+
143
+ ## Security
144
+
145
+ See [SECURITY.md](SECURITY.md) for how to report a vulnerability;
146
+ please do not file a public issue for one.
147
+
148
+ ## License
149
+
150
+ MIT, see [LICENSE](LICENSE).
@@ -0,0 +1,55 @@
1
+ [build-system]
2
+ requires = ["setuptools>=68", "wheel"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "crunk"
7
+ version = "0.1.0"
8
+ description = ""
9
+ readme = "README.md"
10
+ requires-python = ">=3.11"
11
+ license = { text = "MIT" }
12
+
13
+ dependencies = [
14
+ "typani>=0.0.3",
15
+ "pydantic>=2.12.0",
16
+ "python-dotenv>=1.0",
17
+ "tinycss2>=1.5.1",
18
+ ]
19
+
20
+ [project.scripts]
21
+ crunk = "crunk.__main__:main"
22
+ crk = "crunk.__main__:main"
23
+
24
+ [dependency-groups]
25
+ dev = [
26
+ "pytest>=8",
27
+ "pytest-cov>=5",
28
+ "pytest-xdist>=3.8.0",
29
+ "ruff>=0.8",
30
+ "ty>=0.0.1a8",
31
+ ]
32
+
33
+ [tool.setuptools]
34
+ packages = { find = { where = ["src"] } }
35
+
36
+ [tool.setuptools.package-data]
37
+ crunk = ["py.typed", "logging/config.toml"]
38
+
39
+ [tool.pytest.ini_options]
40
+ testpaths = ["tests"]
41
+ addopts = "-q"
42
+ pythonpath = ["."]
43
+
44
+ [tool.ruff]
45
+ line-length = 88
46
+ target-version = "py311"
47
+
48
+ [tool.ruff.lint]
49
+ select = ["E", "F", "W", "I"]
50
+
51
+ [tool.ruff.lint.per-file-ignores]
52
+ "tests/**" = ["E501"]
53
+
54
+ [tool.ruff.format]
55
+ quote-style = "double"
crunk-0.1.0/setup.cfg ADDED
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1 @@
1
+ # crunk
@@ -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()
@@ -0,0 +1,4 @@
1
+ from crunk.app.app import App
2
+ from crunk.app.config import AppConfig
3
+
4
+ __all__ = ["App", "AppConfig"]