drawpyo 0.2.2__tar.gz → 0.2.3__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 (27) hide show
  1. drawpyo-0.2.3/LICENSE +21 -0
  2. {drawpyo-0.2.2 → drawpyo-0.2.3}/PKG-INFO +8 -3
  3. {drawpyo-0.2.2 → drawpyo-0.2.3}/README.md +2 -0
  4. {drawpyo-0.2.2 → drawpyo-0.2.3}/pyproject.toml +6 -1
  5. drawpyo-0.2.3/src/drawpyo/__init__.py +12 -0
  6. {drawpyo-0.2.2 → drawpyo-0.2.3}/src/drawpyo/diagram/base_diagram.py +50 -44
  7. {drawpyo-0.2.2 → drawpyo-0.2.3}/src/drawpyo/diagram/edges.py +184 -128
  8. {drawpyo-0.2.2 → drawpyo-0.2.3}/src/drawpyo/diagram/extended_objects.py +15 -12
  9. {drawpyo-0.2.2 → drawpyo-0.2.3}/src/drawpyo/diagram/objects.py +218 -159
  10. {drawpyo-0.2.2 → drawpyo-0.2.3}/src/drawpyo/diagram/text_format.py +89 -36
  11. drawpyo-0.2.3/src/drawpyo/diagram_types/bar_chart.py +445 -0
  12. {drawpyo-0.2.2 → drawpyo-0.2.3}/src/drawpyo/diagram_types/class_diagram.py +9 -7
  13. {drawpyo-0.2.2 → drawpyo-0.2.3}/src/drawpyo/diagram_types/tree.py +69 -61
  14. {drawpyo-0.2.2 → drawpyo-0.2.3}/src/drawpyo/file.py +42 -21
  15. {drawpyo-0.2.2 → drawpyo-0.2.3}/src/drawpyo/page.py +49 -45
  16. drawpyo-0.2.3/src/drawpyo/utils/__init__.py +3 -0
  17. drawpyo-0.2.3/src/drawpyo/utils/color_scheme.py +90 -0
  18. drawpyo-0.2.3/src/drawpyo/utils/logger.py +15 -0
  19. drawpyo-0.2.3/src/drawpyo/utils/standard_colors.py +124 -0
  20. {drawpyo-0.2.2 → drawpyo-0.2.3}/src/drawpyo/xml_base.py +28 -19
  21. drawpyo-0.2.2/src/drawpyo/__init__.py +0 -8
  22. {drawpyo-0.2.2 → drawpyo-0.2.3}/src/drawpyo/diagram/__init__.py +0 -0
  23. {drawpyo-0.2.2 → drawpyo-0.2.3}/src/drawpyo/diagram_types/__init__.py +0 -0
  24. {drawpyo-0.2.2 → drawpyo-0.2.3}/src/drawpyo/formatting_database/edge_styles.toml +0 -0
  25. {drawpyo-0.2.2 → drawpyo-0.2.3}/src/drawpyo/formatting_database/line_styles.toml +0 -0
  26. {drawpyo-0.2.2 → drawpyo-0.2.3}/src/drawpyo/shape_libraries/flowchart.toml +0 -0
  27. {drawpyo-0.2.2 → drawpyo-0.2.3}/src/drawpyo/shape_libraries/general.toml +0 -0
drawpyo-0.2.3/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 MerrimanInd
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -1,17 +1,22 @@
1
- Metadata-Version: 2.3
1
+ Metadata-Version: 2.4
2
2
  Name: drawpyo
3
- Version: 0.2.2
3
+ Version: 0.2.3
4
4
  Summary: A Python library for programmatically generating Draw.io charts.
5
5
  Keywords: draw.io,diagrams.net,diagrams
6
6
  Author-email: Xander Cesari <xander@merriman.industries>
7
- Requires-Python: >=3.8
7
+ Requires-Python: >=3.10
8
8
  Description-Content-Type: text/markdown
9
9
  Classifier: Programming Language :: Python :: 3
10
10
  Classifier: License :: OSI Approved :: MIT License
11
11
  Classifier: Operating System :: OS Independent
12
+ License-File: LICENSE
12
13
  Requires-Dist: toml >= 0.10.2; python_version < '3.11'
14
+ Requires-Dist: pytest >= 7.0 ; extra == "dev"
13
15
  Project-URL: Homepage, https://github.com/MerrimanInd/drawpyo
14
16
  Project-URL: Issues, https://github.com/MerrimanInd/drawpyo/issues
17
+ Provides-Extra: dev
18
+
19
+ ![CI](https://github.com/MerrimanInd/drawpyo/actions/workflows/ci.yml/badge.svg) ![GitHub License](https://img.shields.io/github/license/MerrimanInd/drawpyo)
15
20
 
16
21
  # drawpyo
17
22
 
@@ -1,3 +1,5 @@
1
+ ![CI](https://github.com/MerrimanInd/drawpyo/actions/workflows/ci.yml/badge.svg) ![GitHub License](https://img.shields.io/github/license/MerrimanInd/drawpyo)
2
+
1
3
  # drawpyo
2
4
 
3
5
  Drawpyo is a Python library for programmatically generating Diagrams.net/Draw.io charts. It enables creating a diagram object, placing and styling objects, then writing the object to a file.
@@ -14,7 +14,7 @@ classifiers = [
14
14
  "License :: OSI Approved :: MIT License",
15
15
  "Operating System :: OS Independent",
16
16
  ]
17
- requires-python = ">=3.8"
17
+ requires-python = ">=3.10"
18
18
  dynamic = ["version"]
19
19
  dependencies = [
20
20
  "toml >= 0.10.2; python_version < '3.11'"
@@ -24,6 +24,11 @@ dependencies = [
24
24
  Homepage = "https://github.com/MerrimanInd/drawpyo"
25
25
  Issues = "https://github.com/MerrimanInd/drawpyo/issues"
26
26
 
27
+ [project.optional-dependencies]
28
+ dev = [
29
+ "pytest >= 7.0"
30
+ ]
31
+
27
32
  [tool.pytest.ini_options]
28
33
  addopts = [
29
34
  "--import-mode=importlib",
@@ -0,0 +1,12 @@
1
+ from .xml_base import XMLBase
2
+ from .file import File
3
+ from .page import Page
4
+
5
+ from .utils.standard_colors import StandardColor
6
+ from .utils.color_scheme import ColorScheme
7
+ from .utils.logger import logger
8
+ from . import utils
9
+ from . import diagram
10
+ from . import diagram_types
11
+
12
+ __version__ = "0.2.3"
@@ -1,9 +1,14 @@
1
+ from __future__ import annotations
2
+
3
+ from typing import List, Optional, Tuple, Dict, Any, Union
4
+
1
5
  from ..xml_base import XMLBase
2
6
  from os import path
3
7
 
4
8
 
5
9
  __all__ = [
6
10
  "DiagramBase",
11
+ "Geometry",
7
12
  "style_str_from_dict",
8
13
  "import_shape_database",
9
14
  "color_input_check",
@@ -11,7 +16,7 @@ __all__ = [
11
16
  ]
12
17
 
13
18
 
14
- def color_input_check(color_str):
19
+ def color_input_check(color_str: Optional[str]) -> Optional[str]:
15
20
  if color_str == None:
16
21
  return None
17
22
  elif color_str == "none":
@@ -20,9 +25,10 @@ def color_input_check(color_str):
20
25
  return color_str
21
26
  elif color_str[0] == "#" and len(color_str) == 7:
22
27
  return color_str
28
+ return None
23
29
 
24
30
 
25
- def width_input_check(width):
31
+ def width_input_check(width: Optional[Union[int, str]]) -> Optional[int]:
26
32
  if not width or (isinstance(width, str) and not width.isdigit()):
27
33
  return None
28
34
 
@@ -35,7 +41,7 @@ def width_input_check(width):
35
41
  return width
36
42
 
37
43
 
38
- def import_shape_database(file_name, relative=False):
44
+ def import_shape_database(file_name: str, relative: bool = False) -> Dict[str, Any]:
39
45
  """
40
46
  This function imports a TOML shape database and returns a dictionary of the
41
47
  shapes defined therein. It supports inheritance, meaning that if there is
@@ -86,7 +92,7 @@ def import_shape_database(file_name, relative=False):
86
92
  return data
87
93
 
88
94
 
89
- def style_str_from_dict(style_dict):
95
+ def style_str_from_dict(style_dict: Dict[str, Any]) -> str:
90
96
  """
91
97
  This function returns a concatenated style string from a style dictionary.
92
98
  This format is:
@@ -123,19 +129,19 @@ class DiagramBase(XMLBase):
123
129
  This class is the base for all diagram objects to inherit from. It defines some general creation methods and properties to make diagram objects printable and useful.
124
130
  """
125
131
 
126
- def __init__(self, **kwargs):
132
+ def __init__(self, **kwargs: Any) -> None:
127
133
  super().__init__(**kwargs)
128
- self._style_attributes = ["html"]
129
- self.page = kwargs.get("page", None)
130
- self.xml_parent = kwargs.get("xml_parent", None)
134
+ self._style_attributes: List[str] = ["html"]
135
+ self.page: Optional[Any] = kwargs.get("page", None)
136
+ self.xml_parent: Optional[DiagramBase] = kwargs.get("xml_parent", None)
131
137
 
132
138
  @classmethod
133
- def create_from_library(cls, library, obj):
134
- return cls
139
+ def create_from_library(cls, library: Dict[str, Any], obj: str) -> DiagramBase:
140
+ return cls()
135
141
 
136
142
  # XML_parent property
137
143
  @property
138
- def xml_parent_id(self):
144
+ def xml_parent_id(self) -> int:
139
145
  if self.xml_parent is not None:
140
146
  return self.xml_parent.id
141
147
  else:
@@ -143,11 +149,11 @@ class DiagramBase(XMLBase):
143
149
 
144
150
  # Parent object linking
145
151
  @property
146
- def xml_parent(self):
152
+ def xml_parent(self) -> Optional[DiagramBase]:
147
153
  return self._xml_parent
148
154
 
149
155
  @xml_parent.setter
150
- def xml_parent(self, p):
156
+ def xml_parent(self, p: Optional[DiagramBase]) -> None:
151
157
  if p is not None:
152
158
  p.add_object(self)
153
159
  self._xml_parent = p
@@ -155,13 +161,13 @@ class DiagramBase(XMLBase):
155
161
  self._xml_parent = None
156
162
 
157
163
  @xml_parent.deleter
158
- def xml_parent(self):
164
+ def xml_parent(self) -> None:
159
165
  self._xml_parent.remove_object(self)
160
166
  self._xml_parent = None
161
167
 
162
168
  # Page property
163
169
  @property
164
- def page_id(self):
170
+ def page_id(self) -> int:
165
171
  if self.page is not None:
166
172
  return self.page.id
167
173
  else:
@@ -169,11 +175,11 @@ class DiagramBase(XMLBase):
169
175
 
170
176
  # page object linking
171
177
  @property
172
- def page(self):
178
+ def page(self) -> Optional[Any]:
173
179
  return self._page
174
180
 
175
181
  @page.setter
176
- def page(self, p):
182
+ def page(self, p: Optional[Any]) -> None:
177
183
  if p is not None:
178
184
  p.add_object(self)
179
185
  self._page = p
@@ -181,22 +187,22 @@ class DiagramBase(XMLBase):
181
187
  self._page = None
182
188
 
183
189
  @page.deleter
184
- def page(self):
190
+ def page(self) -> None:
185
191
  self._page.remove_object(self)
186
192
  self._page = None
187
193
 
188
- def add_object(self, obj):
194
+ def add_object(self, obj: DiagramBase) -> None:
189
195
  self.page.add_object(obj)
190
196
 
191
197
  ###########################################################
192
198
  # Style properties
193
199
  ###########################################################
194
- def add_style_attribute(self, style_attr):
200
+ def add_style_attribute(self, style_attr: str) -> None:
195
201
  if style_attr not in self._style_attributes:
196
202
  self._style_attributes.append(style_attr)
197
203
 
198
204
  @property
199
- def style_attributes(self):
205
+ def style_attributes(self) -> List[str]:
200
206
  """
201
207
  The style attributes are the list of style tags that should be printed into the style XML attribute. This is a subset of the attributes defined on the object method.
202
208
 
@@ -206,11 +212,11 @@ class DiagramBase(XMLBase):
206
212
  return self._style_attributes
207
213
 
208
214
  @style_attributes.setter
209
- def style_attributes(self, value):
215
+ def style_attributes(self, value: List[str]) -> None:
210
216
  self._style_attributes = value
211
217
 
212
218
  @property
213
- def style(self):
219
+ def style(self) -> str:
214
220
  """
215
221
  This function returns the style string of the object to be appended into the style XML attribute.
216
222
 
@@ -246,14 +252,14 @@ class DiagramBase(XMLBase):
246
252
  style_str = style_str + self.text_format.style
247
253
  return style_str
248
254
 
249
- def _add_and_set_style_attrib(self, attrib, value):
255
+ def _add_and_set_style_attrib(self, attrib: str, value: Any) -> None:
250
256
  if hasattr(self, attrib):
251
257
  setattr(self, attrib, value)
252
258
  else:
253
259
  setattr(self, attrib, value)
254
260
  self.add_style_attribute(attrib)
255
261
 
256
- def apply_style_string(self, style_str):
262
+ def apply_style_string(self, style_str: str) -> None:
257
263
  """
258
264
  This function will apply a passed in style string to the object. This style string can be obtained from the Draw.io app by selecting Edit Style from the context menu of any object. This function will iterate through the attributes in the style string and assign the corresponding property the value.
259
265
 
@@ -278,12 +284,12 @@ class DiagramBase(XMLBase):
278
284
  else:
279
285
  self.baseStyle = attrib
280
286
 
281
- def _apply_style_from_template(self, template):
287
+ def _apply_style_from_template(self, template: DiagramBase) -> None:
282
288
  for attrib in template.style_attributes:
283
289
  value = getattr(template, attrib)
284
290
  self._add_and_set_style_attrib(attrib, value)
285
291
 
286
- def apply_attribute_dict(self, attr_dict):
292
+ def apply_attribute_dict(self, attr_dict: Dict[str, Any]) -> None:
287
293
  """
288
294
  This function takes in a dictionary of attributes and applies them
289
295
  to the object. These attributes can be style or properties. If the
@@ -305,7 +311,7 @@ class DiagramBase(XMLBase):
305
311
  self._add_and_set_style_attrib(attr, val)
306
312
 
307
313
  @classmethod
308
- def from_style_string(cls, style_string):
314
+ def from_style_string(cls, style_string: str) -> DiagramBase:
309
315
  """
310
316
  This classmethod allows the intantiation of an object from a style
311
317
  string. This is useful since Draw.io allows copying the style string
@@ -316,7 +322,7 @@ class DiagramBase(XMLBase):
316
322
  style_string (str): A Draw.io style string
317
323
 
318
324
  Returns:
319
- BaseDiagram: A BaseDiagram or subclass instantiated with the style from the Draw.io string
325
+ DiagramBase: A DiagramBase or subclass instantiated with the style from the Draw.io string
320
326
  """
321
327
  new_obj = cls()
322
328
  new_obj.apply_style_string(style_string)
@@ -324,35 +330,35 @@ class DiagramBase(XMLBase):
324
330
 
325
331
 
326
332
  class Geometry(DiagramBase):
327
- def __init__(self, **kwargs):
333
+ def __init__(self, **kwargs: Any) -> None:
328
334
  super().__init__(**kwargs)
329
- self.xml_class = "mxGeometry"
335
+ self.xml_class: str = "mxGeometry"
330
336
 
331
- self.parent_object = kwargs.get("parent_object", None)
332
- self.x = kwargs.get("x", 0)
333
- self.y = kwargs.get("y", 0)
334
- self.width = kwargs.get("width", 120)
335
- self.height = kwargs.get("height", 60)
336
- self.as_attribute = kwargs.get("as_attribute", "geometry")
337
+ self.parent_object: Optional[Any] = kwargs.get("parent_object", None)
338
+ self._x: Union[int, float] = kwargs.get("x", 0)
339
+ self._y: Union[int, float] = kwargs.get("y", 0)
340
+ self.width: Union[int, float] = kwargs.get("width", 120)
341
+ self.height: Union[int, float] = kwargs.get("height", 60)
342
+ self.as_attribute: str = kwargs.get("as_attribute", "geometry")
337
343
 
338
344
  @property
339
- def x(self):
345
+ def x(self) -> Union[int, float]:
340
346
  return self._x
341
347
 
342
348
  @x.setter
343
- def x(self, value):
349
+ def x(self, value: Union[int, float]) -> None:
344
350
  self._x = value
345
351
 
346
352
  @property
347
- def y(self):
353
+ def y(self) -> Union[int, float]:
348
354
  return self._y
349
355
 
350
356
  @y.setter
351
- def y(self, value):
357
+ def y(self, value: Union[int, float]) -> None:
352
358
  self._y = value
353
359
 
354
360
  @property
355
- def attributes(self):
361
+ def attributes(self) -> Dict[str, Union[int, float, str]]:
356
362
  return {
357
363
  "x": self.x,
358
364
  "y": self.y,
@@ -363,7 +369,7 @@ class Geometry(DiagramBase):
363
369
 
364
370
  # Size property
365
371
  @property
366
- def size(self):
372
+ def size(self) -> Tuple[Union[int, float], Union[int, float]]:
367
373
  """The size of the object. It's set with a tuple of ints, width and height respectively.
368
374
 
369
375
  (width, height)
@@ -374,6 +380,6 @@ class Geometry(DiagramBase):
374
380
  return (self.width, self.height)
375
381
 
376
382
  @size.setter
377
- def size(self, value):
383
+ def size(self, value: Tuple[Union[int, float], Union[int, float]]) -> None:
378
384
  self.width = value[0]
379
385
  self.height = value[1]