mapcan 0.26.0__tar.gz → 0.27.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 (181) hide show
  1. {mapcan-0.26.0 → mapcan-0.27.0}/PKG-INFO +1 -1
  2. {mapcan-0.26.0 → mapcan-0.27.0}/docs/web.md +16 -5
  3. {mapcan-0.26.0 → mapcan-0.27.0}/pyproject.toml +1 -1
  4. {mapcan-0.26.0 → mapcan-0.27.0}/src/mapcan/__init__.py +1 -1
  5. {mapcan-0.26.0 → mapcan-0.27.0}/src/mapcan/launcher.py +11 -3
  6. {mapcan-0.26.0 → mapcan-0.27.0}/src/mapcan/locale/ru.py +3 -0
  7. mapcan-0.27.0/src/mapcan/updates.py +315 -0
  8. {mapcan-0.26.0 → mapcan-0.27.0}/src/mapcan/web/app.py +33 -4
  9. mapcan-0.27.0/src/mapcan/web/static/assets/index-BmUz9-Nm.js +37 -0
  10. mapcan-0.27.0/src/mapcan/web/static/assets/index-D8_yYT3g.css +1 -0
  11. {mapcan-0.26.0 → mapcan-0.27.0}/src/mapcan/web/static/index.html +2 -2
  12. mapcan-0.27.0/tests/test_update_install.py +324 -0
  13. {mapcan-0.26.0 → mapcan-0.27.0}/tests/test_updates.py +5 -4
  14. mapcan-0.26.0/src/mapcan/updates.py +0 -85
  15. mapcan-0.26.0/src/mapcan/web/static/assets/index-DFi-dbfG.css +0 -1
  16. mapcan-0.26.0/src/mapcan/web/static/assets/index-DV8miVDx.js +0 -37
  17. {mapcan-0.26.0 → mapcan-0.27.0}/.gitignore +0 -0
  18. {mapcan-0.26.0 → mapcan-0.27.0}/LICENSE +0 -0
  19. {mapcan-0.26.0 → mapcan-0.27.0}/NOTICE +0 -0
  20. {mapcan-0.26.0 → mapcan-0.27.0}/README.md +0 -0
  21. {mapcan-0.26.0 → mapcan-0.27.0}/THIRD_PARTY_NOTICES.md +0 -0
  22. {mapcan-0.26.0 → mapcan-0.27.0}/docs/ci-example.md +0 -0
  23. {mapcan-0.26.0 → mapcan-0.27.0}/docs/cli.md +0 -0
  24. {mapcan-0.26.0 → mapcan-0.27.0}/docs/format-changelog.md +0 -0
  25. {mapcan-0.26.0 → mapcan-0.27.0}/docs/format.md +0 -0
  26. {mapcan-0.26.0 → mapcan-0.27.0}/docs/images/demo-dark.gif +0 -0
  27. {mapcan-0.26.0 → mapcan-0.27.0}/docs/images/demo-light.gif +0 -0
  28. {mapcan-0.26.0 → mapcan-0.27.0}/docs/images/document-pages-dark.png +0 -0
  29. {mapcan-0.26.0 → mapcan-0.27.0}/docs/images/document-pages-light.png +0 -0
  30. {mapcan-0.26.0 → mapcan-0.27.0}/docs/images/vscode-demo-dark.gif +0 -0
  31. {mapcan-0.26.0 → mapcan-0.27.0}/docs/images/vscode-demo-light.gif +0 -0
  32. {mapcan-0.26.0 → mapcan-0.27.0}/docs/images/vscode-hover-dark.png +0 -0
  33. {mapcan-0.26.0 → mapcan-0.27.0}/docs/images/vscode-hover-light.png +0 -0
  34. {mapcan-0.26.0 → mapcan-0.27.0}/docs/images/vscode-map-dark.png +0 -0
  35. {mapcan-0.26.0 → mapcan-0.27.0}/docs/images/vscode-map-light.png +0 -0
  36. {mapcan-0.26.0 → mapcan-0.27.0}/docs/images/vscode-problems-dark.png +0 -0
  37. {mapcan-0.26.0 → mapcan-0.27.0}/docs/images/vscode-problems-light.png +0 -0
  38. {mapcan-0.26.0 → mapcan-0.27.0}/docs/images/vscode-quickfix-dark.gif +0 -0
  39. {mapcan-0.26.0 → mapcan-0.27.0}/docs/images/vscode-quickfix-light.gif +0 -0
  40. {mapcan-0.26.0 → mapcan-0.27.0}/docs/images/web-frame-dark.png +0 -0
  41. {mapcan-0.26.0 → mapcan-0.27.0}/docs/images/web-frame-light.png +0 -0
  42. {mapcan-0.26.0 → mapcan-0.27.0}/docs/logo-dark.svg +0 -0
  43. {mapcan-0.26.0 → mapcan-0.27.0}/docs/logo-light.svg +0 -0
  44. {mapcan-0.26.0 → mapcan-0.27.0}/docs/templates.md +0 -0
  45. {mapcan-0.26.0 → mapcan-0.27.0}/docs/zephyr.md +0 -0
  46. {mapcan-0.26.0 → mapcan-0.27.0}/examples/canopen-node.yaml +0 -0
  47. {mapcan-0.26.0 → mapcan-0.27.0}/examples/j1939.yaml +0 -0
  48. {mapcan-0.26.0 → mapcan-0.27.0}/examples/minimal.yaml +0 -0
  49. {mapcan-0.26.0 → mapcan-0.27.0}/examples/structures.yaml +0 -0
  50. {mapcan-0.26.0 → mapcan-0.27.0}/examples/tractor/powertrain.yaml +0 -0
  51. {mapcan-0.26.0 → mapcan-0.27.0}/examples/tractor/tractor.yaml +0 -0
  52. {mapcan-0.26.0 → mapcan-0.27.0}/examples/vehicle-can.yaml +0 -0
  53. {mapcan-0.26.0 → mapcan-0.27.0}/examples/zephyr/CMakeLists.txt +0 -0
  54. {mapcan-0.26.0 → mapcan-0.27.0}/examples/zephyr/prj.conf +0 -0
  55. {mapcan-0.26.0 → mapcan-0.27.0}/examples/zephyr/src/main.c +0 -0
  56. {mapcan-0.26.0 → mapcan-0.27.0}/schema/mapcan-part-v1.schema.json +0 -0
  57. {mapcan-0.26.0 → mapcan-0.27.0}/schema/mapcan-part.schema.json +0 -0
  58. {mapcan-0.26.0 → mapcan-0.27.0}/schema/mapcan-v1.schema.json +0 -0
  59. {mapcan-0.26.0 → mapcan-0.27.0}/schema/mapcan.schema.json +0 -0
  60. {mapcan-0.26.0 → mapcan-0.27.0}/src/mapcan/bits.py +0 -0
  61. {mapcan-0.26.0 → mapcan-0.27.0}/src/mapcan/canopen.py +0 -0
  62. {mapcan-0.26.0 → mapcan-0.27.0}/src/mapcan/cli.py +0 -0
  63. {mapcan-0.26.0 → mapcan-0.27.0}/src/mapcan/codegen/__init__.py +0 -0
  64. {mapcan-0.26.0 → mapcan-0.27.0}/src/mapcan/codegen/c.py +0 -0
  65. {mapcan-0.26.0 → mapcan-0.27.0}/src/mapcan/codegen/common.py +0 -0
  66. {mapcan-0.26.0 → mapcan-0.27.0}/src/mapcan/codegen/py.py +0 -0
  67. {mapcan-0.26.0 → mapcan-0.27.0}/src/mapcan/codegen/zephyr.py +0 -0
  68. {mapcan-0.26.0 → mapcan-0.27.0}/src/mapcan/diagnostics.py +0 -0
  69. {mapcan-0.26.0 → mapcan-0.27.0}/src/mapcan/diff.py +0 -0
  70. {mapcan-0.26.0 → mapcan-0.27.0}/src/mapcan/docmodel.py +0 -0
  71. {mapcan-0.26.0 → mapcan-0.27.0}/src/mapcan/export/__init__.py +0 -0
  72. {mapcan-0.26.0 → mapcan-0.27.0}/src/mapcan/export/dbc.py +0 -0
  73. {mapcan-0.26.0 → mapcan-0.27.0}/src/mapcan/export/eds.py +0 -0
  74. {mapcan-0.26.0 → mapcan-0.27.0}/src/mapcan/export/pdf.py +0 -0
  75. {mapcan-0.26.0 → mapcan-0.27.0}/src/mapcan/export/text.py +0 -0
  76. {mapcan-0.26.0 → mapcan-0.27.0}/src/mapcan/export/xlsx.py +0 -0
  77. {mapcan-0.26.0 → mapcan-0.27.0}/src/mapcan/extras.py +0 -0
  78. {mapcan-0.26.0 → mapcan-0.27.0}/src/mapcan/fmt.py +0 -0
  79. {mapcan-0.26.0 → mapcan-0.27.0}/src/mapcan/fonts/OFL-PTSerif.txt +0 -0
  80. {mapcan-0.26.0 → mapcan-0.27.0}/src/mapcan/fonts/OFL.txt +0 -0
  81. {mapcan-0.26.0 → mapcan-0.27.0}/src/mapcan/fonts/PT_Sans-Web-Bold.ttf +0 -0
  82. {mapcan-0.26.0 → mapcan-0.27.0}/src/mapcan/fonts/PT_Sans-Web-BoldItalic.ttf +0 -0
  83. {mapcan-0.26.0 → mapcan-0.27.0}/src/mapcan/fonts/PT_Sans-Web-Italic.ttf +0 -0
  84. {mapcan-0.26.0 → mapcan-0.27.0}/src/mapcan/fonts/PT_Sans-Web-Regular.ttf +0 -0
  85. {mapcan-0.26.0 → mapcan-0.27.0}/src/mapcan/fonts/PT_Serif-Web-Bold.ttf +0 -0
  86. {mapcan-0.26.0 → mapcan-0.27.0}/src/mapcan/fonts/PT_Serif-Web-BoldItalic.ttf +0 -0
  87. {mapcan-0.26.0 → mapcan-0.27.0}/src/mapcan/fonts/PT_Serif-Web-Italic.ttf +0 -0
  88. {mapcan-0.26.0 → mapcan-0.27.0}/src/mapcan/fonts/PT_Serif-Web-Regular.ttf +0 -0
  89. {mapcan-0.26.0 → mapcan-0.27.0}/src/mapcan/i18n.py +0 -0
  90. {mapcan-0.26.0 → mapcan-0.27.0}/src/mapcan/importers/__init__.py +0 -0
  91. {mapcan-0.26.0 → mapcan-0.27.0}/src/mapcan/importers/dbc.py +0 -0
  92. {mapcan-0.26.0 → mapcan-0.27.0}/src/mapcan/importers/eds.py +0 -0
  93. {mapcan-0.26.0 → mapcan-0.27.0}/src/mapcan/layout.py +0 -0
  94. {mapcan-0.26.0 → mapcan-0.27.0}/src/mapcan/loader.py +0 -0
  95. {mapcan-0.26.0 → mapcan-0.27.0}/src/mapcan/locale/__init__.py +0 -0
  96. {mapcan-0.26.0 → mapcan-0.27.0}/src/mapcan/lsp/__init__.py +0 -0
  97. {mapcan-0.26.0 → mapcan-0.27.0}/src/mapcan/lsp/analysis.py +0 -0
  98. {mapcan-0.26.0 → mapcan-0.27.0}/src/mapcan/lsp/edits.py +0 -0
  99. {mapcan-0.26.0 → mapcan-0.27.0}/src/mapcan/lsp/exports.py +0 -0
  100. {mapcan-0.26.0 → mapcan-0.27.0}/src/mapcan/lsp/server.py +0 -0
  101. {mapcan-0.26.0 → mapcan-0.27.0}/src/mapcan/model.py +0 -0
  102. {mapcan-0.26.0 → mapcan-0.27.0}/src/mapcan/od.py +0 -0
  103. {mapcan-0.26.0 → mapcan-0.27.0}/src/mapcan/protocols.py +0 -0
  104. {mapcan-0.26.0 → mapcan-0.27.0}/src/mapcan/resolve.py +0 -0
  105. {mapcan-0.26.0 → mapcan-0.27.0}/src/mapcan/schema.py +0 -0
  106. {mapcan-0.26.0 → mapcan-0.27.0}/src/mapcan/structures.py +0 -0
  107. {mapcan-0.26.0 → mapcan-0.27.0}/src/mapcan/templates/document.html.j2 +0 -0
  108. {mapcan-0.26.0 → mapcan-0.27.0}/src/mapcan/templates/document.md.j2 +0 -0
  109. {mapcan-0.26.0 → mapcan-0.27.0}/src/mapcan/templates/pdf/gost-19.typ +0 -0
  110. {mapcan-0.26.0 → mapcan-0.27.0}/src/mapcan/templates/pdf/gost-2.105.typ +0 -0
  111. {mapcan-0.26.0 → mapcan-0.27.0}/src/mapcan/templates/pdf/gost-7.32.typ +0 -0
  112. {mapcan-0.26.0 → mapcan-0.27.0}/src/mapcan/templates/pdf/lib.typ +0 -0
  113. {mapcan-0.26.0 → mapcan-0.27.0}/src/mapcan/templates/pdf/mapcan.typ +0 -0
  114. {mapcan-0.26.0 → mapcan-0.27.0}/src/mapcan/templates/xlsx_style.yaml +0 -0
  115. {mapcan-0.26.0 → mapcan-0.27.0}/src/mapcan/units.py +0 -0
  116. {mapcan-0.26.0 → mapcan-0.27.0}/src/mapcan/upgrade.py +0 -0
  117. {mapcan-0.26.0 → mapcan-0.27.0}/src/mapcan/userconfig.py +0 -0
  118. {mapcan-0.26.0 → mapcan-0.27.0}/src/mapcan/validate.py +0 -0
  119. {mapcan-0.26.0 → mapcan-0.27.0}/src/mapcan/web/__init__.py +0 -0
  120. {mapcan-0.26.0 → mapcan-0.27.0}/src/mapcan/web/devicefile.py +0 -0
  121. {mapcan-0.26.0 → mapcan-0.27.0}/src/mapcan/web/examples.py +0 -0
  122. {mapcan-0.26.0 → mapcan-0.27.0}/src/mapcan/web/newmap.py +0 -0
  123. {mapcan-0.26.0 → mapcan-0.27.0}/src/mapcan/web/session.py +0 -0
  124. {mapcan-0.26.0 → mapcan-0.27.0}/src/mapcan/web/static/OFL-Sora.txt +0 -0
  125. {mapcan-0.26.0 → mapcan-0.27.0}/src/mapcan/web/static/favicon.svg +0 -0
  126. {mapcan-0.26.0 → mapcan-0.27.0}/src/mapcan/web/yamlops.py +0 -0
  127. {mapcan-0.26.0 → mapcan-0.27.0}/tests/__init__.py +0 -0
  128. {mapcan-0.26.0 → mapcan-0.27.0}/tests/conftest.py +0 -0
  129. {mapcan-0.26.0 → mapcan-0.27.0}/tests/data/bit_layouts.json +0 -0
  130. {mapcan-0.26.0 → mapcan-0.27.0}/tests/data/canopen-od.yaml +0 -0
  131. {mapcan-0.26.0 → mapcan-0.27.0}/tests/data/invalid_map.yaml +0 -0
  132. {mapcan-0.26.0 → mapcan-0.27.0}/tests/data/legacy.yaml +0 -0
  133. {mapcan-0.26.0 → mapcan-0.27.0}/tests/data/logo.png +0 -0
  134. {mapcan-0.26.0 → mapcan-0.27.0}/tests/data/logo.svg +0 -0
  135. {mapcan-0.26.0 → mapcan-0.27.0}/tests/data/reference.yaml +0 -0
  136. {mapcan-0.26.0 → mapcan-0.27.0}/tests/data/v1/canopen-node.yaml +0 -0
  137. {mapcan-0.26.0 → mapcan-0.27.0}/tests/data/v1/j1939.yaml +0 -0
  138. {mapcan-0.26.0 → mapcan-0.27.0}/tests/data/v1/reference.yaml +0 -0
  139. {mapcan-0.26.0 → mapcan-0.27.0}/tests/data/v1/vehicle-can.yaml +0 -0
  140. {mapcan-0.26.0 → mapcan-0.27.0}/tests/data/vendor-io.eds +0 -0
  141. {mapcan-0.26.0 → mapcan-0.27.0}/tests/data/zephyr_stub/zephyr/drivers/can.h +0 -0
  142. {mapcan-0.26.0 → mapcan-0.27.0}/tests/data/zephyr_stub/zephyr/kernel.h +0 -0
  143. {mapcan-0.26.0 → mapcan-0.27.0}/tests/golden/reference.md +0 -0
  144. {mapcan-0.26.0 → mapcan-0.27.0}/tests/golden/reference_bus1.h +0 -0
  145. {mapcan-0.26.0 → mapcan-0.27.0}/tests/test_auth.py +0 -0
  146. {mapcan-0.26.0 → mapcan-0.27.0}/tests/test_cli.py +0 -0
  147. {mapcan-0.26.0 → mapcan-0.27.0}/tests/test_codegen.py +0 -0
  148. {mapcan-0.26.0 → mapcan-0.27.0}/tests/test_device_file.py +0 -0
  149. {mapcan-0.26.0 → mapcan-0.27.0}/tests/test_diff.py +0 -0
  150. {mapcan-0.26.0 → mapcan-0.27.0}/tests/test_direction.py +0 -0
  151. {mapcan-0.26.0 → mapcan-0.27.0}/tests/test_eds.py +0 -0
  152. {mapcan-0.26.0 → mapcan-0.27.0}/tests/test_eds_import.py +0 -0
  153. {mapcan-0.26.0 → mapcan-0.27.0}/tests/test_exchange.py +0 -0
  154. {mapcan-0.26.0 → mapcan-0.27.0}/tests/test_export.py +0 -0
  155. {mapcan-0.26.0 → mapcan-0.27.0}/tests/test_extras.py +0 -0
  156. {mapcan-0.26.0 → mapcan-0.27.0}/tests/test_fmt.py +0 -0
  157. {mapcan-0.26.0 → mapcan-0.27.0}/tests/test_format_v1.py +0 -0
  158. {mapcan-0.26.0 → mapcan-0.27.0}/tests/test_i18n.py +0 -0
  159. {mapcan-0.26.0 → mapcan-0.27.0}/tests/test_import.py +0 -0
  160. {mapcan-0.26.0 → mapcan-0.27.0}/tests/test_include.py +0 -0
  161. {mapcan-0.26.0 → mapcan-0.27.0}/tests/test_j1939.py +0 -0
  162. {mapcan-0.26.0 → mapcan-0.27.0}/tests/test_launcher.py +0 -0
  163. {mapcan-0.26.0 → mapcan-0.27.0}/tests/test_loader_fast.py +0 -0
  164. {mapcan-0.26.0 → mapcan-0.27.0}/tests/test_lsp.py +0 -0
  165. {mapcan-0.26.0 → mapcan-0.27.0}/tests/test_lsp_edits.py +0 -0
  166. {mapcan-0.26.0 → mapcan-0.27.0}/tests/test_lsp_server.py +0 -0
  167. {mapcan-0.26.0 → mapcan-0.27.0}/tests/test_model.py +0 -0
  168. {mapcan-0.26.0 → mapcan-0.27.0}/tests/test_new_signal.py +0 -0
  169. {mapcan-0.26.0 → mapcan-0.27.0}/tests/test_od.py +0 -0
  170. {mapcan-0.26.0 → mapcan-0.27.0}/tests/test_source.py +0 -0
  171. {mapcan-0.26.0 → mapcan-0.27.0}/tests/test_structures.py +0 -0
  172. {mapcan-0.26.0 → mapcan-0.27.0}/tests/test_templates.py +0 -0
  173. {mapcan-0.26.0 → mapcan-0.27.0}/tests/test_titles.py +0 -0
  174. {mapcan-0.26.0 → mapcan-0.27.0}/tests/test_units.py +0 -0
  175. {mapcan-0.26.0 → mapcan-0.27.0}/tests/test_upgrade.py +0 -0
  176. {mapcan-0.26.0 → mapcan-0.27.0}/tests/test_validate.py +0 -0
  177. {mapcan-0.26.0 → mapcan-0.27.0}/tests/test_web.py +0 -0
  178. {mapcan-0.26.0 → mapcan-0.27.0}/tests/test_web_errors.py +0 -0
  179. {mapcan-0.26.0 → mapcan-0.27.0}/tests/test_web_session.py +0 -0
  180. {mapcan-0.26.0 → mapcan-0.27.0}/tests/test_workspace.py +0 -0
  181. {mapcan-0.26.0 → mapcan-0.27.0}/tests/test_yamlops.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: mapcan
3
- Version: 0.26.0
3
+ Version: 0.27.0
4
4
  Summary: A YAML map of CAN signals as the single source of truth: validation, Excel/PDF/Markdown/HTML, DBC, C/Python code
5
5
  Project-URL: Homepage, https://github.com/ordu1453/mapcan
6
6
  Project-URL: Documentation, https://github.com/ordu1453/mapcan/blob/main/docs/format.md
@@ -22,10 +22,19 @@ mapcan app --browser # the same in a browser tab
22
22
  current map has unsaved changes, the editor asks what to do with them first.
23
23
  * **Port.** 8765, or any free port if it is taken. The window opens once the server is ready.
24
24
  * **Closing the window** with unsaved changes asks for confirmation.
25
- * **Updates.** Once a day the editor checks the
26
- [latest release](https://github.com/ordu1453/mapcan/releases/latest) and shows a banner with a
27
- link to the installer. **Hide** dismisses it until the next version. To turn the check off, set
28
- the environment variable `MAPCAN_NO_UPDATE_CHECK=1`.
25
+ * **Updates.** Every time the editor starts it checks the
26
+ [latest release](https://github.com/ordu1453/mapcan/releases/latest) (reloading the page within a day
27
+ uses the saved answer, so GitHub is not asked again). When there is a newer
28
+ version, a chip appears in the top bar, right of **Save** (only the icon below 1600 px of width);
29
+ its popover opens by itself once per version and shows what is new.
30
+ With the Windows installer, **Download and update** downloads the installer in the background
31
+ (you can keep working), checks it against `SHA256SUMS.txt` of the same release (a file whose
32
+ checksum is missing or does not match is never run) and the chip turns into **Restart**. The
33
+ restart asks what to do with unsaved changes, closes the window, runs the installer silently and
34
+ opens the new version; settings and files in `~/.mapcan` are not touched. The downloaded installer
35
+ is kept in `~/.mapcan/updates` until the next version. With `pipx`, `uv tool` or `pip` the popover
36
+ shows the command to run in a terminal instead. **Skip this version** hides the chip until the
37
+ next one. To turn the check off, set the environment variable `MAPCAN_NO_UPDATE_CHECK=1`.
29
38
  * **Files.** Window settings, the theme and the selected PDF template are stored in
30
39
  `~/.mapcan/webview/`; the desktop app's error log is `~/.mapcan/mapcan.log`.
31
40
 
@@ -178,7 +187,9 @@ available at `http://127.0.0.1:8765/api/docs`.
178
187
  |---|---|---|
179
188
  | GET | `/api/meta` | mapcan version, profile, recent files, whether a map is open |
180
189
  | GET/PUT | `/api/user` | Author profile `{name, github}` |
181
- | GET | `/api/update` | Newer version on GitHub Releases: `{current, latest, newer, url, installer}` (`mapcan app` and local `serve` only) |
190
+ | GET | `/api/update` | Newer version on GitHub Releases: `{current, latest, newer, url, installer, size, notes, kind, command, can_apply, state, progress, error}`; `kind` is `installer`, `command` or `manual`, `state` is `idle`, `downloading`, `ready` or `error` (`mapcan app` and local `serve` only) |
191
+ | POST | `/api/update/download`, `/api/update/cancel` | Start or cancel the background download of the installer (Windows installer builds); `409 update-unavailable` if there is nothing to install |
192
+ | POST | `/api/update/apply` | Close the window and run the downloaded installer; only in `mapcan app`, `409 update-not-ready` before the download is finished |
182
193
  | POST | `/api/instance/activate` | `{token, path}`: a second launch hands the file to the running instance (the token is in `~/.mapcan/instance.json`) |
183
194
  | GET | `/api/fs/list?dir=` | Folders and YAML files for the file dialog |
184
195
  | POST | `/api/file/open`, `/api/file/new`, `/api/file/example`, `/api/file/import_dbc`, `/api/file/save_as`, `/api/file/close` | File operations; `409 unsaved` means there are unsaved changes (pass `force: true` to proceed) |
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "mapcan"
3
- version = "0.26.0"
3
+ version = "0.27.0"
4
4
  description = "A YAML map of CAN signals as the single source of truth: validation, Excel/PDF/Markdown/HTML, DBC, C/Python code"
5
5
  # readme: built from README.md with absolute links for PyPI (see fancy-pypi-readme below)
6
6
  dynamic = ["readme"]
@@ -1,6 +1,6 @@
1
1
  """mapcan: a YAML signal map as the single source of truth."""
2
2
 
3
- __version__ = "0.26.0"
3
+ __version__ = "0.27.0"
4
4
 
5
5
  from .loader import load, loads # noqa: E402
6
6
  from .model import MapCan # noqa: E402
@@ -22,7 +22,7 @@ import urllib.request
22
22
  import webbrowser
23
23
  from pathlib import Path
24
24
 
25
- from . import __version__
25
+ from . import __version__, updates
26
26
  from .i18n import _
27
27
  from .userconfig import config_dir
28
28
 
@@ -228,6 +228,13 @@ def run(path: Path | None = None, *, window: bool = True, readonly: bool = False
228
228
  webview = _webview() if window else None
229
229
  win = None
230
230
  minimized = False
231
+ quitting = False # the editor is closing itself to update: no questions
232
+
233
+ def on_quit() -> None:
234
+ nonlocal quitting
235
+ quitting = True
236
+ if win is not None:
237
+ win.destroy()
231
238
 
232
239
  def on_activate() -> None:
233
240
  if win is not None:
@@ -252,7 +259,7 @@ def run(path: Path | None = None, *, window: bool = True, readonly: bool = False
252
259
 
253
260
  app = create_app(session, cwd=cwd.resolve(), readonly=readonly, check_updates=check_updates,
254
261
  instance_token=token if single_instance else None, on_activate=on_activate,
255
- allowed_hosts=LOCAL_HOSTS, mode="app")
262
+ on_quit=on_quit if webview is not None else None, allowed_hosts=LOCAL_HOSTS, mode="app")
256
263
  server = ServerThread(app, host, port)
257
264
  try:
258
265
  server.start()
@@ -268,7 +275,7 @@ def run(path: Path | None = None, *, window: bool = True, readonly: bool = False
268
275
 
269
276
  def on_closing() -> bool:
270
277
  s = wsp.session
271
- if s is None or not s.dirty:
278
+ if quitting or s is None or not s.dirty:
272
279
  return True
273
280
  answer = _ask_save(_("“{name}” has unsaved changes.\n\nSave before closing?", name=s.path.name))
274
281
  if answer is None:
@@ -312,6 +319,7 @@ def run(path: Path | None = None, *, window: bool = True, readonly: bool = False
312
319
  if single_instance:
313
320
  _remove_instance(token)
314
321
  server.stop()
322
+ updates.UPDATER.launch_pending() # the update the user asked for, now that nothing is running
315
323
  return 0
316
324
 
317
325
 
@@ -647,6 +647,9 @@ RU: dict[str, str] = {
647
647
  "на сервере есть коммиты, которых нет здесь: сначала получите изменения (pull)",
648
648
  "the editor is running in read-only mode": "редактор запущен в режиме только для чтения",
649
649
  "invalid instance token": "неверный токен экземпляра",
650
+ "update checks are turned off": "проверка обновлений выключена",
651
+ "there is no installer to update to": "нет установщика, до которого можно обновиться",
652
+ "the update is not downloaded yet": "обновление ещё не скачано",
650
653
  "{path}: characters {chars} are not in the {encoding} encoding and were written as '?'":
651
654
  "{path}: символы {chars} не входят в кодировку {encoding} и записаны как «?»",
652
655
  "invalid Host header": "недопустимый заголовок Host",
@@ -0,0 +1,315 @@
1
+ """Check for a new mapcan version on GitHub Releases and, for the Windows installer, update from the app.
2
+
3
+ The editor asks GitHub on every start; the result is also cached for a day in ``~/.mapcan/update.json``
4
+ (for page reloads and the command line), so that GitHub is not contacted more often than needed.
5
+ The check is turned off by the environment variable ``MAPCAN_NO_UPDATE_CHECK=1``.
6
+
7
+ The installer is downloaded in the background to ``~/.mapcan/updates/`` and checked against the
8
+ ``SHA256SUMS.txt`` of the same release; a file whose checksum is missing or does not match is never run.
9
+ The app runs it only when the user asks, after the window is closed (:meth:`Updater.launch_pending`).
10
+ """
11
+
12
+ from __future__ import annotations
13
+
14
+ import hashlib
15
+ import json
16
+ import os
17
+ import re
18
+ import subprocess
19
+ import sys
20
+ import threading
21
+ import time
22
+ import urllib.request
23
+ from pathlib import Path
24
+
25
+ from . import __version__
26
+ from .userconfig import config_dir
27
+
28
+ REPO = "ordu1453/mapcan"
29
+ API_URL = f"https://api.github.com/repos/{REPO}/releases/latest"
30
+ RELEASES_URL = f"https://github.com/{REPO}/releases/latest"
31
+ CACHE_TTL = 24 * 3600
32
+ SUMS_NAME = "SHA256SUMS.txt"
33
+ INSTALLER_NAME = re.compile(r"mapcan-\d+\.\d+\.\d+-setup\.exe")
34
+ NOTES_LIMIT = 5
35
+ CHUNK = 256 * 1024
36
+
37
+
38
+ def parse_version(v: str) -> tuple[int, ...] | None:
39
+ """"v1.2.3" / "1.2" → (1, 2, 3) / (1, 2, 0); pre-releases and garbage → None."""
40
+ m = re.fullmatch(r"v?(\d+)\.(\d+)(?:\.(\d+))?", v.strip())
41
+ return (int(m[1]), int(m[2]), int(m[3] or 0)) if m else None
42
+
43
+
44
+ def is_newer(latest: str, current: str = __version__) -> bool:
45
+ a, b = parse_version(latest), parse_version(current)
46
+ return a is not None and b is not None and a > b
47
+
48
+
49
+ def disabled() -> bool:
50
+ flag = os.environ.get("MAPCAN_NO_UPDATE_CHECK") or os.environ.get("CANMAP_NO_UPDATE_CHECK") or ""
51
+ return flag.strip() not in ("", "0")
52
+
53
+
54
+ def _notes(body: str) -> list[str]:
55
+ """The bullet points of the release notes as plain text (the body is Markdown written on GitHub)."""
56
+ out = []
57
+ for line in body.splitlines():
58
+ m = re.match(r"\s*[-*]\s+(.*\S)", line)
59
+ if not m:
60
+ continue
61
+ text = re.sub(r"\[([^\]]*)\]\([^)]*\)", r"\1", m[1])
62
+ text = re.sub(r"[*_`]", "", text).strip()
63
+ if text:
64
+ out.append(text[:200])
65
+ if len(out) == NOTES_LIMIT:
66
+ break
67
+ return out
68
+
69
+
70
+ def _fetch(timeout: float) -> dict:
71
+ req = urllib.request.Request(API_URL, headers={
72
+ "Accept": "application/vnd.github+json",
73
+ "User-Agent": f"mapcan/{__version__}",
74
+ })
75
+ with urllib.request.urlopen(req, timeout=timeout) as r: # noqa: S310 — a fixed https address
76
+ data = json.load(r)
77
+ assets = data.get("assets", [])
78
+ installer = next((a for a in assets if a.get("name", "").endswith("-setup.exe")), None)
79
+ sums = next((a for a in assets if a.get("name") == SUMS_NAME), None)
80
+ return {"latest": str(data.get("tag_name", "")).lstrip("v"),
81
+ "url": data.get("html_url") or RELEASES_URL,
82
+ "installer": installer["browser_download_url"] if installer else None,
83
+ "size": installer.get("size") if installer else None,
84
+ "sums": sums["browser_download_url"] if sums else None,
85
+ "notes": _notes(str(data.get("body") or ""))}
86
+
87
+
88
+ def empty() -> dict:
89
+ """The answer when there is nothing to say (checks are off or GitHub is unreachable)."""
90
+ return {"current": __version__, "latest": None, "newer": False, "url": RELEASES_URL, "installer": None,
91
+ "size": None, "sums": None, "notes": []}
92
+
93
+
94
+ def check(timeout: float = 4.0, use_cache: bool = True) -> dict:
95
+ """Information about the latest version: {current, latest, newer, url, installer, size, sums, notes}.
96
+
97
+ Network errors are not raised: if GitHub is unreachable, ``newer`` = False.
98
+ """
99
+ result = empty()
100
+ if disabled():
101
+ return result
102
+ cache = config_dir() / "update.json"
103
+ info = None
104
+ if use_cache:
105
+ try:
106
+ cached = json.loads(cache.read_text(encoding="utf-8"))
107
+ if time.time() - float(cached.get("checked", 0)) < CACHE_TTL:
108
+ info = cached
109
+ except (OSError, ValueError, TypeError):
110
+ pass
111
+ if info is None:
112
+ try:
113
+ info = {**_fetch(timeout), "checked": time.time()}
114
+ except Exception: # noqa: BLE001 — no network, API rate limit, unexpected response
115
+ return result
116
+ try:
117
+ cache.parent.mkdir(parents=True, exist_ok=True)
118
+ cache.write_text(json.dumps(info), encoding="utf-8")
119
+ except OSError:
120
+ pass
121
+ latest = info.get("latest") or None
122
+ result.update(latest=latest, newer=bool(latest) and is_newer(latest),
123
+ url=info.get("url") or RELEASES_URL, installer=info.get("installer"),
124
+ size=info.get("size"), sums=info.get("sums"), notes=info.get("notes") or [])
125
+ return result
126
+
127
+
128
+ # --------------------------------------------------------------------------- how mapcan was installed
129
+
130
+
131
+ def install_kind() -> tuple[str, str | None]:
132
+ """How this copy was installed: ("installer", None) can update itself, ("command", cmd) is updated in a
133
+ terminal, ("manual", None) is a portable build that is replaced by hand."""
134
+ if getattr(sys, "frozen", False):
135
+ return ("installer", None) if os.name == "nt" else ("manual", None)
136
+ exe = sys.executable.replace("\\", "/").lower()
137
+ if "/pipx/" in exe:
138
+ return "command", "pipx upgrade mapcan"
139
+ if "/uv/tools/" in exe:
140
+ return "command", "uv tool upgrade mapcan"
141
+ return "command", "pip install --upgrade mapcan"
142
+
143
+
144
+ # --------------------------------------------------------------------------- download and install
145
+
146
+
147
+ class UpdateError(Exception):
148
+ """A failed download; ``code`` is what the editor shows: network, checksum, no-checksum, disk."""
149
+
150
+ def __init__(self, code: str):
151
+ super().__init__(code)
152
+ self.code = code
153
+
154
+
155
+ def _open(url: str | None, timeout: float = 20.0):
156
+ if not url or not url.startswith("https://github.com/"):
157
+ raise UpdateError("network")
158
+ req = urllib.request.Request(url, headers={"User-Agent": f"mapcan/{__version__}"})
159
+ return urllib.request.urlopen(req, timeout=timeout) # noqa: S310 — https://github.com/ only, checked above
160
+
161
+
162
+ def parse_sums(text: str) -> dict[str, str]:
163
+ """``sha256sum`` output: "<hash> <name>" (a "*" before the name marks binary mode)."""
164
+ out = {}
165
+ for line in text.splitlines():
166
+ m = re.fullmatch(r"([0-9a-fA-F]{64})\s+\*?(\S.*?)\s*", line)
167
+ if m:
168
+ out[m[2]] = m[1].lower()
169
+ return out
170
+
171
+
172
+ def _sha256(path: Path) -> str:
173
+ h = hashlib.sha256()
174
+ with open(path, "rb") as f:
175
+ while chunk := f.read(CHUNK):
176
+ h.update(chunk)
177
+ return h.hexdigest()
178
+
179
+
180
+ class Updater:
181
+ """One background download at a time. States: idle, downloading, ready, error."""
182
+
183
+ def __init__(self) -> None:
184
+ self._lock = threading.Lock()
185
+ self._cancel = threading.Event()
186
+ self._thread: threading.Thread | None = None
187
+ self.pending: Path | None = None
188
+ self._reset()
189
+
190
+ def _reset(self) -> None:
191
+ self.state, self.done, self.total = "idle", 0, 0
192
+ self.error: str | None = None
193
+ self.version: str | None = None
194
+ self.path: Path | None = None
195
+
196
+ def status(self) -> dict:
197
+ with self._lock:
198
+ progress = min(1.0, self.done / self.total) if self.total else 0.0
199
+ return {"state": self.state, "progress": progress, "error": self.error, "version": self.version}
200
+
201
+ def start(self, info: dict) -> None:
202
+ """Start downloading the installer of ``info`` (a result of :func:`check`); no-op while one is running."""
203
+ with self._lock:
204
+ if self.state == "downloading":
205
+ return
206
+ self._reset()
207
+ self.state, self.version = "downloading", info.get("latest")
208
+ self.total = int(info.get("size") or 0)
209
+ self._cancel.clear()
210
+ self._thread = threading.Thread(target=self._run, args=(dict(info),), daemon=True, name="mapcan-update")
211
+ self._thread.start()
212
+
213
+ def cancel(self) -> None:
214
+ self._cancel.set()
215
+ thread = self._thread
216
+ if thread is not None and thread.is_alive():
217
+ thread.join(timeout=5)
218
+ with self._lock:
219
+ if self.state == "downloading":
220
+ self._reset()
221
+
222
+ def _fail(self, code: str) -> None:
223
+ with self._lock:
224
+ if self._cancel.is_set():
225
+ self._reset()
226
+ else:
227
+ self.state, self.error = "error", code
228
+
229
+ def _finish(self, path: Path) -> None:
230
+ with self._lock:
231
+ self.state, self.path, self.done = "ready", path, self.total or self.done
232
+
233
+ def _run(self, info: dict) -> None:
234
+ try:
235
+ name = f"mapcan-{info['latest']}-setup.exe"
236
+ if not INSTALLER_NAME.fullmatch(name):
237
+ raise UpdateError("network")
238
+ if not info.get("sums"):
239
+ raise UpdateError("no-checksum")
240
+ with _open(info["sums"]) as r:
241
+ expected = parse_sums(r.read(1_000_000).decode("utf-8", "replace")).get(name)
242
+ if not expected:
243
+ raise UpdateError("no-checksum")
244
+ folder = config_dir() / "updates"
245
+ folder.mkdir(parents=True, exist_ok=True)
246
+ for old in folder.glob("mapcan-*"):
247
+ if old.name != name:
248
+ old.unlink(missing_ok=True)
249
+ final, part = folder / name, folder / (name + ".part")
250
+ if final.is_file() and _sha256(final) == expected:
251
+ self._finish(final)
252
+ return
253
+ digest = hashlib.sha256()
254
+ with _open(info.get("installer")) as r, open(part, "wb") as f:
255
+ total = int(r.headers.get("Content-Length") or info.get("size") or 0)
256
+ with self._lock:
257
+ self.total = total
258
+ while chunk := r.read(CHUNK):
259
+ if self._cancel.is_set():
260
+ raise UpdateError("cancelled")
261
+ f.write(chunk)
262
+ digest.update(chunk)
263
+ with self._lock:
264
+ self.done += len(chunk)
265
+ if digest.hexdigest() != expected:
266
+ part.unlink(missing_ok=True)
267
+ raise UpdateError("checksum")
268
+ os.replace(part, final)
269
+ self._finish(final)
270
+ except UpdateError as e:
271
+ self._fail(e.code)
272
+ except OSError as e:
273
+ self._fail("disk" if isinstance(e, PermissionError) or getattr(e, "errno", None) in (13, 28) else "network")
274
+ except Exception: # noqa: BLE001 — whatever fails in the background must not take the editor down
275
+ self._fail("network")
276
+
277
+ def apply(self) -> bool:
278
+ """Mark the downloaded installer to be run when the app exits (:meth:`launch_pending`)."""
279
+ with self._lock:
280
+ if self.state != "ready" or self.path is None or not self.path.is_file():
281
+ return False
282
+ self.pending = self.path
283
+ return True
284
+
285
+ def launch_pending(self) -> bool:
286
+ """Run the installer chosen by :meth:`apply`; called after the window and the server are closed.
287
+
288
+ It closes any mapcan process left over and starts the new version when it is done (``/restart=1`` is
289
+ read by packaging/mapcan.iss).
290
+ """
291
+ path, self.pending = self.pending, None
292
+ if path is None or os.name != "nt":
293
+ return False
294
+ flags = getattr(subprocess, "DETACHED_PROCESS", 0) | getattr(subprocess, "CREATE_NEW_PROCESS_GROUP", 0)
295
+ try:
296
+ subprocess.Popen([str(path), "/SILENT", "/CLOSEAPPLICATIONS", "/restart=1"], # noqa: S603
297
+ close_fds=True, creationflags=flags)
298
+ except OSError:
299
+ return False
300
+ return True
301
+
302
+
303
+ UPDATER = Updater()
304
+
305
+
306
+ def payload(result: dict, *, can_apply: bool = False) -> dict:
307
+ """What /api/update answers: the check, how this copy is updated and the state of the download."""
308
+ kind, command = install_kind()
309
+ st = UPDATER.status()
310
+ if st["version"] and st["version"] != result.get("latest"): # a download of an older version is stale
311
+ st = {"state": "idle", "progress": 0.0, "error": None, "version": None}
312
+ return {"current": result["current"], "latest": result["latest"], "newer": result["newer"], "url": result["url"],
313
+ "installer": result["installer"], "size": result["size"], "notes": result["notes"],
314
+ "kind": kind, "command": command, "can_apply": can_apply and kind == "installer",
315
+ "state": st["state"], "progress": st["progress"], "error": st["error"]}
@@ -543,7 +543,7 @@ def _remote_error(e: HTTPException, upstream: str | None) -> Exception:
543
543
  def create_app(session: EditorSession | None = None, poll_interval: float = 1.0,
544
544
  cwd: Path | None = None, readonly: bool | None = None, *,
545
545
  check_updates: bool = False, instance_token: str | None = None,
546
- on_activate: Callable[[], None] | None = None,
546
+ on_activate: Callable[[], None] | None = None, on_quit: Callable[[], None] | None = None,
547
547
  allowed_hosts: Collection[str] | None = None, auth_token: str | None = None,
548
548
  mode: str = "serve") -> FastAPI:
549
549
  """The editor application.
@@ -554,6 +554,7 @@ def create_app(session: EditorSession | None = None, poll_interval: float = 1.0,
554
554
  ``check_updates``: answer /api/update with information from GitHub Releases;
555
555
  ``instance_token`` allows /api/instance/activate (mapcan run again
556
556
  passes the file to the running instance), ``on_activate`` brings the window to the front;
557
+ ``on_quit`` closes the app window without asking (the editor updates itself and restarts);
557
558
  ``mode``: "app" (the app window) or "serve" (for a bug report).
558
559
  """
559
560
  hub = Hub()
@@ -642,12 +643,40 @@ def create_app(session: EditorSession | None = None, poll_interval: float = 1.0,
642
643
  async def get_meta() -> dict:
643
644
  return wsp.meta()
644
645
 
646
+ can_apply = mode == "app" and on_quit is not None
647
+ first_check = [True] # the first check after the editor starts asks GitHub; page reloads use the day's cache
648
+
645
649
  @app.get("/api/update")
646
650
  async def get_update() -> dict:
647
651
  if not check_updates:
648
- return {"current": __version__, "latest": None, "newer": False,
649
- "url": updates.RELEASES_URL, "installer": None}
650
- return await run_in_threadpool(updates.check)
652
+ return updates.payload(updates.empty(), can_apply=False)
653
+ use_cache, first_check[0] = not first_check[0], False
654
+ result = await run_in_threadpool(updates.check, 4.0, use_cache)
655
+ return updates.payload(result, can_apply=can_apply)
656
+
657
+ @app.post("/api/update/download")
658
+ async def update_download() -> dict:
659
+ if not check_updates:
660
+ raise AppError(409, "update-unavailable", _("update checks are turned off"))
661
+ result = await run_in_threadpool(updates.check, 4.0, False) # fresh: the cache may lack the checksum file
662
+ payload = updates.payload(result, can_apply=can_apply)
663
+ if not result["newer"] or payload["kind"] != "installer" or not result["installer"]:
664
+ raise AppError(409, "update-unavailable", _("there is no installer to update to"))
665
+ updates.UPDATER.start(result)
666
+ return updates.payload(result, can_apply=can_apply)
667
+
668
+ @app.post("/api/update/cancel")
669
+ async def update_cancel() -> dict:
670
+ await run_in_threadpool(updates.UPDATER.cancel)
671
+ return updates.payload(await run_in_threadpool(updates.check), can_apply=can_apply)
672
+
673
+ @app.post("/api/update/apply")
674
+ async def update_apply() -> dict:
675
+ if not can_apply or not updates.UPDATER.apply():
676
+ raise AppError(409, "update-not-ready", _("the update is not downloaded yet"))
677
+ # After the response is sent: the window closes, then the installer starts (see launcher.run)
678
+ asyncio.get_running_loop().call_later(0.3, on_quit)
679
+ return {"ok": True}
651
680
 
652
681
  @app.post("/api/instance/activate")
653
682
  async def activate(body: ActivateBody) -> dict: