drawio-python 0.1.4__tar.gz → 0.1.6__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 (90) hide show
  1. {drawio_python-0.1.4 → drawio_python-0.1.6}/HISTORY.md +10 -0
  2. drawio_python-0.1.6/LICENSES/Apache-2.0.txt +202 -0
  3. {drawio_python-0.1.4 → drawio_python-0.1.6}/MANIFEST.in +1 -0
  4. {drawio_python-0.1.4 → drawio_python-0.1.6}/PKG-INFO +13 -4
  5. {drawio_python-0.1.4 → drawio_python-0.1.6}/README.md +12 -3
  6. drawio_python-0.1.6/drawio/VERSION +1 -0
  7. {drawio_python-0.1.4 → drawio_python-0.1.6}/drawio/cli.py +20 -1
  8. {drawio_python-0.1.4 → drawio_python-0.1.6}/drawio/lint.py +154 -4
  9. {drawio_python-0.1.4 → drawio_python-0.1.6}/drawio/render/desktop.py +18 -3
  10. drawio_python-0.1.6/drawio/routing.py +676 -0
  11. {drawio_python-0.1.4 → drawio_python-0.1.6}/drawio/scene.py +14 -242
  12. {drawio_python-0.1.4 → drawio_python-0.1.6}/drawio/skill/SKILL.md +11 -3
  13. {drawio_python-0.1.4 → drawio_python-0.1.6}/drawio/skill/references/api.md +5 -3
  14. {drawio_python-0.1.4 → drawio_python-0.1.6}/drawio/text.py +8 -5
  15. {drawio_python-0.1.4 → drawio_python-0.1.6}/drawio_python.egg-info/PKG-INFO +13 -4
  16. {drawio_python-0.1.4 → drawio_python-0.1.6}/drawio_python.egg-info/SOURCES.txt +4 -1
  17. drawio_python-0.1.6/tests/data/drawio_routes.json +1 -0
  18. {drawio_python-0.1.4 → drawio_python-0.1.6}/tests/test_cli.py +15 -0
  19. {drawio_python-0.1.4 → drawio_python-0.1.6}/tests/test_lint_render.py +88 -17
  20. drawio_python-0.1.4/drawio/VERSION +0 -1
  21. {drawio_python-0.1.4 → drawio_python-0.1.6}/Containerfile +0 -0
  22. {drawio_python-0.1.4 → drawio_python-0.1.6}/LICENSE +0 -0
  23. {drawio_python-0.1.4 → drawio_python-0.1.6}/docs/index.md +0 -0
  24. {drawio_python-0.1.4 → drawio_python-0.1.6}/drawio/__init__.py +0 -0
  25. {drawio_python-0.1.4 → drawio_python-0.1.6}/drawio/__main__.py +0 -0
  26. {drawio_python-0.1.4 → drawio_python-0.1.6}/drawio/base.py +0 -0
  27. {drawio_python-0.1.4 → drawio_python-0.1.6}/drawio/controllers/__init__.py +0 -0
  28. {drawio_python-0.1.4 → drawio_python-0.1.6}/drawio/doctor.py +0 -0
  29. {drawio_python-0.1.4 → drawio_python-0.1.6}/drawio/document.py +0 -0
  30. {drawio_python-0.1.4 → drawio_python-0.1.6}/drawio/entities/__init__.py +0 -0
  31. {drawio_python-0.1.4 → drawio_python-0.1.6}/drawio/entities/base_entity.py +0 -0
  32. {drawio_python-0.1.4 → drawio_python-0.1.6}/drawio/entities/config.py +0 -0
  33. {drawio_python-0.1.4 → drawio_python-0.1.6}/drawio/entities/drawio.py +0 -0
  34. {drawio_python-0.1.4 → drawio_python-0.1.6}/drawio/entities/drawio_app.py +0 -0
  35. {drawio_python-0.1.4 → drawio_python-0.1.6}/drawio/entities/drawio_browser.py +0 -0
  36. {drawio_python-0.1.4 → drawio_python-0.1.6}/drawio/entities/drawio_config/__init__.py +0 -0
  37. {drawio_python-0.1.4 → drawio_python-0.1.6}/drawio/entities/drawio_config/abstract_config.py +0 -0
  38. {drawio_python-0.1.4 → drawio_python-0.1.6}/drawio/entities/drawio_config/connect_config.py +0 -0
  39. {drawio_python-0.1.4 → drawio_python-0.1.6}/drawio/entities/drawio_config/drawio_config.py +0 -0
  40. {drawio_python-0.1.4 → drawio_python-0.1.6}/drawio/entities/drawio_config/label_config.py +0 -0
  41. {drawio_python-0.1.4 → drawio_python-0.1.6}/drawio/entities/erd/__init__.py +0 -0
  42. {drawio_python-0.1.4 → drawio_python-0.1.6}/drawio/entities/erd/column.py +0 -0
  43. {drawio_python-0.1.4 → drawio_python-0.1.6}/drawio/entities/erd/erd.py +0 -0
  44. {drawio_python-0.1.4 → drawio_python-0.1.6}/drawio/entities/erd/table.py +0 -0
  45. {drawio_python-0.1.4 → drawio_python-0.1.6}/drawio/entities/graph/__init__.py +0 -0
  46. {drawio_python-0.1.4 → drawio_python-0.1.6}/drawio/entities/graph/edge.py +0 -0
  47. {drawio_python-0.1.4 → drawio_python-0.1.6}/drawio/entities/graph/graph.py +0 -0
  48. {drawio_python-0.1.4 → drawio_python-0.1.6}/drawio/entities/graph/node.py +0 -0
  49. {drawio_python-0.1.4 → drawio_python-0.1.6}/drawio/entities/logger.py +0 -0
  50. {drawio_python-0.1.4 → drawio_python-0.1.6}/drawio/entities/renderers/__init__.py +0 -0
  51. {drawio_python-0.1.4 → drawio_python-0.1.6}/drawio/entities/renderers/base_render.py +0 -0
  52. {drawio_python-0.1.4 → drawio_python-0.1.6}/drawio/entities/renderers/drawio_render.py +0 -0
  53. {drawio_python-0.1.4 → drawio_python-0.1.6}/drawio/entities/renderers/pdf_render.py +0 -0
  54. {drawio_python-0.1.4 → drawio_python-0.1.6}/drawio/itergrations/__init__.py +0 -0
  55. {drawio_python-0.1.4 → drawio_python-0.1.6}/drawio/itergrations/mermaid/__init__.py +0 -0
  56. {drawio_python-0.1.4 → drawio_python-0.1.6}/drawio/itergrations/mermaid/mermaid_controller.py +0 -0
  57. {drawio_python-0.1.4 → drawio_python-0.1.6}/drawio/layout.py +0 -0
  58. {drawio_python-0.1.4 → drawio_python-0.1.6}/drawio/render/__init__.py +0 -0
  59. {drawio_python-0.1.4 → drawio_python-0.1.6}/drawio/render/browser.py +0 -0
  60. {drawio_python-0.1.4 → drawio_python-0.1.6}/drawio/render/fonts.py +0 -0
  61. {drawio_python-0.1.4 → drawio_python-0.1.6}/drawio/render/native.py +0 -0
  62. {drawio_python-0.1.4 → drawio_python-0.1.6}/drawio/shapes.py +0 -0
  63. {drawio_python-0.1.4 → drawio_python-0.1.6}/drawio/skill.py +0 -0
  64. {drawio_python-0.1.4 → drawio_python-0.1.6}/drawio_python.egg-info/dependency_links.txt +0 -0
  65. {drawio_python-0.1.4 → drawio_python-0.1.6}/drawio_python.egg-info/entry_points.txt +0 -0
  66. {drawio_python-0.1.4 → drawio_python-0.1.6}/drawio_python.egg-info/requires.txt +0 -0
  67. {drawio_python-0.1.4 → drawio_python-0.1.6}/drawio_python.egg-info/top_level.txt +0 -0
  68. {drawio_python-0.1.4 → drawio_python-0.1.6}/examples/agent_workflow.py +0 -0
  69. {drawio_python-0.1.4 → drawio_python-0.1.6}/examples/complex-example.py +0 -0
  70. {drawio_python-0.1.4 → drawio_python-0.1.6}/examples/draw-flow-diagrams.png +0 -0
  71. {drawio_python-0.1.4 → drawio_python-0.1.6}/examples/draw-flow-diagrams.py +0 -0
  72. {drawio_python-0.1.4 → drawio_python-0.1.6}/examples/mermaid-to-drawio.py +0 -0
  73. {drawio_python-0.1.4 → drawio_python-0.1.6}/examples/native_document.py +0 -0
  74. {drawio_python-0.1.4 → drawio_python-0.1.6}/mkdocs.yml +0 -0
  75. {drawio_python-0.1.4 → drawio_python-0.1.6}/pyproject.toml +0 -0
  76. {drawio_python-0.1.4 → drawio_python-0.1.6}/requirements-test.txt +0 -0
  77. {drawio_python-0.1.4 → drawio_python-0.1.6}/requirements.txt +0 -0
  78. {drawio_python-0.1.4 → drawio_python-0.1.6}/setup.cfg +0 -0
  79. {drawio_python-0.1.4 → drawio_python-0.1.6}/setup.py +0 -0
  80. {drawio_python-0.1.4 → drawio_python-0.1.6}/tests/__init__.py +0 -0
  81. {drawio_python-0.1.4 → drawio_python-0.1.6}/tests/conftest.py +0 -0
  82. {drawio_python-0.1.4 → drawio_python-0.1.6}/tests/test_base.py +0 -0
  83. {drawio_python-0.1.4 → drawio_python-0.1.6}/tests/test_document.py +0 -0
  84. {drawio_python-0.1.4 → drawio_python-0.1.6}/tests/test_examples.py +0 -0
  85. {drawio_python-0.1.4 → drawio_python-0.1.6}/tests/test_graph.py +0 -0
  86. {drawio_python-0.1.4 → drawio_python-0.1.6}/tests/test_graph_native.py +0 -0
  87. {drawio_python-0.1.4 → drawio_python-0.1.6}/tests/test_imports.py +0 -0
  88. {drawio_python-0.1.4 → drawio_python-0.1.6}/tests/test_layout_text.py +0 -0
  89. {drawio_python-0.1.4 → drawio_python-0.1.6}/tests/test_mermaid.py +0 -0
  90. {drawio_python-0.1.4 → drawio_python-0.1.6}/tests/test_toolkit_api.py +0 -0
@@ -1,5 +1,15 @@
1
1
  # Unreleased
2
2
 
3
+ - Route connectors exactly as draw.io does: `drawio/routing.py` ports mxGraph's
4
+ OrthConnector, SegmentConnector, elbow connectors and perimeters (Apache-2.0). Native
5
+ renders and lint now follow the editor for unpinned orthogonal connectors and for
6
+ waypoints that are off the line of a port; tests compare against routes recorded from
7
+ draw.io.
8
+ - Lint: `edge-hidden` for connectors painted under an opaque shape created after them;
9
+ `style-ignored` (info) for properties draw.io ignores, such as `ellipse=1`; text boxes
10
+ collide by their glyphs, not their line boxes; `--select`, `--ignore` and `-v`.
11
+ - Labels collapse runs of spaces as draw.io does.
12
+
3
13
  - Render pages to PNG, SVG, PDF and JPEG on any OS: a built-in native renderer (SVG
4
14
  with no dependencies, raster through Pillow), the draw.io desktop exporter, or the
5
15
  official diagrams.net viewer in a headless browser.
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
@@ -1,4 +1,5 @@
1
1
  include LICENSE
2
+ graft LICENSES
2
3
  include HISTORY.md
3
4
  include Containerfile
4
5
  include README.md
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: drawio-python
3
- Version: 0.1.4
3
+ Version: 0.1.6
4
4
  Summary: Build, check and export editable draw.io diagrams in Python; made for people and agents
5
5
  Home-page: https://github.com/maycuatroi1/drawio/
6
6
  Author: Nguyen Anh Binh
@@ -164,13 +164,16 @@ doc.save("flow.drawio", overwrite=True)
164
164
  ```sh
165
165
  drawio lint flow.drawio # exit status 1 when something is wrong
166
166
  drawio lint deck.drawio --fit 8.15x4.85in # also: text below 12 pt once placed on a slide
167
+ drawio lint flow.drawio --ignore aspect -v # pick codes with --select/--ignore; -v prints info
167
168
  drawio inspect flow.drawio --json # every shape box and connector route
168
169
  ```
169
170
 
170
171
  Lint reports overflowing labels, overlapping shapes and labels, connectors that run
171
- through shapes or labels, children outside containers, and (with `--fit`) text that
172
- ends up too small and aspect-ratio mismatches. Text widths are estimated from
173
- Helvetica/Arial metrics, close to draw.io's wrapping.
172
+ through shapes or labels or hide under a shape painted after them, children outside
173
+ containers, style properties draw.io ignores, and (with `--fit`) text that ends up too
174
+ small and aspect-ratio mismatches. Connector routes come from a port of draw.io's own
175
+ router (`drawio/routing.py`, checked against the diagrams.net viewer); text widths are
176
+ estimated from Helvetica/Arial metrics, close to draw.io's wrapping.
174
177
 
175
178
  ## Render
176
179
 
@@ -284,3 +287,9 @@ Tests write real XML, render with the native backend and run examples in
284
287
  temporary directories. They do not install packages, download browser drivers, or
285
288
  launch Chrome. See
286
289
  [the API reference](docs/index.md) and [contribution guide](CONTRIBUTING.md).
290
+
291
+ ## License
292
+
293
+ drawio-python is released into the public domain (see `LICENSE`), except
294
+ `drawio/routing.py`, a port of connector routing from mxGraph by JGraph Ltd, which is
295
+ under the Apache License 2.0 (`LICENSES/Apache-2.0.txt`).
@@ -126,13 +126,16 @@ doc.save("flow.drawio", overwrite=True)
126
126
  ```sh
127
127
  drawio lint flow.drawio # exit status 1 when something is wrong
128
128
  drawio lint deck.drawio --fit 8.15x4.85in # also: text below 12 pt once placed on a slide
129
+ drawio lint flow.drawio --ignore aspect -v # pick codes with --select/--ignore; -v prints info
129
130
  drawio inspect flow.drawio --json # every shape box and connector route
130
131
  ```
131
132
 
132
133
  Lint reports overflowing labels, overlapping shapes and labels, connectors that run
133
- through shapes or labels, children outside containers, and (with `--fit`) text that
134
- ends up too small and aspect-ratio mismatches. Text widths are estimated from
135
- Helvetica/Arial metrics, close to draw.io's wrapping.
134
+ through shapes or labels or hide under a shape painted after them, children outside
135
+ containers, style properties draw.io ignores, and (with `--fit`) text that ends up too
136
+ small and aspect-ratio mismatches. Connector routes come from a port of draw.io's own
137
+ router (`drawio/routing.py`, checked against the diagrams.net viewer); text widths are
138
+ estimated from Helvetica/Arial metrics, close to draw.io's wrapping.
136
139
 
137
140
  ## Render
138
141
 
@@ -246,3 +249,9 @@ Tests write real XML, render with the native backend and run examples in
246
249
  temporary directories. They do not install packages, download browser drivers, or
247
250
  launch Chrome. See
248
251
  [the API reference](docs/index.md) and [contribution guide](CONTRIBUTING.md).
252
+
253
+ ## License
254
+
255
+ drawio-python is released into the public domain (see `LICENSE`), except
256
+ `drawio/routing.py`, a port of connector routing from mxGraph by JGraph Ltd, which is
257
+ under the Apache License 2.0 (`LICENSES/Apache-2.0.txt`).
@@ -0,0 +1 @@
1
+ 0.1.6
@@ -95,7 +95,17 @@ def _cmd_lint(args):
95
95
  document = Document.load(args.input)
96
96
  document.validate()
97
97
  fit = parse_fit(args.fit, args.min_pt) if args.fit else None
98
- issues = check(document, fit=fit, pages=args.page or None)
98
+
99
+ def codes(values):
100
+ return [c.strip() for v in values or [] for c in v.split(",") if c.strip()] or None
101
+
102
+ issues = check(
103
+ document,
104
+ fit=fit,
105
+ pages=args.page or None,
106
+ select=codes(args.select),
107
+ ignore=codes(args.ignore),
108
+ )
99
109
  threshold = SEVERITIES.index(args.fail_on)
100
110
  failing = [i for i in issues if SEVERITIES.index(i.severity) <= threshold]
101
111
  counts = {s: sum(i.severity == s for i in issues) for s in SEVERITIES}
@@ -109,10 +119,14 @@ def _cmd_lint(args):
109
119
  )
110
120
  else:
111
121
  for issue in issues:
122
+ if issue.severity == "info" and not args.verbose:
123
+ continue
112
124
  print(f"{issue.severity}: [{issue.code}] page {issue.page}: {issue.message}")
113
125
  if issue.hint:
114
126
  print(f" fix: {issue.hint}")
115
127
  summary = ", ".join(f"{n} {s}(s)" for s, n in counts.items() if n)
128
+ if counts["info"] and not args.verbose:
129
+ summary += " (-v shows the info lines)"
116
130
  print(f"{args.input}: {summary or 'no layout problems found'}")
117
131
  return 1 if failing else 0
118
132
 
@@ -332,6 +346,11 @@ def _parser():
332
346
  " smaller than --min-pt",
333
347
  )
334
348
  lint.add_argument("--min-pt", type=float, default=12)
349
+ lint.add_argument(
350
+ "--select", action="append", help="Only these codes (comma list; edge-* for a prefix)"
351
+ )
352
+ lint.add_argument("--ignore", action="append", help="Drop these codes (comma list)")
353
+ lint.add_argument("-v", "--verbose", action="store_true", help="Also print info findings")
335
354
  lint.add_argument(
336
355
  "--fail-on",
337
356
  choices=["error", "warning", "info"],
@@ -203,7 +203,7 @@ def check_scene(scene: Scene, fit: Optional[Fit] = None) -> list[Issue]:
203
203
 
204
204
  def footprint(shape: Shape) -> Box:
205
205
  if shape.id in textlike:
206
- return shape.label.box if shape.label else (shape.box[0], shape.box[1], 0, 0)
206
+ return _ink(shape.label) if shape.label else (shape.box[0], shape.box[1], 0, 0)
207
207
  return shape.box
208
208
 
209
209
  def kind(shape: Shape) -> str:
@@ -425,6 +425,57 @@ def check_scene(scene: Scene, fit: Optional[Fit] = None) -> list[Issue]:
425
425
  )
426
426
  )
427
427
 
428
+ # Connectors covered by an opaque shape drawn after them (draw.io paints in order).
429
+ for edge in connectors:
430
+ total = sum(math.dist(a, b) for a, b in zip(edge.points, edge.points[1:]))
431
+ if total <= 0:
432
+ continue
433
+ ends = {e for e in (edge.source, edge.target) if e}
434
+ protected = set(ends)
435
+ for end in ends:
436
+ protected |= lineage.get(end, set())
437
+ for shape in shapes:
438
+ if shape.id in protected or depth[shape.id] < depth[edge.id] or not _opaque(shape):
439
+ continue
440
+ box = _shrink(shape.box, 1) # a connector along the outline stays visible
441
+ if shape.kind in _ROUND:
442
+ box = _shrink(box, min(box[2], box[3]) * 0.15)
443
+ hidden = sum(_inside_length(a, b, box) for a, b in zip(edge.points, edge.points[1:]))
444
+ # Half the line, or the arrow head: a mark placed over a short stretch on purpose
445
+ # (a cross on a broken link) is not reported.
446
+ if hidden >= total * 0.5 or _contains_point(box, edge.points[-1]):
447
+ issues.append(
448
+ Issue(
449
+ "edge-hidden",
450
+ "warning",
451
+ page,
452
+ [edge.id, shape.id],
453
+ f"Connector {edge.id} is drawn under {_name(shape)}, which covers"
454
+ f" {hidden:.0f} of its {total:.0f} px"
455
+ + (
456
+ " including the arrow head."
457
+ if _contains_point(box, edge.points[-1])
458
+ else "."
459
+ ),
460
+ "draw.io paints cells in order: create the connector after the shape, give"
461
+ " the shape fillColor=none, or move it off the route.",
462
+ {"route": [list(p) for p in edge.points], "shape": _round(shape.box)},
463
+ )
464
+ )
465
+
466
+ for item in scene.items:
467
+ for problem in _style_problems(item.style):
468
+ issues.append(
469
+ Issue(
470
+ "style-ignored",
471
+ "info",
472
+ page,
473
+ [item.id],
474
+ f"draw.io ignores the style property {problem[0]!r} on {item.id}.",
475
+ problem[1],
476
+ )
477
+ )
478
+
428
479
  for shape in shapes:
429
480
  if not shape.known:
430
481
  issues.append(
@@ -518,13 +569,112 @@ def _name(shape: Shape) -> str:
518
569
  return shape.id
519
570
 
520
571
 
521
- def check(document, *, fit: Optional[Fit] = None, pages=None) -> list[Issue]:
522
- """Run every layout check on a Document (or only on the pages whose IDs are given)."""
572
+ def _ink(label: Label) -> Box:
573
+ """The part of a label's line boxes that glyphs cover: no leading above the first line,
574
+ no space under the last line's descenders."""
575
+ x, y, w, h = label.box
576
+ top, bottom = 0.18 * label.font_size, 0.09 * label.font_size
577
+ return x, y + top, w, max(h - top - bottom, 0)
578
+
579
+
580
+ def _opaque(shape: Shape) -> bool:
581
+ if shape.kind in ("text", "image", "line") and shape.style.get("fillColor") in (None, "none"):
582
+ return False
583
+ fill = shape.style.get("fillColor", "#ffffff")
584
+ if fill in ("none", ""):
585
+ return False
586
+ try:
587
+ alpha = float(shape.style.get("opacity", 100)) * float(shape.style.get("fillOpacity", 100))
588
+ except ValueError:
589
+ alpha = 10000
590
+ return alpha >= 5000
591
+
592
+
593
+ def _contains_point(box: Box, p) -> bool:
594
+ return box[0] < p[0] < box[0] + box[2] and box[1] < p[1] < box[1] + box[3]
595
+
596
+
597
+ def _inside_length(a, b, box: Box) -> float:
598
+ """Length of segment a-b inside box (Liang-Barsky clipping)."""
599
+ x0, y0 = a
600
+ dx, dy = b[0] - x0, b[1] - y0
601
+ t0, t1 = 0.0, 1.0
602
+ for p, q in ((-dx, x0 - box[0]), (dx, box[0] + box[2] - x0),
603
+ (-dy, y0 - box[1]), (dy, box[1] + box[3] - y0)): # fmt: skip
604
+ if p == 0:
605
+ if q < 0:
606
+ return 0.0
607
+ else:
608
+ t = q / p
609
+ if p < 0:
610
+ t0 = max(t0, t)
611
+ else:
612
+ t1 = min(t1, t)
613
+ return max(0.0, t1 - t0) * math.hypot(dx, dy)
614
+
615
+
616
+ # Shape names that only work as `shape=NAME` or as a bare style name, never as NAME=1.
617
+ _SHAPE_KEYS = {
618
+ "ellipse", "doubleEllipse", "rhombus", "triangle", "cloud", "hexagon", "cylinder",
619
+ "swimlane", "image", "line", "text", "actor", "process", "note", "card", "step",
620
+ "document", "parallelogram", "trapezoid", "circle", "diamond",
621
+ } # fmt: skip
622
+ # Common style properties, to catch case mistakes such as fontsize for fontSize.
623
+ _KNOWN_KEYS = {
624
+ "fillColor", "strokeColor", "fontColor", "fontSize", "fontFamily", "fontStyle",
625
+ "strokeWidth", "dashed", "dashPattern", "rounded", "arcSize", "absoluteArcSize",
626
+ "whiteSpace", "html", "align", "verticalAlign", "labelPosition", "verticalLabelPosition",
627
+ "spacing", "spacingTop", "spacingLeft", "spacingRight", "spacingBottom", "opacity",
628
+ "fillOpacity", "strokeOpacity", "textOpacity", "shadow", "glass", "gradientColor",
629
+ "gradientDirection", "edgeStyle", "curved", "endArrow", "startArrow", "endFill",
630
+ "startFill", "endSize", "startSize", "exitX", "exitY", "entryX", "entryY", "exitDx",
631
+ "exitDy", "entryDx", "entryDy", "exitPerimeter", "entryPerimeter", "labelBackgroundColor",
632
+ "labelBorderColor", "container", "collapsible", "recursiveResize", "shape", "perimeter",
633
+ "aspect", "image", "imageAspect", "direction", "rotation", "flipH", "flipV", "size",
634
+ "fixedSize", "boundedLbl", "backgroundOutline", "horizontal", "jettySize", "elbow",
635
+ "orthogonalLoop", "noLabel", "editable", "movable", "resizable", "deletable",
636
+ "connectable", "portConstraint", "swimlaneFillColor", "swimlaneLine", "childLayout",
637
+ } # fmt: skip
638
+ _BY_LOWER = {k.lower(): k for k in _KNOWN_KEYS}
639
+
640
+
641
+ def _style_problems(style: dict) -> list[tuple[str, str]]:
642
+ found = []
643
+ for key, value in style.items():
644
+ if value is not None and key in _SHAPE_KEYS and key not in _KNOWN_KEYS:
645
+ name = {"circle": "ellipse", "diamond": "rhombus", "cylinder": "cylinder3"}.get(
646
+ key, key
647
+ )
648
+ found.append((f"{key}={value}", f"Use shape={name} (or page.box(..., shape={key!r}))."))
649
+ elif key not in _KNOWN_KEYS and key.lower() in _BY_LOWER:
650
+ found.append((key, f"Property names are case-sensitive: use {_BY_LOWER[key.lower()]}."))
651
+ return found
652
+
653
+
654
+ def _wanted(code: str, select, ignore) -> bool:
655
+ if select and not any(code == s or code.startswith(s.rstrip("*")) for s in select):
656
+ return False
657
+ return not (ignore and any(code == s or code.startswith(s.rstrip("*")) for s in ignore))
658
+
659
+
660
+ def check(
661
+ document,
662
+ *,
663
+ fit: Optional[Fit] = None,
664
+ pages=None,
665
+ select=None,
666
+ ignore=None,
667
+ ) -> list[Issue]:
668
+ """Run every layout check on a Document (or only on the pages whose IDs are given).
669
+
670
+ `select` keeps only the listed finding codes and `ignore` drops them; a trailing `*`
671
+ matches a prefix, e.g. ignore=["edge-*"].
672
+ """
523
673
  result = []
524
674
  for page in document.pages:
525
675
  if pages and page.id not in pages and page.name not in pages:
526
676
  continue
527
- result.extend(check_scene(build(page), fit))
677
+ result.extend(i for i in check_scene(build(page), fit) if _wanted(i.code, select, ignore))
528
678
  return result
529
679
 
530
680
 
@@ -12,6 +12,7 @@ import os
12
12
  import shutil
13
13
  import subprocess
14
14
  import sys
15
+ import sysconfig
15
16
  from pathlib import Path
16
17
  from typing import Optional
17
18
 
@@ -34,13 +35,27 @@ _CANDIDATES = {
34
35
 
35
36
 
36
37
  def _is_ours(path: str) -> bool:
37
- """The `drawio` command of this Python package also sits on PATH; skip it."""
38
+ """Whether `path` is the `drawio` command of a Python package rather than draw.io desktop.
39
+
40
+ pip installs that command as a script with a Python shebang on Linux and macOS, and as
41
+ an .exe launcher with the script appended (uncompressed) on Windows. Anything inside a
42
+ Python scripts directory counts as ours too.
43
+ """
44
+ resolved = Path(path).resolve()
45
+ scripts = {sysconfig.get_path("scripts"), str(Path(sys.executable).parent)}
46
+ if any(d and Path(d).resolve() == resolved.parent for d in scripts):
47
+ return True
38
48
  try:
39
- with open(path, "rb") as stream:
49
+ with open(resolved, "rb") as stream:
40
50
  head = stream.read(256)
51
+ stream.seek(0, os.SEEK_END)
52
+ stream.seek(max(0, stream.tell() - 65536))
53
+ tail = stream.read()
41
54
  except OSError:
42
55
  return False
43
- return head.startswith(b"#!") and b"python" in head.lower()
56
+ if head.startswith(b"#!") and b"python" in head.lower():
57
+ return True
58
+ return b"drawio.__main__" in tail or b"from drawio" in tail
44
59
 
45
60
 
46
61
  def find() -> Optional[str]: