awexpress 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.
- awexpress-0.1.0/LICENSE +15 -0
- awexpress-0.1.0/PKG-INFO +107 -0
- awexpress-0.1.0/README.md +91 -0
- awexpress-0.1.0/awexpress/__init__.py +7 -0
- awexpress-0.1.0/awexpress/__main__.py +5 -0
- awexpress-0.1.0/awexpress/_doctor.py +195 -0
- awexpress-0.1.0/awexpress/cli.py +212 -0
- awexpress-0.1.0/awexpress/compilers.py +280 -0
- awexpress-0.1.0/awexpress/importer.py +89 -0
- awexpress-0.1.0/awexpress/manifest.py +200 -0
- awexpress-0.1.0/awexpress/media.py +232 -0
- awexpress-0.1.0/awexpress/picker.py +145 -0
- awexpress-0.1.0/awexpress/selftest.py +133 -0
- awexpress-0.1.0/awexpress/targets.py +119 -0
- awexpress-0.1.0/awexpress.egg-info/PKG-INFO +107 -0
- awexpress-0.1.0/awexpress.egg-info/SOURCES.txt +21 -0
- awexpress-0.1.0/awexpress.egg-info/dependency_links.txt +1 -0
- awexpress-0.1.0/awexpress.egg-info/entry_points.txt +2 -0
- awexpress-0.1.0/awexpress.egg-info/requires.txt +4 -0
- awexpress-0.1.0/awexpress.egg-info/top_level.txt +1 -0
- awexpress-0.1.0/pyproject.toml +41 -0
- awexpress-0.1.0/setup.cfg +4 -0
- awexpress-0.1.0/tests/test_awexpress.py +147 -0
awexpress-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
Apache License 2.0
|
|
2
|
+
|
|
3
|
+
Copyright 2026 Aitherium
|
|
4
|
+
|
|
5
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
you may not use this file except in compliance with the License.
|
|
7
|
+
You may obtain a copy of the License at
|
|
8
|
+
|
|
9
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
|
|
11
|
+
Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
See the License for the specific language governing permissions and
|
|
15
|
+
limitations under the License.
|
awexpress-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: awexpress
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: One expression pack of stickers, emoji, captions and sounds, compiled for every app. Aither World Expressions.
|
|
5
|
+
License: Apache-2.0
|
|
6
|
+
Project-URL: Homepage, https://github.com/Aitherium/awexpress
|
|
7
|
+
Project-URL: Repository, https://github.com/Aitherium/awexpress.git
|
|
8
|
+
Project-URL: Issues, https://github.com/Aitherium/awexpress/issues
|
|
9
|
+
Requires-Python: >=3.10
|
|
10
|
+
Description-Content-Type: text/markdown
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
Requires-Dist: Pillow>=10.0
|
|
13
|
+
Provides-Extra: dev
|
|
14
|
+
Requires-Dist: pytest>=7.0; extra == "dev"
|
|
15
|
+
Dynamic: license-file
|
|
16
|
+
|
|
17
|
+
# awexpress — Aither World Expressions
|
|
18
|
+
|
|
19
|
+
One expression pack of stickers, emoji, caption cards and short sounds, compiled for
|
|
20
|
+
every app that has its own rules.
|
|
21
|
+
|
|
22
|
+
A sticker made for Discord (320 px APNG under 512 KiB) is the wrong size, format and
|
|
23
|
+
weight for Telegram (512 px WEBP or a 3-second VP9 WEBM), for Slack (under 128 KB, up to
|
|
24
|
+
50 frames), and for a LinkedIn or X post, where there is no sticker system at all and the
|
|
25
|
+
right thing is a post-ready image with alt text. awexpress keeps ONE source pack and
|
|
26
|
+
compiles a bundle per target, measuring every file it writes against that target's
|
|
27
|
+
published limit.
|
|
28
|
+
|
|
29
|
+
awexpress never draws anything. Masters come from wherever you make them; awexpress
|
|
30
|
+
packages and compiles.
|
|
31
|
+
|
|
32
|
+
## Install
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
pip install -e . # Pillow is the only dependency
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
ffmpeg/ffprobe on `PATH` are used for Telegram video stickers and sound clips. Without
|
|
39
|
+
them animated Telegram stickers compile as stills (and say so) and sounds are reported
|
|
40
|
+
`not judged`, never passed.
|
|
41
|
+
|
|
42
|
+
## A pack
|
|
43
|
+
|
|
44
|
+
`expressions.json` beside the master files:
|
|
45
|
+
|
|
46
|
+
```json
|
|
47
|
+
{
|
|
48
|
+
"schema": "awexpress/1",
|
|
49
|
+
"kind": "expressions",
|
|
50
|
+
"id": "my-pack",
|
|
51
|
+
"name": "My pack",
|
|
52
|
+
"version": "0.1.0",
|
|
53
|
+
"license": "CC-BY-4.0",
|
|
54
|
+
"attribution": "Me",
|
|
55
|
+
"items": [
|
|
56
|
+
{"id": "citation-needed", "kind": "sticker", "file": "stickers/vera_1.png",
|
|
57
|
+
"caption": "CITATION NEEDED", "alt": "Vera holds up a sign: CITATION NEEDED",
|
|
58
|
+
"emoji": "📚", "tags": ["citation", "source"]}
|
|
59
|
+
]
|
|
60
|
+
}
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
`kind` is `sticker`, `emoji`, `caption` or `sound`. Items marked `"public": false` are
|
|
64
|
+
never compiled unless you pass `--include-private`.
|
|
65
|
+
|
|
66
|
+
Already have a folder of Discord assets with a `manifest.json` (`stickers` / `emoji` /
|
|
67
|
+
`sounds` lists)? `awexpress import <dir>` writes the pack in place.
|
|
68
|
+
|
|
69
|
+
## Commands
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
awexpress validate ./my-pack
|
|
73
|
+
awexpress build ./my-pack --target all # discord, telegram, slack, linkedin, x
|
|
74
|
+
awexpress build ./my-pack --target post # just the composer images
|
|
75
|
+
awexpress pick citation # best match for X -> clipboard
|
|
76
|
+
awexpress pick citation --target linkedin --alt # copy its alt text instead
|
|
77
|
+
awexpress install https://github.com/org/repo#packs/my-pack
|
|
78
|
+
awexpress targets # every limit and where it came from
|
|
79
|
+
awexpress --self-test
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
`build` writes `<out>/<target>/<kind>/<item>.<ext>`, a `<target>.json` upload manifest
|
|
83
|
+
in each target's own field names (Discord sticker name/description/tags, Telegram
|
|
84
|
+
`emoji_list`/`keywords`/`sticker_format`, alt text for posts) and `report.json` with
|
|
85
|
+
every file measured. Exit 1 if any file is over its limit, 2 if something could not be
|
|
86
|
+
judged.
|
|
87
|
+
|
|
88
|
+
## Limits used
|
|
89
|
+
|
|
90
|
+
| target | file | limit | source |
|
|
91
|
+
|---|---|---|---|
|
|
92
|
+
| Discord | sticker | 320x320 PNG/APNG/GIF, 512 KiB, 5 s | Discord developer docs, sticker resource |
|
|
93
|
+
| Discord | emoji | 128x128, 256 KiB | Discord developer docs, emoji resource |
|
|
94
|
+
| Discord | soundboard | mp3/ogg, 512 kb, 5.2 s | Discord developer docs, soundboard resource |
|
|
95
|
+
| Telegram | sticker | 512 px side, PNG/WEBP; video WEBM VP9 256 KB, 3 s, 30 fps, no audio | core.telegram.org/stickers |
|
|
96
|
+
| Telegram | custom emoji | 100x100 | core.telegram.org/stickers |
|
|
97
|
+
| Telegram | set thumbnail | 100x100 WEBP/PNG, 128 KB | Bot API setStickerSetThumbnail |
|
|
98
|
+
| Slack | emoji | under 128 KB, GIF up to 50 frames, lower-case names | Slack help + admin.emoji.add |
|
|
99
|
+
| X | post image | 5 MB; GIF 15 MB, up to 1280x1080, 350 frames | docs.x.com media best practices |
|
|
100
|
+
| LinkedIn | post image | 1080x1080, 5 MB, alt 300 chars | third-party spec guides (marked unverified) |
|
|
101
|
+
|
|
102
|
+
LinkedIn publishes no image spec page; those numbers are treated as a conservative
|
|
103
|
+
ceiling and are flagged `verified: false` in `awexpress targets`.
|
|
104
|
+
|
|
105
|
+
## Licence
|
|
106
|
+
|
|
107
|
+
Apache-2.0.
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
# awexpress — Aither World Expressions
|
|
2
|
+
|
|
3
|
+
One expression pack of stickers, emoji, caption cards and short sounds, compiled for
|
|
4
|
+
every app that has its own rules.
|
|
5
|
+
|
|
6
|
+
A sticker made for Discord (320 px APNG under 512 KiB) is the wrong size, format and
|
|
7
|
+
weight for Telegram (512 px WEBP or a 3-second VP9 WEBM), for Slack (under 128 KB, up to
|
|
8
|
+
50 frames), and for a LinkedIn or X post, where there is no sticker system at all and the
|
|
9
|
+
right thing is a post-ready image with alt text. awexpress keeps ONE source pack and
|
|
10
|
+
compiles a bundle per target, measuring every file it writes against that target's
|
|
11
|
+
published limit.
|
|
12
|
+
|
|
13
|
+
awexpress never draws anything. Masters come from wherever you make them; awexpress
|
|
14
|
+
packages and compiles.
|
|
15
|
+
|
|
16
|
+
## Install
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
pip install -e . # Pillow is the only dependency
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
ffmpeg/ffprobe on `PATH` are used for Telegram video stickers and sound clips. Without
|
|
23
|
+
them animated Telegram stickers compile as stills (and say so) and sounds are reported
|
|
24
|
+
`not judged`, never passed.
|
|
25
|
+
|
|
26
|
+
## A pack
|
|
27
|
+
|
|
28
|
+
`expressions.json` beside the master files:
|
|
29
|
+
|
|
30
|
+
```json
|
|
31
|
+
{
|
|
32
|
+
"schema": "awexpress/1",
|
|
33
|
+
"kind": "expressions",
|
|
34
|
+
"id": "my-pack",
|
|
35
|
+
"name": "My pack",
|
|
36
|
+
"version": "0.1.0",
|
|
37
|
+
"license": "CC-BY-4.0",
|
|
38
|
+
"attribution": "Me",
|
|
39
|
+
"items": [
|
|
40
|
+
{"id": "citation-needed", "kind": "sticker", "file": "stickers/vera_1.png",
|
|
41
|
+
"caption": "CITATION NEEDED", "alt": "Vera holds up a sign: CITATION NEEDED",
|
|
42
|
+
"emoji": "📚", "tags": ["citation", "source"]}
|
|
43
|
+
]
|
|
44
|
+
}
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
`kind` is `sticker`, `emoji`, `caption` or `sound`. Items marked `"public": false` are
|
|
48
|
+
never compiled unless you pass `--include-private`.
|
|
49
|
+
|
|
50
|
+
Already have a folder of Discord assets with a `manifest.json` (`stickers` / `emoji` /
|
|
51
|
+
`sounds` lists)? `awexpress import <dir>` writes the pack in place.
|
|
52
|
+
|
|
53
|
+
## Commands
|
|
54
|
+
|
|
55
|
+
```bash
|
|
56
|
+
awexpress validate ./my-pack
|
|
57
|
+
awexpress build ./my-pack --target all # discord, telegram, slack, linkedin, x
|
|
58
|
+
awexpress build ./my-pack --target post # just the composer images
|
|
59
|
+
awexpress pick citation # best match for X -> clipboard
|
|
60
|
+
awexpress pick citation --target linkedin --alt # copy its alt text instead
|
|
61
|
+
awexpress install https://github.com/org/repo#packs/my-pack
|
|
62
|
+
awexpress targets # every limit and where it came from
|
|
63
|
+
awexpress --self-test
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
`build` writes `<out>/<target>/<kind>/<item>.<ext>`, a `<target>.json` upload manifest
|
|
67
|
+
in each target's own field names (Discord sticker name/description/tags, Telegram
|
|
68
|
+
`emoji_list`/`keywords`/`sticker_format`, alt text for posts) and `report.json` with
|
|
69
|
+
every file measured. Exit 1 if any file is over its limit, 2 if something could not be
|
|
70
|
+
judged.
|
|
71
|
+
|
|
72
|
+
## Limits used
|
|
73
|
+
|
|
74
|
+
| target | file | limit | source |
|
|
75
|
+
|---|---|---|---|
|
|
76
|
+
| Discord | sticker | 320x320 PNG/APNG/GIF, 512 KiB, 5 s | Discord developer docs, sticker resource |
|
|
77
|
+
| Discord | emoji | 128x128, 256 KiB | Discord developer docs, emoji resource |
|
|
78
|
+
| Discord | soundboard | mp3/ogg, 512 kb, 5.2 s | Discord developer docs, soundboard resource |
|
|
79
|
+
| Telegram | sticker | 512 px side, PNG/WEBP; video WEBM VP9 256 KB, 3 s, 30 fps, no audio | core.telegram.org/stickers |
|
|
80
|
+
| Telegram | custom emoji | 100x100 | core.telegram.org/stickers |
|
|
81
|
+
| Telegram | set thumbnail | 100x100 WEBP/PNG, 128 KB | Bot API setStickerSetThumbnail |
|
|
82
|
+
| Slack | emoji | under 128 KB, GIF up to 50 frames, lower-case names | Slack help + admin.emoji.add |
|
|
83
|
+
| X | post image | 5 MB; GIF 15 MB, up to 1280x1080, 350 frames | docs.x.com media best practices |
|
|
84
|
+
| LinkedIn | post image | 1080x1080, 5 MB, alt 300 chars | third-party spec guides (marked unverified) |
|
|
85
|
+
|
|
86
|
+
LinkedIn publishes no image spec page; those numbers are treated as a conservative
|
|
87
|
+
ceiling and are flagged `verified: false` in `awexpress targets`.
|
|
88
|
+
|
|
89
|
+
## Licence
|
|
90
|
+
|
|
91
|
+
Apache-2.0.
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"""awexpress -- Aither World Expressions.
|
|
2
|
+
|
|
3
|
+
One expression pack (stickers, emoji, caption cards, sound clips, alt text, tags,
|
|
4
|
+
licence) compiled into a bundle for each app that has its own limits: Discord,
|
|
5
|
+
Telegram, Slack, and post-ready images for LinkedIn and X.
|
|
6
|
+
"""
|
|
7
|
+
__version__ = "0.1.0"
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
"""Stack-aware `doctor` for awexpress.
|
|
2
|
+
|
|
3
|
+
GENERATED BY gen_aw_doctor.py -- DO NOT EDIT.
|
|
4
|
+
Regenerate it with the generator named above; a hand-edit here is reverted by
|
|
5
|
+
the next run and fails the parity gate.
|
|
6
|
+
|
|
7
|
+
Why a doctor exists at all: the aw* bricks are designed to COMPOSE, so the
|
|
8
|
+
interesting failures live BETWEEN them. "awexpress is installed" is not the useful
|
|
9
|
+
fact -- "awexpress is installed and the thing it pairs with is not" is. This reports
|
|
10
|
+
the whole stack, not just itself.
|
|
11
|
+
|
|
12
|
+
stdlib only, on purpose: a diagnostic that cannot run because a dependency is
|
|
13
|
+
missing is worthless precisely when you need it.
|
|
14
|
+
"""
|
|
15
|
+
from __future__ import annotations
|
|
16
|
+
|
|
17
|
+
import importlib.util
|
|
18
|
+
import os
|
|
19
|
+
import shutil
|
|
20
|
+
import sys
|
|
21
|
+
|
|
22
|
+
SELF = 'awexpress'
|
|
23
|
+
#: Frozen from the Aither World registry at generation time. A shipped
|
|
24
|
+
#: package cannot read the registry, and a doctor that guessed at the family
|
|
25
|
+
#: would go stale in silence. Regenerate to update.
|
|
26
|
+
FAMILY = ['awdecide', 'awdiscord']
|
|
27
|
+
FAMILY_ERROR = None
|
|
28
|
+
PAIRS_WITH = ['awdiscord']
|
|
29
|
+
|
|
30
|
+
#: This brick's OWN config, read out of its source at generation time.
|
|
31
|
+
#: ENV_REQUIRED is `os.environ["X"]` -- absent, that is a KeyError the moment
|
|
32
|
+
#: the line runs. ENV_OPTIONAL is `os.getenv("X")`, which returns None and lets
|
|
33
|
+
#: the caller cope. Only this brick's namespace is listed: reporting the
|
|
34
|
+
#: platform-wide vars it also touches would be noise, and a doctor that floods
|
|
35
|
+
#: gets ignored.
|
|
36
|
+
ENV_REQUIRED = []
|
|
37
|
+
ENV_OPTIONAL = ['AWEXPRESS_HOME']
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def _installed(mod: str) -> "str | None":
|
|
41
|
+
"""Version if importable, else None. Never raises -- a broken sibling must
|
|
42
|
+
not take the diagnostic down with it."""
|
|
43
|
+
try:
|
|
44
|
+
if importlib.util.find_spec(mod) is None:
|
|
45
|
+
return None
|
|
46
|
+
except (ImportError, ValueError):
|
|
47
|
+
return None
|
|
48
|
+
try:
|
|
49
|
+
from importlib.metadata import PackageNotFoundError, version
|
|
50
|
+
try:
|
|
51
|
+
return version(mod)
|
|
52
|
+
except PackageNotFoundError:
|
|
53
|
+
return "installed"
|
|
54
|
+
except Exception:
|
|
55
|
+
return "installed"
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def report(out=None) -> int:
|
|
59
|
+
"""Print the stack picture. 0 = this brick and its pairs are present."""
|
|
60
|
+
out = out or sys.stdout
|
|
61
|
+
print(f"{SELF} doctor", file=out)
|
|
62
|
+
|
|
63
|
+
mine = _installed(SELF)
|
|
64
|
+
print(f" self {SELF} {mine or 'NOT IMPORTABLE'}", file=out)
|
|
65
|
+
shim = shutil.which(SELF)
|
|
66
|
+
print(f" command {shim or 'not on PATH'}", file=out)
|
|
67
|
+
if FAMILY_ERROR:
|
|
68
|
+
# Never an empty stack: "0/0 installed" reads as a clean machine.
|
|
69
|
+
print(f"\nverdict: UNJUDGED -- {FAMILY_ERROR}", file=out)
|
|
70
|
+
return 2
|
|
71
|
+
|
|
72
|
+
# The stack. Siblings this brick pairs with are called out separately,
|
|
73
|
+
# because a missing pair is a REASON, while a missing unrelated brick is
|
|
74
|
+
# just a fact about your machine.
|
|
75
|
+
missing_pairs, present = [], []
|
|
76
|
+
for name in FAMILY:
|
|
77
|
+
v = _installed(name)
|
|
78
|
+
if v:
|
|
79
|
+
present.append(name)
|
|
80
|
+
elif name in PAIRS_WITH:
|
|
81
|
+
missing_pairs.append(name)
|
|
82
|
+
print(f" stack {len(present)}/{len(FAMILY)} aw* packages installed",
|
|
83
|
+
file=out)
|
|
84
|
+
if present:
|
|
85
|
+
print(f" {' '.join(sorted(present))}", file=out)
|
|
86
|
+
|
|
87
|
+
missing_req = [v for v in ENV_REQUIRED if not os.environ.get(v)]
|
|
88
|
+
if ENV_REQUIRED or ENV_OPTIONAL:
|
|
89
|
+
have = sum(1 for v in ENV_REQUIRED + ENV_OPTIONAL if os.environ.get(v))
|
|
90
|
+
total = len(ENV_REQUIRED) + len(ENV_OPTIONAL)
|
|
91
|
+
print(f" config {have}/{total} of this brick's own vars set", file=out)
|
|
92
|
+
if missing_req:
|
|
93
|
+
# Not a preference. os.environ[...] raises the moment it runs.
|
|
94
|
+
print(f" MISSING REQUIRED: {' '.join(missing_req)}", file=out)
|
|
95
|
+
|
|
96
|
+
local = _local_checks()
|
|
97
|
+
for line in local:
|
|
98
|
+
print(f" {line}", file=out)
|
|
99
|
+
problems, unjudged = _local_verdict()
|
|
100
|
+
|
|
101
|
+
if mine is None:
|
|
102
|
+
print(f"\nverdict: {SELF} itself is not importable. Reinstall it before "
|
|
103
|
+
f"anything else here means much.", file=out)
|
|
104
|
+
return 1
|
|
105
|
+
if missing_req:
|
|
106
|
+
print(f"\nverdict: {SELF} is missing required config "
|
|
107
|
+
f"({', '.join(missing_req)}). Those are read with os.environ[...], "
|
|
108
|
+
f"so the code path that needs them raises rather than degrades.",
|
|
109
|
+
file=out)
|
|
110
|
+
return 1
|
|
111
|
+
# A measured NO outranks a missing optional pair: awrise printed
|
|
112
|
+
# "nothing wakes run-due" and still exited 0 because the missing-pairs
|
|
113
|
+
# branch returned first (measured 2026-09-20).
|
|
114
|
+
if problems:
|
|
115
|
+
for p in problems:
|
|
116
|
+
print(f"\nverdict: {p}", file=out)
|
|
117
|
+
return 1
|
|
118
|
+
if unjudged:
|
|
119
|
+
for u in unjudged:
|
|
120
|
+
print(f"\nverdict: UNJUDGED -- could not judge: {u}", file=out)
|
|
121
|
+
return 2
|
|
122
|
+
if missing_pairs:
|
|
123
|
+
print(f"\nverdict: {SELF} works, but pairs with "
|
|
124
|
+
f"{', '.join(sorted(missing_pairs))} which "
|
|
125
|
+
f"{'is' if len(missing_pairs) == 1 else 'are'} not installed. "
|
|
126
|
+
f"That is a capability you are missing, not an error.", file=out)
|
|
127
|
+
return 0
|
|
128
|
+
print(f"\nverdict: {SELF} and everything it pairs with are present.", file=out)
|
|
129
|
+
return 0
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
def _local_verdict() -> tuple:
|
|
133
|
+
"""The brick's OWN verdict, folded into the exit code.
|
|
134
|
+
|
|
135
|
+
Without this the local lines are DECORATION. Measured 2026-09-20: awrise
|
|
136
|
+
printed "hostclock NOT INSTALLED -- nothing wakes run-due" and "last tick
|
|
137
|
+
never", then exited 0 -- teaching an operator that a doctor exit code
|
|
138
|
+
carries no information. A brick opts in with `_doctor_local_verdict()`
|
|
139
|
+
returning (problems, unjudged); a brick without one is unaffected.
|
|
140
|
+
"""
|
|
141
|
+
try:
|
|
142
|
+
mod = importlib.import_module(f"{SELF}.doctor_local")
|
|
143
|
+
problems, unjudged = mod._doctor_local_verdict()
|
|
144
|
+
except Exception: # noqa: BLE001
|
|
145
|
+
return [], []
|
|
146
|
+
return list(problems or []), list(unjudged or [])
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
def _local_checks() -> "list[str]":
|
|
150
|
+
"""Per-brick checks, if this package defines them.
|
|
151
|
+
|
|
152
|
+
Kept as a HOOK rather than generated guesses: the generator knows the family
|
|
153
|
+
from the registry, but it does not know what awexpress needs at runtime, and a
|
|
154
|
+
doctor that invented config requirements would be confidently wrong. A
|
|
155
|
+
package supplies `_doctor_local()` returning display lines; absent, the
|
|
156
|
+
stack picture above still stands on its own.
|
|
157
|
+
"""
|
|
158
|
+
try:
|
|
159
|
+
mod = importlib.import_module(f"{SELF}.doctor_local")
|
|
160
|
+
except Exception:
|
|
161
|
+
return []
|
|
162
|
+
try:
|
|
163
|
+
return list(mod._doctor_local())
|
|
164
|
+
except Exception as exc: # noqa: BLE001
|
|
165
|
+
return [f"local checks raised {type(exc).__name__}: {exc}"]
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
def main(argv: "list[str] | None" = None) -> int:
|
|
169
|
+
# --self-test delegates to a SIBLING module when one exists.
|
|
170
|
+
#
|
|
171
|
+
# This file is generated and a fresh run replaces it, so a self-test
|
|
172
|
+
# written HERE is deleted by the next regeneration. awdelphi learned that
|
|
173
|
+
# the expensive way: 125 lines exercising four real failure paths --
|
|
174
|
+
# convergence, roster anonymization, resume, gateway-down -- lived in this
|
|
175
|
+
# file and were destroyed by a routine regeneration, silently, leaving a
|
|
176
|
+
# --self-test flag that reported PASS while asserting nothing.
|
|
177
|
+
#
|
|
178
|
+
# So the seam is a separate module the generator never writes. A package
|
|
179
|
+
# with real machinery to prove puts it in _selftest.py; everything else
|
|
180
|
+
# keeps the honest answer below rather than a self-test that only ever
|
|
181
|
+
# passes.
|
|
182
|
+
argv = list(argv if argv is not None else __import__("sys").argv[1:])
|
|
183
|
+
if "--self-test" in argv:
|
|
184
|
+
try:
|
|
185
|
+
from . import _selftest as _st
|
|
186
|
+
except Exception:
|
|
187
|
+
print("no _selftest module: this doctor reports the stack, and has",
|
|
188
|
+
"no machinery of its own to prove")
|
|
189
|
+
return 0
|
|
190
|
+
return int(_st.run())
|
|
191
|
+
return report()
|
|
192
|
+
|
|
193
|
+
|
|
194
|
+
if __name__ == "__main__":
|
|
195
|
+
raise SystemExit(main())
|
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
"""awexpress -- Aither World Expressions.
|
|
2
|
+
|
|
3
|
+
awexpress validate <pack>
|
|
4
|
+
awexpress build <pack> --target discord|telegram|slack|post|all [--out DIR]
|
|
5
|
+
awexpress import <discord-asset-dir> [--id ID] [--name NAME]
|
|
6
|
+
awexpress install <pack-dir | https://git-url[#subdir]>
|
|
7
|
+
awexpress pick <query> [--target x|linkedin|discord|telegram|slack] [--alt] [--print]
|
|
8
|
+
awexpress list [--target T]
|
|
9
|
+
awexpress targets
|
|
10
|
+
awexpress --self-test
|
|
11
|
+
|
|
12
|
+
Exit codes: 0 done, 1 a file is over its limit / nothing matched / invalid pack,
|
|
13
|
+
2 could not judge (missing tool, unreadable input).
|
|
14
|
+
"""
|
|
15
|
+
from __future__ import annotations
|
|
16
|
+
|
|
17
|
+
import argparse
|
|
18
|
+
import json
|
|
19
|
+
import shutil
|
|
20
|
+
import subprocess
|
|
21
|
+
import sys
|
|
22
|
+
import tempfile
|
|
23
|
+
from pathlib import Path
|
|
24
|
+
|
|
25
|
+
from . import __version__, compilers, picker
|
|
26
|
+
from .importer import import_dir
|
|
27
|
+
from .manifest import PackError, load
|
|
28
|
+
from .targets import table
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def _out(pack_root: Path, out: str | None) -> Path:
|
|
32
|
+
return Path(out).expanduser().resolve() if out else pack_root / "dist"
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def cmd_validate(a) -> int:
|
|
36
|
+
pack = load(a.pack)
|
|
37
|
+
kinds: dict[str, int] = {}
|
|
38
|
+
for i in pack.items:
|
|
39
|
+
kinds[i.kind] = kinds.get(i.kind, 0) + 1
|
|
40
|
+
print(f"{pack.id} {pack.version}: {len(pack.items)} items "
|
|
41
|
+
+ ", ".join(f"{n} {k}" for k, n in sorted(kinds.items()))
|
|
42
|
+
+ f"; {sum(1 for i in pack.items if not i.public)} private")
|
|
43
|
+
return 0
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def cmd_build(a) -> int:
|
|
47
|
+
pack = load(a.pack)
|
|
48
|
+
out = _out(pack.root, a.out)
|
|
49
|
+
report = compilers.build(pack, a.target, out, include_private=a.include_private)
|
|
50
|
+
picker.record(pack.id, pack.root, out)
|
|
51
|
+
by: dict[str, list[int]] = {}
|
|
52
|
+
for r in report["rows"]:
|
|
53
|
+
t = by.setdefault(r["target"], [0, 0, 0])
|
|
54
|
+
if r["ok"] is True:
|
|
55
|
+
t[0] += 1
|
|
56
|
+
elif r["ok"] is False:
|
|
57
|
+
t[1] += 1
|
|
58
|
+
elif r["reason"].startswith("not judged"):
|
|
59
|
+
t[2] += 1
|
|
60
|
+
for target, (ok, over, unj) in by.items():
|
|
61
|
+
print(f"{target:9} {ok:4} fit {over:3} over {unj:3} not judged")
|
|
62
|
+
for r in report["rows"]:
|
|
63
|
+
if r["ok"] is False:
|
|
64
|
+
print(f" OVER {r['target']}/{r['kind']}/{r['item']}: {r['reason']}")
|
|
65
|
+
print(f"report: {out / 'report.json'}")
|
|
66
|
+
if report["over"]:
|
|
67
|
+
return 1
|
|
68
|
+
return 2 if report["unjudged"] else 0
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def cmd_import(a) -> int:
|
|
72
|
+
path = import_dir(Path(a.src).expanduser(), pack_id=a.id, name=a.name, license=a.license,
|
|
73
|
+
attribution=a.attribution, force=a.force)
|
|
74
|
+
pack = load(path)
|
|
75
|
+
print(f"wrote {path}: {len(pack.items)} items")
|
|
76
|
+
return 0
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
def cmd_install(a) -> int:
|
|
80
|
+
dest_root = picker.home() / "packs"
|
|
81
|
+
with tempfile.TemporaryDirectory(prefix="awexpress-install-") as tmp:
|
|
82
|
+
src = a.src
|
|
83
|
+
if src.startswith(("https://", "git@")):
|
|
84
|
+
url, _, sub = src.partition("#")
|
|
85
|
+
clone = Path(tmp) / "clone"
|
|
86
|
+
r = subprocess.run(["git", "clone", "--depth", "1", "-q", url, str(clone)],
|
|
87
|
+
capture_output=True, timeout=180)
|
|
88
|
+
if r.returncode != 0:
|
|
89
|
+
print(f"could not clone {url}", file=sys.stderr)
|
|
90
|
+
return 2
|
|
91
|
+
path = clone / sub if sub else clone
|
|
92
|
+
else:
|
|
93
|
+
path = Path(src).expanduser()
|
|
94
|
+
pack = load(path)
|
|
95
|
+
dest = dest_root / pack.id
|
|
96
|
+
if dest.exists():
|
|
97
|
+
if not a.force:
|
|
98
|
+
print(f"{pack.id} already installed at {dest} (use --force)", file=sys.stderr)
|
|
99
|
+
return 1
|
|
100
|
+
shutil.rmtree(dest)
|
|
101
|
+
shutil.copytree(path, dest, ignore=shutil.ignore_patterns(".git", "dist"))
|
|
102
|
+
pack = load(dest)
|
|
103
|
+
report = compilers.build(pack, ["all"], dest / "dist")
|
|
104
|
+
picker.record(pack.id, dest, dest / "dist")
|
|
105
|
+
print(f"installed {pack.id} {pack.version} -> {dest} ({report['files']} files, "
|
|
106
|
+
f"{report['over']} over)")
|
|
107
|
+
if report["over"]:
|
|
108
|
+
return 1
|
|
109
|
+
return 2 if report["unjudged"] else 0
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
def cmd_pick(a) -> int:
|
|
113
|
+
hits = picker.search(" ".join(a.query), target=a.target, limit=a.limit)
|
|
114
|
+
if not hits:
|
|
115
|
+
print(f"nothing matches {' '.join(a.query)!r} for {a.target}", file=sys.stderr)
|
|
116
|
+
return 1
|
|
117
|
+
if a.print or a.limit > 1 and a.all:
|
|
118
|
+
print(json.dumps(hits, indent=2, ensure_ascii=False))
|
|
119
|
+
return 0
|
|
120
|
+
best = hits[0]
|
|
121
|
+
how = picker.copy(text=best["alt"]) if a.alt else picker.copy(Path(best["file"]))
|
|
122
|
+
print(f"copied {how}: {best['file']}")
|
|
123
|
+
if best["alt"] and not a.alt:
|
|
124
|
+
print(f"alt: {best['alt']}")
|
|
125
|
+
return 0
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
def cmd_list(a) -> int:
|
|
129
|
+
for e in picker.search("", target=a.target, limit=10_000):
|
|
130
|
+
print(f"{e['pack']:20} {e['item']:36} {e['file']}")
|
|
131
|
+
return 0
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
def main(argv: list[str] | None = None) -> int:
|
|
135
|
+
# GENERATED doctor intercept (gen_aw_doctor.py) -- do not edit
|
|
136
|
+
_dv = locals().get("argv")
|
|
137
|
+
if (_dv if _dv is not None else __import__("sys").argv[1:])[:1] == ["doctor"]:
|
|
138
|
+
from ._doctor import report
|
|
139
|
+
return report()
|
|
140
|
+
# GENERATED repo-state intercept (gen_aw_doctor.py) -- do not edit
|
|
141
|
+
try:
|
|
142
|
+
from awgit import state as _aw_state
|
|
143
|
+
except Exception:
|
|
144
|
+
_aw_state = None
|
|
145
|
+
if _aw_state is not None:
|
|
146
|
+
_sv = locals().get("argv")
|
|
147
|
+
if _aw_state.cli_banner(_sv if _sv is not None else __import__("sys").argv[1:]):
|
|
148
|
+
return 0
|
|
149
|
+
p = argparse.ArgumentParser(prog="awexpress", description=__doc__.split("\n")[0])
|
|
150
|
+
p.add_argument("--version", action="version", version=f"awexpress {__version__}")
|
|
151
|
+
p.add_argument("--self-test", action="store_true", help="prove the compilers and judge")
|
|
152
|
+
sub = p.add_subparsers(dest="cmd")
|
|
153
|
+
v = sub.add_parser("validate")
|
|
154
|
+
v.add_argument("pack")
|
|
155
|
+
b = sub.add_parser("build")
|
|
156
|
+
b.add_argument("pack")
|
|
157
|
+
b.add_argument("--target", action="append", default=None,
|
|
158
|
+
help="discord, telegram, slack, post (linkedin + x) or all; repeatable")
|
|
159
|
+
b.add_argument("--out")
|
|
160
|
+
b.add_argument("--include-private", action="store_true")
|
|
161
|
+
i = sub.add_parser("import")
|
|
162
|
+
i.add_argument("src")
|
|
163
|
+
i.add_argument("--id", default="")
|
|
164
|
+
i.add_argument("--name", default="")
|
|
165
|
+
i.add_argument("--license", default="")
|
|
166
|
+
i.add_argument("--attribution", default="")
|
|
167
|
+
i.add_argument("--force", action="store_true")
|
|
168
|
+
n = sub.add_parser("install")
|
|
169
|
+
n.add_argument("src")
|
|
170
|
+
n.add_argument("--force", action="store_true")
|
|
171
|
+
k = sub.add_parser("pick")
|
|
172
|
+
k.add_argument("query", nargs="+")
|
|
173
|
+
k.add_argument("--target", default="x")
|
|
174
|
+
k.add_argument("--alt", action="store_true", help="copy the alt text, not the file")
|
|
175
|
+
k.add_argument("--print", action="store_true", help="print matches, copy nothing")
|
|
176
|
+
k.add_argument("--all", action="store_true")
|
|
177
|
+
k.add_argument("--limit", type=int, default=1)
|
|
178
|
+
ls = sub.add_parser("list")
|
|
179
|
+
ls.add_argument("--target", default="x")
|
|
180
|
+
sub.add_parser("targets")
|
|
181
|
+
a = p.parse_args(argv)
|
|
182
|
+
for stream in (sys.stdout, sys.stderr):
|
|
183
|
+
if hasattr(stream, "reconfigure"):
|
|
184
|
+
stream.reconfigure(encoding="utf-8", errors="replace")
|
|
185
|
+
if a.self_test:
|
|
186
|
+
from .selftest import run
|
|
187
|
+
code, lines = run()
|
|
188
|
+
print("\n".join(lines))
|
|
189
|
+
print("self-test " + ("PASSED" if code == 0 else "FAILED"))
|
|
190
|
+
return code
|
|
191
|
+
if a.cmd == "targets":
|
|
192
|
+
print(json.dumps(table(), indent=2))
|
|
193
|
+
return 0
|
|
194
|
+
if a.cmd == "build" and not a.target:
|
|
195
|
+
a.target = ["all"]
|
|
196
|
+
handlers = {"validate": cmd_validate, "build": cmd_build, "import": cmd_import,
|
|
197
|
+
"install": cmd_install, "pick": cmd_pick, "list": cmd_list}
|
|
198
|
+
if a.cmd not in handlers:
|
|
199
|
+
p.print_help()
|
|
200
|
+
return 2
|
|
201
|
+
try:
|
|
202
|
+
return handlers[a.cmd](a)
|
|
203
|
+
except PackError as exc:
|
|
204
|
+
print(f"invalid pack: {exc}", file=sys.stderr)
|
|
205
|
+
return 1
|
|
206
|
+
except (OSError, RuntimeError, ValueError) as exc:
|
|
207
|
+
print(f"could not judge: {type(exc).__name__}: {exc}", file=sys.stderr)
|
|
208
|
+
return 2
|
|
209
|
+
|
|
210
|
+
|
|
211
|
+
if __name__ == "__main__":
|
|
212
|
+
sys.exit(main())
|