makea-cli 0.2.29__tar.gz → 0.2.30__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 (85) hide show
  1. {makea_cli-0.2.29 → makea_cli-0.2.30}/CHANGELOG.md +12 -0
  2. {makea_cli-0.2.29 → makea_cli-0.2.30}/PKG-INFO +4 -4
  3. {makea_cli-0.2.29 → makea_cli-0.2.30}/README.md +3 -3
  4. makea_cli-0.2.30/makea_cli/__init__.py +1 -0
  5. {makea_cli-0.2.29 → makea_cli-0.2.30}/makea_cli/commands/files/cmd.py +2 -2
  6. {makea_cli-0.2.29 → makea_cli-0.2.30}/makea_cli/file_reader.py +256 -0
  7. {makea_cli-0.2.29 → makea_cli-0.2.30}/pyproject.toml +1 -1
  8. {makea_cli-0.2.29 → makea_cli-0.2.30}/tests/golden_manifest.json +3 -3
  9. {makea_cli-0.2.29 → makea_cli-0.2.30}/tests/test_file_reader.py +66 -0
  10. makea_cli-0.2.29/makea_cli/__init__.py +0 -1
  11. {makea_cli-0.2.29 → makea_cli-0.2.30}/.claude/skills/create-supplier-profile/SKILL.md +0 -0
  12. {makea_cli-0.2.29 → makea_cli-0.2.30}/.claude/skills/lark-cli-setup/SKILL.md +0 -0
  13. {makea_cli-0.2.29 → makea_cli-0.2.30}/.claude/skills/link-supplier-user/SKILL.md +0 -0
  14. {makea_cli-0.2.29 → makea_cli-0.2.30}/.claude/skills/makea-cli-setup/SKILL.md +0 -0
  15. {makea_cli-0.2.29 → makea_cli-0.2.30}/.claude/skills/payment-revenue-report/SKILL.md +0 -0
  16. {makea_cli-0.2.29 → makea_cli-0.2.30}/.claude/skills/supplier-user-id-migration/SKILL.md +0 -0
  17. {makea_cli-0.2.29 → makea_cli-0.2.30}/.gitignore +0 -0
  18. {makea_cli-0.2.29 → makea_cli-0.2.30}/makea-collection-upload/SKILL.md +0 -0
  19. {makea_cli-0.2.29 → makea_cli-0.2.30}/makea-collection-upload/scripts/create_products.py +0 -0
  20. {makea_cli-0.2.29 → makea_cli-0.2.30}/makea_cli/__main__.py +0 -0
  21. {makea_cli-0.2.29 → makea_cli-0.2.30}/makea_cli/api_client.py +0 -0
  22. {makea_cli-0.2.29 → makea_cli-0.2.30}/makea_cli/auth_pkce.py +0 -0
  23. {makea_cli-0.2.29 → makea_cli-0.2.30}/makea_cli/broker.py +0 -0
  24. {makea_cli-0.2.29 → makea_cli-0.2.30}/makea_cli/commands/__init__.py +0 -0
  25. {makea_cli-0.2.29 → makea_cli-0.2.30}/makea_cli/commands/_util.py +0 -0
  26. {makea_cli-0.2.29 → makea_cli-0.2.30}/makea_cli/commands/about/__init__.py +0 -0
  27. {makea_cli-0.2.29 → makea_cli-0.2.30}/makea_cli/commands/about/cmd.py +0 -0
  28. {makea_cli-0.2.29 → makea_cli-0.2.30}/makea_cli/commands/analytics/__init__.py +0 -0
  29. {makea_cli-0.2.29 → makea_cli-0.2.30}/makea_cli/commands/analytics/cmd.py +0 -0
  30. {makea_cli-0.2.29 → makea_cli-0.2.30}/makea_cli/commands/auth/__init__.py +0 -0
  31. {makea_cli-0.2.29 → makea_cli-0.2.30}/makea_cli/commands/auth/cmd.py +0 -0
  32. {makea_cli-0.2.29 → makea_cli-0.2.30}/makea_cli/commands/brand/__init__.py +0 -0
  33. {makea_cli-0.2.29 → makea_cli-0.2.30}/makea_cli/commands/brand/cmd.py +0 -0
  34. {makea_cli-0.2.29 → makea_cli-0.2.30}/makea_cli/commands/designer/__init__.py +0 -0
  35. {makea_cli-0.2.29 → makea_cli-0.2.30}/makea_cli/commands/designer/cmd.py +0 -0
  36. {makea_cli-0.2.29 → makea_cli-0.2.30}/makea_cli/commands/directory/__init__.py +0 -0
  37. {makea_cli-0.2.29 → makea_cli-0.2.30}/makea_cli/commands/directory/cmd.py +0 -0
  38. {makea_cli-0.2.29 → makea_cli-0.2.30}/makea_cli/commands/document/__init__.py +0 -0
  39. {makea_cli-0.2.29 → makea_cli-0.2.30}/makea_cli/commands/document/cmd.py +0 -0
  40. {makea_cli-0.2.29 → makea_cli-0.2.30}/makea_cli/commands/email/__init__.py +0 -0
  41. {makea_cli-0.2.29 → makea_cli-0.2.30}/makea_cli/commands/email/cmd.py +0 -0
  42. {makea_cli-0.2.29 → makea_cli-0.2.30}/makea_cli/commands/factory/__init__.py +0 -0
  43. {makea_cli-0.2.29 → makea_cli-0.2.30}/makea_cli/commands/factory/cmd.py +0 -0
  44. {makea_cli-0.2.29 → makea_cli-0.2.30}/makea_cli/commands/files/__init__.py +0 -0
  45. {makea_cli-0.2.29 → makea_cli-0.2.30}/makea_cli/commands/flags/__init__.py +0 -0
  46. {makea_cli-0.2.29 → makea_cli-0.2.30}/makea_cli/commands/flags/cmd.py +0 -0
  47. {makea_cli-0.2.29 → makea_cli-0.2.30}/makea_cli/commands/library/__init__.py +0 -0
  48. {makea_cli-0.2.29 → makea_cli-0.2.30}/makea_cli/commands/library/cmd.py +0 -0
  49. {makea_cli-0.2.29 → makea_cli-0.2.30}/makea_cli/commands/metrics/__init__.py +0 -0
  50. {makea_cli-0.2.29 → makea_cli-0.2.30}/makea_cli/commands/metrics/cmd.py +0 -0
  51. {makea_cli-0.2.29 → makea_cli-0.2.30}/makea_cli/commands/orders/__init__.py +0 -0
  52. {makea_cli-0.2.29 → makea_cli-0.2.30}/makea_cli/commands/orders/cmd.py +0 -0
  53. {makea_cli-0.2.29 → makea_cli-0.2.30}/makea_cli/commands/playbook/__init__.py +0 -0
  54. {makea_cli-0.2.29 → makea_cli-0.2.30}/makea_cli/commands/playbook/cmd.py +0 -0
  55. {makea_cli-0.2.29 → makea_cli-0.2.30}/makea_cli/commands/product/__init__.py +0 -0
  56. {makea_cli-0.2.29 → makea_cli-0.2.30}/makea_cli/commands/product/cmd.py +0 -0
  57. {makea_cli-0.2.29 → makea_cli-0.2.30}/makea_cli/commands/production/__init__.py +0 -0
  58. {makea_cli-0.2.29 → makea_cli-0.2.30}/makea_cli/commands/production/cmd.py +0 -0
  59. {makea_cli-0.2.29 → makea_cli-0.2.30}/makea_cli/commands/production/pricing_spec.py +0 -0
  60. {makea_cli-0.2.29 → makea_cli-0.2.30}/makea_cli/commands/shipping/__init__.py +0 -0
  61. {makea_cli-0.2.29 → makea_cli-0.2.30}/makea_cli/commands/shipping/cmd.py +0 -0
  62. {makea_cli-0.2.29 → makea_cli-0.2.30}/makea_cli/commands/supplier/__init__.py +0 -0
  63. {makea_cli-0.2.29 → makea_cli-0.2.30}/makea_cli/commands/supplier/cmd.py +0 -0
  64. {makea_cli-0.2.29 → makea_cli-0.2.30}/makea_cli/commands/tasks/__init__.py +0 -0
  65. {makea_cli-0.2.29 → makea_cli-0.2.30}/makea_cli/commands/tasks/cmd.py +0 -0
  66. {makea_cli-0.2.29 → makea_cli-0.2.30}/makea_cli/companion.py +0 -0
  67. {makea_cli-0.2.29 → makea_cli-0.2.30}/makea_cli/config.py +0 -0
  68. {makea_cli-0.2.29 → makea_cli-0.2.30}/makea_cli/errors.py +0 -0
  69. {makea_cli-0.2.29 → makea_cli-0.2.30}/makea_cli/identity.py +0 -0
  70. {makea_cli-0.2.29 → makea_cli-0.2.30}/makea_cli/main.py +0 -0
  71. {makea_cli-0.2.29 → makea_cli-0.2.30}/makea_cli/output.py +0 -0
  72. {makea_cli-0.2.29 → makea_cli-0.2.30}/makea_cli/posthog_client.py +0 -0
  73. {makea_cli-0.2.29 → makea_cli-0.2.30}/makea_cli/registry.py +0 -0
  74. {makea_cli-0.2.29 → makea_cli-0.2.30}/npm/makea-cli/README.md +0 -0
  75. {makea_cli-0.2.29 → makea_cli-0.2.30}/npm/makea-cli/makea-cli.mjs +0 -0
  76. {makea_cli-0.2.29 → makea_cli-0.2.30}/npm/makea-cli/package.json +0 -0
  77. {makea_cli-0.2.29 → makea_cli-0.2.30}/tests/test_broker.py +0 -0
  78. {makea_cli-0.2.29 → makea_cli-0.2.30}/tests/test_companion.py +0 -0
  79. {makea_cli-0.2.29 → makea_cli-0.2.30}/tests/test_currency_conversion.py +0 -0
  80. {makea_cli-0.2.29 → makea_cli-0.2.30}/tests/test_output_contract.py +0 -0
  81. {makea_cli-0.2.29 → makea_cli-0.2.30}/tests/test_persona_commands.py +0 -0
  82. {makea_cli-0.2.29 → makea_cli-0.2.30}/tests/test_pm_reads.py +0 -0
  83. {makea_cli-0.2.29 → makea_cli-0.2.30}/tests/test_registry.py +0 -0
  84. {makea_cli-0.2.29 → makea_cli-0.2.30}/tests/test_supplier_scorecard.py +0 -0
  85. {makea_cli-0.2.29 → makea_cli-0.2.30}/uv.lock +0 -0
@@ -1,5 +1,17 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.2.30
4
+
5
+ Read HP-GL plot files (.plt), the pattern or marker a CAD sends to a cutting
6
+ plotter (TECH-148).
7
+
8
+ - A PLT reads as its size in cm (40 plotter units to the mm), its pens and the
9
+ text plotted on it (piece names and sizes), with a drawing of the plot.
10
+ PCL/PJL-wrapped HP-GL/2 opens too, with or without the extension.
11
+ - Labels are decoded together, so a one-character GBK piece name (领, 前) is
12
+ read as Chinese rather than as Latin letters.
13
+ - A .plt in another plotter language says to send a DXF + RUL instead.
14
+
3
15
  ## 0.2.29
4
16
 
5
17
  The file reader stays inside a web worker's memory (TECH-145).
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: makea-cli
3
- Version: 0.2.29
3
+ Version: 0.2.30
4
4
  Summary: Makea admin CLI (browser login + Makea admin HTTP API)
5
5
  Requires-Python: >=3.10
6
6
  Requires-Dist: click<9,>=8.1
@@ -122,7 +122,7 @@ exit code:`0` 成功 · `2` 用法错 · `3` 未登录或身份与 persona 不
122
122
  | `makea-cli admin get about` | read | `GET /admin/about/{target}` | one account's About you (`--user`: a supplier account's person gets their factory's page; `--supplier`): facts, removed, unknown, paused, topic keys. | — |
123
123
  | `makea-cli admin get active-users` | read | `POST /admin/analytics/query` | Distinct active users per day over the last N days (DAU series). | `analytics-active-users` |
124
124
  | `makea-cli admin get analytics-query` | read | `POST /admin/analytics/query` | Run an arbitrary HogQL query (escape hatch). Example: analytics-query "SELECT count() FROM events" | `analytics-query` |
125
- | `makea-cli admin get file` | read | local (makea_cli.file_reader) | read a pattern (DXF/RUL), artwork (AI/EPS/PSD/SVG), embroidery (PES/DST/EMB), ZIP or AVIF/TIFF file on this machine; saves PNG pictures of what it draws next to it. No API call. | — |
125
+ | `makea-cli admin get file` | read | local (makea_cli.file_reader) | read a pattern (DXF/RUL/PLT), artwork (AI/EPS/PSD/SVG), embroidery (PES/DST/EMB), ZIP or AVIF/TIFF file on this machine; saves PNG pictures of what it draws next to it. No API call. | — |
126
126
  | `makea-cli admin get currency-conversion` | read | `GET /admin/fx/rates` | the platform's own exchange rates and rounding (rate table for several --from; one --from with --amount converts it). | `convert-currency` |
127
127
  | `makea-cli admin get feature-usage` | read | `POST /admin/analytics/query` | How many distinct users used a feature recently, plus event volume. Matches $pageview path and feature_time_spent eve… | `analytics-feature-usage` |
128
128
  | `makea-cli admin get growth-snapshot` | read | `GET /admin/growth/snapshots/{id}` | one reconciled Growth Analysis snapshot (default `latest`); `--block` prints one block (headline, gates, review_items, …). | — |
@@ -207,7 +207,7 @@ exit code:`0` 成功 · `2` 用法错 · `3` 未登录或身份与 persona 不
207
207
  | `makea-cli designer delete sampling-order` | write(never) | `DELETE /designer/sampling_orders/{sampling_order_id}` | delete a DRAFT sample order. The backend refuses any other status. Graded `never`. | — |
208
208
  | `makea-cli designer delete shipping-order` | write(never) | `POST /designer/shipping_orders/{shipping_order_id}/cancel` | the endpoint is called cancel but it unlinks every production order and removes the shipment, so it is a delete here.… | — |
209
209
  | `makea-cli designer download document` | read | `GET /designer/document/download` | save bytes for user_id + document_id (designer-authenticated; same query contract as admin document download). | `designer-download-document` |
210
- | `makea-cli designer get file` | read | local (makea_cli.file_reader) | read a pattern (DXF/RUL), artwork (AI/EPS/PSD/SVG), embroidery (PES/DST/EMB), ZIP or AVIF/TIFF file on this machine; saves PNG pictures of what it draws next to it. No API call. | — |
210
+ | `makea-cli designer get file` | read | local (makea_cli.file_reader) | read a pattern (DXF/RUL/PLT), artwork (AI/EPS/PSD/SVG), embroidery (PES/DST/EMB), ZIP or AVIF/TIFF file on this machine; saves PNG pictures of what it draws next to it. No API call. | — |
211
211
  | `makea-cli designer get collection` | read | `GET /designer/collections/{collection_id}/overview` | one collection with its products, orders and lifecycle in a single read. | — |
212
212
  | `makea-cli designer get lifecycle` | read | `GET /designer/product_orders/{product_order_id}/lifecycle` | which stage this product is in. | — |
213
213
  | `makea-cli designer get product` | read | `GET /designer/get_product` | one product: status, documents, prices, links. | — |
@@ -251,7 +251,7 @@ exit code:`0` 成功 · `2` 用法错 · `3` 未登录或身份与 persona 不
251
251
  |---|---|---|---|---|
252
252
  | `makea-cli supplier create note` | write(ask) | `POST /supplier/products/{id}/channels/{key}/notes` | post a message into a product channel you are part of. | — |
253
253
  | `makea-cli supplier download document` | read | `GET /supplier/document/download` | save a document you are allowed to read. | — |
254
- | `makea-cli supplier get file` | read | local (makea_cli.file_reader) | read a pattern (DXF/RUL), artwork (AI/EPS/PSD/SVG), embroidery (PES/DST/EMB), ZIP or AVIF/TIFF file on this machine; saves PNG pictures of what it draws next to it. No API call. | — |
254
+ | `makea-cli supplier get file` | read | local (makea_cli.file_reader) | read a pattern (DXF/RUL/PLT), artwork (AI/EPS/PSD/SVG), embroidery (PES/DST/EMB), ZIP or AVIF/TIFF file on this machine; saves PNG pictures of what it draws next to it. No API call. | — |
255
255
  | `makea-cli supplier get pack` | read | `GET /supplier/quote_requests/{id}/technical-specifications` | the tech pack for an RFQ, as the factory is allowed to see it (`--readable`: labels, values and blank essentials only). | — |
256
256
  | `makea-cli supplier get pack-changes` | read | `GET /supplier/products/{product_id}/specification-change-history` | what changed in the pack since you quoted, field by field. | — |
257
257
  | `makea-cli supplier get profile` | read | `GET /supplier/profile` | your own supplier profile. | — |
@@ -106,7 +106,7 @@ exit code:`0` 成功 · `2` 用法错 · `3` 未登录或身份与 persona 不
106
106
  | `makea-cli admin get about` | read | `GET /admin/about/{target}` | one account's About you (`--user`: a supplier account's person gets their factory's page; `--supplier`): facts, removed, unknown, paused, topic keys. | — |
107
107
  | `makea-cli admin get active-users` | read | `POST /admin/analytics/query` | Distinct active users per day over the last N days (DAU series). | `analytics-active-users` |
108
108
  | `makea-cli admin get analytics-query` | read | `POST /admin/analytics/query` | Run an arbitrary HogQL query (escape hatch). Example: analytics-query "SELECT count() FROM events" | `analytics-query` |
109
- | `makea-cli admin get file` | read | local (makea_cli.file_reader) | read a pattern (DXF/RUL), artwork (AI/EPS/PSD/SVG), embroidery (PES/DST/EMB), ZIP or AVIF/TIFF file on this machine; saves PNG pictures of what it draws next to it. No API call. | — |
109
+ | `makea-cli admin get file` | read | local (makea_cli.file_reader) | read a pattern (DXF/RUL/PLT), artwork (AI/EPS/PSD/SVG), embroidery (PES/DST/EMB), ZIP or AVIF/TIFF file on this machine; saves PNG pictures of what it draws next to it. No API call. | — |
110
110
  | `makea-cli admin get currency-conversion` | read | `GET /admin/fx/rates` | the platform's own exchange rates and rounding (rate table for several --from; one --from with --amount converts it). | `convert-currency` |
111
111
  | `makea-cli admin get feature-usage` | read | `POST /admin/analytics/query` | How many distinct users used a feature recently, plus event volume. Matches $pageview path and feature_time_spent eve… | `analytics-feature-usage` |
112
112
  | `makea-cli admin get growth-snapshot` | read | `GET /admin/growth/snapshots/{id}` | one reconciled Growth Analysis snapshot (default `latest`); `--block` prints one block (headline, gates, review_items, …). | — |
@@ -191,7 +191,7 @@ exit code:`0` 成功 · `2` 用法错 · `3` 未登录或身份与 persona 不
191
191
  | `makea-cli designer delete sampling-order` | write(never) | `DELETE /designer/sampling_orders/{sampling_order_id}` | delete a DRAFT sample order. The backend refuses any other status. Graded `never`. | — |
192
192
  | `makea-cli designer delete shipping-order` | write(never) | `POST /designer/shipping_orders/{shipping_order_id}/cancel` | the endpoint is called cancel but it unlinks every production order and removes the shipment, so it is a delete here.… | — |
193
193
  | `makea-cli designer download document` | read | `GET /designer/document/download` | save bytes for user_id + document_id (designer-authenticated; same query contract as admin document download). | `designer-download-document` |
194
- | `makea-cli designer get file` | read | local (makea_cli.file_reader) | read a pattern (DXF/RUL), artwork (AI/EPS/PSD/SVG), embroidery (PES/DST/EMB), ZIP or AVIF/TIFF file on this machine; saves PNG pictures of what it draws next to it. No API call. | — |
194
+ | `makea-cli designer get file` | read | local (makea_cli.file_reader) | read a pattern (DXF/RUL/PLT), artwork (AI/EPS/PSD/SVG), embroidery (PES/DST/EMB), ZIP or AVIF/TIFF file on this machine; saves PNG pictures of what it draws next to it. No API call. | — |
195
195
  | `makea-cli designer get collection` | read | `GET /designer/collections/{collection_id}/overview` | one collection with its products, orders and lifecycle in a single read. | — |
196
196
  | `makea-cli designer get lifecycle` | read | `GET /designer/product_orders/{product_order_id}/lifecycle` | which stage this product is in. | — |
197
197
  | `makea-cli designer get product` | read | `GET /designer/get_product` | one product: status, documents, prices, links. | — |
@@ -235,7 +235,7 @@ exit code:`0` 成功 · `2` 用法错 · `3` 未登录或身份与 persona 不
235
235
  |---|---|---|---|---|
236
236
  | `makea-cli supplier create note` | write(ask) | `POST /supplier/products/{id}/channels/{key}/notes` | post a message into a product channel you are part of. | — |
237
237
  | `makea-cli supplier download document` | read | `GET /supplier/document/download` | save a document you are allowed to read. | — |
238
- | `makea-cli supplier get file` | read | local (makea_cli.file_reader) | read a pattern (DXF/RUL), artwork (AI/EPS/PSD/SVG), embroidery (PES/DST/EMB), ZIP or AVIF/TIFF file on this machine; saves PNG pictures of what it draws next to it. No API call. | — |
238
+ | `makea-cli supplier get file` | read | local (makea_cli.file_reader) | read a pattern (DXF/RUL/PLT), artwork (AI/EPS/PSD/SVG), embroidery (PES/DST/EMB), ZIP or AVIF/TIFF file on this machine; saves PNG pictures of what it draws next to it. No API call. | — |
239
239
  | `makea-cli supplier get pack` | read | `GET /supplier/quote_requests/{id}/technical-specifications` | the tech pack for an RFQ, as the factory is allowed to see it (`--readable`: labels, values and blank essentials only). | — |
240
240
  | `makea-cli supplier get pack-changes` | read | `GET /supplier/products/{product_id}/specification-change-history` | what changed in the pack since you quoted, field by field. | — |
241
241
  | `makea-cli supplier get profile` | read | `GET /supplier/profile` | your own supplier profile. | — |
@@ -0,0 +1 @@
1
+ __version__ = "0.2.30"
@@ -1,6 +1,6 @@
1
1
  """``makea-cli <persona> get file PATH``: read a file a brand sent, locally.
2
2
 
3
- Pattern DXF/RUL, Illustrator, EPS, Photoshop, embroidery (PES/DST/EMB), ZIP,
3
+ Pattern DXF/RUL/PLT, Illustrator, EPS, Photoshop, embroidery (PES/DST/EMB), ZIP,
4
4
  AVIF/TIFF/SVG. No API call: the file never leaves the machine. Pictures of what
5
5
  the file draws are saved next to it so the caller can look at them (an agent
6
6
  reads them with its image tool).
@@ -21,7 +21,7 @@ from makea_cli.registry import command
21
21
  console = Console()
22
22
 
23
23
  _HELP = (
24
- "Read a pattern (DXF/RUL), artwork (AI/EPS/PSD/SVG), embroidery (PES/DST/EMB), ZIP or "
24
+ "Read a pattern (DXF/RUL/PLT), artwork (AI/EPS/PSD/SVG), embroidery (PES/DST/EMB), ZIP or "
25
25
  "AVIF/TIFF file on this machine: what it states plus PNG pictures of what it draws."
26
26
  )
27
27
 
@@ -1071,6 +1071,261 @@ def _read_rul(data: bytes, name: str, depth: int) -> Reading:
1071
1071
  return Reading("grade-rules", "RUL", " ".join(lines) + "\n\n```\n" + text[:6000] + "\n```")
1072
1072
 
1073
1073
 
1074
+ # ── Pattern: HPGL plot files (.plt) ──────────────────────────────────────
1075
+ #
1076
+ # What a pattern CAD sends to a cutting or marker plotter: pen-up / pen-down
1077
+ # moves in plotter units (40 to the mm), with piece names and sizes as LB text.
1078
+ # A plot has no pieces, only strokes, so it says what it draws and how big; the
1079
+ # piece table comes from the DXF.
1080
+
1081
+ _HPGL_EXTS = (".plt", ".hpgl", ".hpg", ".hgl")
1082
+ _HPGL_UNITS_PER_MM = 40.0
1083
+ # A full marker is millions of moves; past this the drawing is cut short (and
1084
+ # says so) so a read stays bounded in time and memory.
1085
+ _HPGL_MAX_POINTS = 2_000_000
1086
+ _HPGL_CMD = re.compile(rb"[A-Za-z]{2}")
1087
+ _HPGL_NUM = re.compile(rb"[-+]?(?:\d+\.?\d*|\.\d+)")
1088
+ # PCL / PJL wrapping around HP-GL/2: "ESC%-12345X@PJL ...", "ESC%1B", "ESCE".
1089
+ _PCL_ESCAPE = re.compile(rb"\x1b(?:%-12345X|%-?\d*[AB]|E|\*[a-z]\d*[A-Z])|@PJL[^\n]*\n?")
1090
+
1091
+
1092
+ def _is_hpgl(head: bytes, ext: str) -> bool:
1093
+ if ext in _HPGL_EXTS:
1094
+ return True
1095
+ h = _PCL_ESCAPE.sub(b"", head).lstrip(b"\x00\r\n\t ;")
1096
+ return bool(re.match(rb"(?:IN|DF)\s*;\s*(?:[A-Z]{2}[^;]*;\s*){0,6}(?:SP|PU|PD|PA)", h))
1097
+
1098
+
1099
+ @dataclass
1100
+ class _Plot:
1101
+ strokes: List[Tuple[int, List[Tuple[float, float]]]] = field(
1102
+ default_factory=list
1103
+ ) # (pen, points)
1104
+ labels: List[str] = field(default_factory=list)
1105
+ raw_labels: List[bytes] = field(default_factory=list)
1106
+ points: int = 0
1107
+ truncated: bool = False
1108
+ scaled: bool = False
1109
+ pens: List[int] = field(default_factory=list)
1110
+
1111
+
1112
+ _HPGL_ABS_POINTS = (b"EA", b"RA")
1113
+ _HPGL_REL_POINTS = (b"PR", b"ER", b"RR", b"AR")
1114
+
1115
+
1116
+ def _hpgl_to_plotter(cmd: bytes, params: List[float], absolute: bool, t) -> List[float]:
1117
+ """A command's coordinates from user units (after SC) to plotter units."""
1118
+ fx, fy, ox, oy = t
1119
+ if cmd == b"CI":
1120
+ return [params[0] * fx] + params[1:] if params else params
1121
+ if cmd in (b"AA", b"AR"):
1122
+ # Centre then sweep angle (degrees) and chord tolerance: only the
1123
+ # centre is a coordinate.
1124
+ head = _hpgl_to_plotter(b"PA" if cmd == b"AA" else b"PR", params[:2], True, t)
1125
+ return head + params[2:]
1126
+ is_abs = cmd == b"PA" or cmd in _HPGL_ABS_POINTS or (cmd in (b"PU", b"PD") and absolute)
1127
+ if not is_abs and cmd not in _HPGL_REL_POINTS + (b"PU", b"PD"):
1128
+ return params
1129
+ if is_abs:
1130
+ return [(ox + v * fx) if k % 2 == 0 else (oy + v * fy) for k, v in enumerate(params)]
1131
+ return [v * (fx if k % 2 == 0 else fy) for k, v in enumerate(params)]
1132
+
1133
+
1134
+ def _parse_hpgl(data: bytes) -> _Plot:
1135
+ """A small HP-GL / HP-GL/2 interpreter: PU PD PA PR, SP, LB (and DT),
1136
+ IP + SC scaling, CI and the rectangles. Anything else is skipped; arcs are
1137
+ joined as chords. Everything is kept in plotter units (40 to the mm)."""
1138
+ data = _PCL_ESCAPE.sub(b"", data)
1139
+ plot = _Plot()
1140
+ x = y = 0.0
1141
+ # User units -> plotter units: X = ox + x * fx. Identity until SC maps the
1142
+ # IP points (some CADs plot in 1/1000 inch: IP0,0,1016,1016;SC0,1000,0,1000).
1143
+ ip: Optional[Tuple[float, float, float, float]] = None
1144
+ fx = fy = 1.0
1145
+ ox = oy = 0.0
1146
+ absolute, pen_down, pen = True, False, 1
1147
+ cur: Optional[List[Tuple[float, float]]] = None
1148
+ label_end = b"\x03"
1149
+ n = len(data)
1150
+ i = 0
1151
+
1152
+ def start():
1153
+ nonlocal cur
1154
+ cur = [(x, y)]
1155
+ plot.strokes.append((pen, cur))
1156
+
1157
+ def move(nx: float, ny: float):
1158
+ nonlocal x, y, cur
1159
+ if plot.points >= _HPGL_MAX_POINTS:
1160
+ plot.truncated = True
1161
+ x, y = nx, ny
1162
+ return
1163
+ if pen_down:
1164
+ if cur is None:
1165
+ start()
1166
+ cur.append((nx, ny))
1167
+ plot.points += 1
1168
+ else:
1169
+ cur = None
1170
+ x, y = nx, ny
1171
+
1172
+ while i < n:
1173
+ m = _HPGL_CMD.search(data, i)
1174
+ if not m:
1175
+ break
1176
+ cmd = m.group().upper()
1177
+ i = m.end()
1178
+ if cmd == b"LB":
1179
+ end = data.find(label_end, i)
1180
+ end = n if end < 0 else end
1181
+ plot.raw_labels.append(data[i:end])
1182
+ i = end + len(label_end)
1183
+ continue
1184
+ if cmd == b"DT":
1185
+ j = i
1186
+ while j < n and data[j : j + 1] in (b" ", b"\t"):
1187
+ j += 1
1188
+ if j < n and data[j : j + 1] not in (b";",):
1189
+ label_end = data[j : j + 1]
1190
+ i = j + 1
1191
+ continue
1192
+ # Parameters run to the next command letter or ';'.
1193
+ j = i
1194
+ while j < n and not (data[j : j + 1].isalpha() or data[j : j + 1] == b";"):
1195
+ j += 1
1196
+ params = [float(v) for v in _HPGL_NUM.findall(data[i:j])]
1197
+ i = j + 1 if j < n and data[j : j + 1] == b";" else j
1198
+ if (fx, fy, ox, oy) != (1.0, 1.0, 0.0, 0.0):
1199
+ params = _hpgl_to_plotter(cmd, params, absolute, (fx, fy, ox, oy))
1200
+ if cmd in (b"PU", b"PD", b"PA", b"PR"):
1201
+ if cmd == b"PU":
1202
+ pen_down = False
1203
+ cur = None
1204
+ elif cmd == b"PD":
1205
+ pen_down = True
1206
+ elif cmd == b"PA":
1207
+ absolute = True
1208
+ else:
1209
+ absolute = False
1210
+ for k in range(0, len(params) - 1, 2):
1211
+ nx, ny = params[k], params[k + 1]
1212
+ move(nx, ny) if absolute else move(x + nx, y + ny)
1213
+ elif cmd == b"SP":
1214
+ pen = int(params[0]) if params else 0
1215
+ cur = None
1216
+ if pen and pen not in plot.pens:
1217
+ plot.pens.append(pen)
1218
+ elif cmd == b"CI" and params:
1219
+ r = params[0]
1220
+ cx, cy = x, y
1221
+ ring = [
1222
+ (cx + r * math.cos(t / 24 * 2 * math.pi), cy + r * math.sin(t / 24 * 2 * math.pi))
1223
+ for t in range(25)
1224
+ ]
1225
+ plot.strokes.append((pen, ring))
1226
+ plot.points += len(ring)
1227
+ elif cmd in (b"EA", b"ER", b"RA", b"RR") and len(params) >= 2:
1228
+ x1, y1 = (
1229
+ (params[0], params[1]) if cmd in (b"EA", b"RA") else (x + params[0], y + params[1])
1230
+ )
1231
+ plot.strokes.append((pen, [(x, y), (x1, y), (x1, y1), (x, y1), (x, y)]))
1232
+ plot.points += 5
1233
+ elif cmd in (b"AA", b"AR") and len(params) >= 3:
1234
+ cx, cy = (params[0], params[1]) if cmd == b"AA" else (x + params[0], y + params[1])
1235
+ r = math.hypot(x - cx, y - cy)
1236
+ a0 = math.atan2(y - cy, x - cx)
1237
+ sweep = math.radians(params[2])
1238
+ steps = max(2, int(abs(params[2]) / 10))
1239
+ for k in range(1, steps + 1):
1240
+ a = a0 + sweep * k / steps
1241
+ move(cx + r * math.cos(a), cy + r * math.sin(a))
1242
+ elif cmd == b"IP":
1243
+ ip = tuple(params[:4]) if len(params) >= 4 else None
1244
+ elif cmd == b"SC":
1245
+ if len(params) >= 4 and ip and params[1] != params[0] and params[3] != params[2]:
1246
+ fx = (ip[2] - ip[0]) / (params[1] - params[0])
1247
+ fy = (ip[3] - ip[1]) / (params[3] - params[2])
1248
+ ox, oy = ip[0] - params[0] * fx, ip[1] - params[2] * fy
1249
+ elif len(params) >= 4:
1250
+ plot.scaled = True # scaled against the plotter's own P1/P2: size unknown
1251
+ else:
1252
+ fx = fy = 1.0
1253
+ ox = oy = 0.0
1254
+ elif cmd == b"IN":
1255
+ absolute, pen_down, cur = True, False, None
1256
+ ip, fx, fy, ox, oy = None, 1.0, 1.0, 0.0, 0.0
1257
+ plot.strokes = [(p, pts) for p, pts in plot.strokes if len(pts) > 1]
1258
+ # One encoding for every label, decided on all of them together: a
1259
+ # one-character GBK piece name (领, 前) is no evidence on its own and
1260
+ # reads as Latin or as valid UTF-8 nonsense.
1261
+ joined = _decode_text(b"\x00".join(plot.raw_labels))
1262
+ plot.labels = [t.replace("\r", " ").replace("\n", " ").strip() for t in joined.split("\x00")]
1263
+ plot.labels = [t for t in plot.labels if t]
1264
+ return plot
1265
+
1266
+
1267
+ def _read_hpgl(data: bytes, name: str, depth: int) -> Reading:
1268
+ ext = os.path.splitext(name.lower())[1]
1269
+ plot = _parse_hpgl(data)
1270
+ if not plot.strokes:
1271
+ return Reading(
1272
+ "pattern",
1273
+ _format_label(ext),
1274
+ f"{_format_label(ext)} file with no HP-GL drawing in it; it may be a plot file in "
1275
+ "another plotter language. To have it read, send an AAMA/ASTM DXF + RUL export "
1276
+ "of the pattern, or a PDF of the pieces.",
1277
+ readable=False,
1278
+ )
1279
+ pts = [p for _pen, s in plot.strokes for p in s]
1280
+ x0, y0, x1, y1 = _bbox(pts)
1281
+ labels = list(dict.fromkeys(plot.labels))
1282
+ head = ["HP-GL plot file: a pattern or marker as sent to a cutting plotter."]
1283
+ if plot.scaled:
1284
+ head.append(
1285
+ f"It sets its own drawing scale, so its size is in its own units: "
1286
+ f"{_fmt(x1 - x0)} x {_fmt(y1 - y0)}."
1287
+ )
1288
+ else:
1289
+ w_cm = (x1 - x0) / _HPGL_UNITS_PER_MM / 10
1290
+ h_cm = (y1 - y0) / _HPGL_UNITS_PER_MM / 10
1291
+ head.append(f"It draws {_fmt(w_cm)} x {_fmt(h_cm)} cm (40 plotter units to the mm).")
1292
+ head.append(
1293
+ f"{len(plot.strokes)} line(s), {plot.points} point(s), pen(s) {', '.join(map(str, plot.pens)) or '1'}."
1294
+ )
1295
+ if plot.truncated:
1296
+ head.append(f"Only the first {_HPGL_MAX_POINTS} points were read.")
1297
+ body = " ".join(head)
1298
+ if labels:
1299
+ shown = labels[:80]
1300
+ body += "\n\nText in the plot (piece names, sizes and notes, in plot order):\n" + "\n".join(
1301
+ f"- {t}" for t in shown
1302
+ )
1303
+ if len(labels) > len(shown):
1304
+ body += f"\n- … and {len(labels) - len(shown)} more"
1305
+ body += (
1306
+ "\n\nA plot file has no pattern pieces, only strokes, so piece sizes, seam "
1307
+ "allowance and grading are not stated; those come from the DXF + RUL."
1308
+ )
1309
+ return Reading("pattern", _format_label(ext), body, _draw_hpgl(plot, (x0, y0, x1, y1)))
1310
+
1311
+
1312
+ def _draw_hpgl(plot: _Plot, bb: Tuple[float, float, float, float]) -> List[Picture]:
1313
+ Image = _pil()
1314
+ if not Image:
1315
+ return []
1316
+ from PIL import ImageDraw # noqa: PLC0415
1317
+
1318
+ w, h = max(bb[2] - bb[0], 1e-6), max(bb[3] - bb[1], 1e-6)
1319
+ scale = (_PICTURE_SIDE - 40) / max(w, h)
1320
+ im = Image.new("RGB", (max(1, int(w * scale) + 40), max(1, int(h * scale) + 40)), "white")
1321
+ draw = ImageDraw.Draw(im)
1322
+ colours = ["#111111", "#d0021b", "#4a90e2", "#2e7d32", "#9b9b9b", "#5a12c4", "#e68a00"]
1323
+ for pen, pts in plot.strokes:
1324
+ xy = [(20 + (px - bb[0]) * scale, 20 + (bb[3] - py) * scale) for px, py in pts]
1325
+ draw.line(xy, fill=colours[(max(pen, 1) - 1) % len(colours)], width=2)
1326
+ return [Picture("plot (each pen in its own colour)", _png(im))]
1327
+
1328
+
1074
1329
  # ── Archives ─────────────────────────────────────────────────────────────
1075
1330
 
1076
1331
 
@@ -1266,6 +1521,7 @@ _READERS: List[Tuple[Callable[[bytes, str], bool], Callable[[bytes, str, int], R
1266
1521
  (_is_stitch, _read_stitch),
1267
1522
  (_is_rul, _read_rul),
1268
1523
  (_is_dxf, _read_dxf),
1524
+ (_is_hpgl, _read_hpgl),
1269
1525
  (_is_zip, _read_zip),
1270
1526
  (_is_svg, _read_svg),
1271
1527
  (_is_image, _read_image),
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "makea-cli"
7
- version = "0.2.29"
7
+ version = "0.2.30"
8
8
  description = "Makea admin CLI (browser login + Makea admin HTTP API)"
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.10"
@@ -2483,7 +2483,7 @@
2483
2483
  "idempotent": null,
2484
2484
  "limit": null,
2485
2485
  "legacy": [],
2486
- "help": "Read a pattern (DXF/RUL), artwork (AI/EPS/PSD/SVG), embroidery (PES/DST/EMB), ZIP or AVIF/TIFF file on this machine: what it states plus PNG pictures of what it draws.",
2486
+ "help": "Read a pattern (DXF/RUL/PLT), artwork (AI/EPS/PSD/SVG), embroidery (PES/DST/EMB), ZIP or AVIF/TIFF file on this machine: what it states plus PNG pictures of what it draws.",
2487
2487
  "function": "makea_cli.commands.files.cmd._register_for.<locals>.get_file",
2488
2488
  "flags": [
2489
2489
  {
@@ -9017,7 +9017,7 @@
9017
9017
  "idempotent": null,
9018
9018
  "limit": null,
9019
9019
  "legacy": [],
9020
- "help": "Read a pattern (DXF/RUL), artwork (AI/EPS/PSD/SVG), embroidery (PES/DST/EMB), ZIP or AVIF/TIFF file on this machine: what it states plus PNG pictures of what it draws.",
9020
+ "help": "Read a pattern (DXF/RUL/PLT), artwork (AI/EPS/PSD/SVG), embroidery (PES/DST/EMB), ZIP or AVIF/TIFF file on this machine: what it states plus PNG pictures of what it draws.",
9021
9021
  "function": "makea_cli.commands.files.cmd._register_for.<locals>.get_file",
9022
9022
  "flags": [
9023
9023
  {
@@ -10871,7 +10871,7 @@
10871
10871
  "idempotent": null,
10872
10872
  "limit": null,
10873
10873
  "legacy": [],
10874
- "help": "Read a pattern (DXF/RUL), artwork (AI/EPS/PSD/SVG), embroidery (PES/DST/EMB), ZIP or AVIF/TIFF file on this machine: what it states plus PNG pictures of what it draws.",
10874
+ "help": "Read a pattern (DXF/RUL/PLT), artwork (AI/EPS/PSD/SVG), embroidery (PES/DST/EMB), ZIP or AVIF/TIFF file on this machine: what it states plus PNG pictures of what it draws.",
10875
10875
  "function": "makea_cli.commands.files.cmd._register_for.<locals>.get_file",
10876
10876
  "flags": [
10877
10877
  {
@@ -100,6 +100,72 @@ def _palette_alpha_tiff() -> bytes:
100
100
  return bytes(raw)
101
101
 
102
102
 
103
+ def _plt() -> bytes:
104
+ """What a Chinese pattern CAD plots: GBK labels, one piece per pen-down run."""
105
+ body = (
106
+ "IN;SP1;PU0,0;PD4000,0,4000,8000,0,8000,0,0;" # 10 x 20 cm piece
107
+ "PU400,400;LB前片 M\x03;"
108
+ "SP2;PU2000,400;PD2000,7600;" # grain line, pen 2
109
+ "SP1;PU6000,0;PR;PD4000,0,0,4000,-4000,0,0,-4000;PA;" # relative square
110
+ "PU6400,400;LB后片 M\x03;PU0,0;SP0;"
111
+ )
112
+ return body.encode("gbk")
113
+
114
+
115
+ class HpglPlotTest(unittest.TestCase):
116
+ def test_reads_size_labels_and_draws(self):
117
+ r = read_bytes(_plt(), "dress.plt")
118
+ self.assertEqual((r.kind, r.format, r.readable), ("pattern", "PLT", True))
119
+ self.assertIn("25.0 x 20.0 cm", r.text)
120
+ self.assertIn("- 前片 M", r.text)
121
+ self.assertIn("- 后片 M", r.text)
122
+ self.assertIn("pen(s) 1, 2", r.text)
123
+ self.assertEqual(len(r.pictures), 1)
124
+ self.assertTrue(r.pictures[0].png.startswith(b"\x89PNG"))
125
+
126
+ def test_pcl_wrapped_hpgl2_without_extension(self):
127
+ data = b"\x1b%-12345X@PJL ENTER LANGUAGE=HPGL2\r\n\x1bE\x1b%1B" + _plt() + b"\x1b%0A\x1bE"
128
+ r = read_bytes(data, "plot")
129
+ self.assertEqual(r.kind, "pattern")
130
+ self.assertIn("25.0 x 20.0 cm", r.text)
131
+
132
+ def test_relative_moves(self):
133
+ r = read_bytes(b"IN;PA;PU0,0;PR;PD400,0;PD0,400;", "a.plt")
134
+ self.assertIn("1.0 x 1.0 cm", r.text)
135
+
136
+ def test_ip_sc_scale_in_thousandths_of_an_inch(self):
137
+ # A 72-inch marker plotted in 1/1000 inch (a real garment CAD export).
138
+ body = b"IN;IP0,0,1016,1016;SC0,1000,0,1000;SP1;PU0,0;PD10000,0,10000,72000,0,72000,0,0;PU;"
139
+ r = read_bytes(body, "72-MLXL2.PLT")
140
+ self.assertIn("25.4 x 183 cm", r.text)
141
+ rel = read_bytes(
142
+ b"IN;IP0,0,1016,1016;SC0,1000,0,1000;PU0,0;PR;PD1000,0;PA;PD1000,1000;", "a.plt"
143
+ )
144
+ self.assertIn("2.5 x 2.5 cm", rel.text)
145
+
146
+ def test_own_scale_is_not_called_cm(self):
147
+ r = read_bytes(b"IN;SC0,100,0,100;PU0,0;PD50,0,50,50;", "a.plt")
148
+ self.assertIn("its own units", r.text)
149
+ self.assertNotIn(" cm ", r.text)
150
+
151
+ def test_plt_in_another_plotter_language(self):
152
+ r = read_bytes(bytes(range(256)) * 4, "cutter.plt")
153
+ self.assertFalse(r.readable)
154
+ self.assertIn("DXF", r.text)
155
+
156
+ def test_one_character_gbk_names_decode_with_the_rest(self):
157
+ body = "IN;PU0,0;PD400,0,400,400;LB领\x03;LB前\x03;LB后裤片\x03;"
158
+ r = read_bytes(body.encode("gbk"), "pants.plt")
159
+ self.assertIn("- 领", r.text)
160
+ self.assertIn("- 前", r.text)
161
+ self.assertIn("- 后裤片", r.text)
162
+
163
+ def test_semicolonless_space_separated(self):
164
+ r = read_bytes(b"IN SP1 PU 0 0 PD 400 0 400 400 PU", "a.hpgl")
165
+ self.assertEqual(r.kind, "pattern")
166
+ self.assertIn("1.0 x 1.0 cm", r.text)
167
+
168
+
103
169
  class EpsTest(unittest.TestCase):
104
170
  def test_illustrator_preview_opens(self):
105
171
  tiff = _palette_alpha_tiff()
@@ -1 +0,0 @@
1
- __version__ = "0.2.29"
File without changes
File without changes
File without changes