decksmith 0.1.6__tar.gz → 0.1.7__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: decksmith
3
- Version: 0.1.6
3
+ Version: 0.1.7
4
4
  Summary: A command-line application to dynamically generate decks of cards from a JSON specification and a CSV data file, inspired by nandeck.
5
5
  License: GPL-2.0-only
6
6
  Author: Julio Cabria
@@ -7,7 +7,7 @@ import operator
7
7
  import pandas as pd
8
8
  from PIL import Image, ImageDraw, ImageFont
9
9
  from .utils import get_wrapped_text, apply_anchor
10
- from .validate import validate_card
10
+ from .validate import validate_card, transform_card
11
11
 
12
12
 
13
13
  class CardBuilder:
@@ -585,6 +585,7 @@ class CardBuilder:
585
585
  Args:
586
586
  output_path (str): The path where the card image will be saved.
587
587
  """
588
+ self.spec = transform_card(self.spec)
588
589
  validate_card(self.spec)
589
590
 
590
591
  for el in self.spec.get("elements", []):
@@ -0,0 +1,124 @@
1
+ """
2
+ Python module for validating a dictionar
3
+ """
4
+
5
+ from jval import validate
6
+
7
+ ELEMENT_SPEC = {
8
+ "?*id": "<?str>",
9
+ "*type": "<?str>",
10
+ "?*position": ["<?float>"],
11
+ "?*relative_to": ["<?str>"],
12
+ "?*anchor": "<?str>",
13
+ }
14
+
15
+ SPECS_FOR_TYPE = {
16
+ "text": {
17
+ "*text": "<?str>",
18
+ "?*color": ["<?int>"],
19
+ "?*font_path": "<?str>",
20
+ "?*font_size": "<?int>",
21
+ "?*font_variant": "<?str>",
22
+ "?*line_spacing": "<?int>",
23
+ "?*width": "<?int>",
24
+ "?*align": "<?str>",
25
+ "?*stroke_width": "<?int>",
26
+ "?*stroke_color": ["<?int>"],
27
+ },
28
+ "image": {
29
+ "*path": "<?str>",
30
+ "?*filters": {
31
+ "?*crop_top": "<?int>",
32
+ "?*crop_bottom": "<?int>",
33
+ "?*crop_left": "<?int>",
34
+ "?*crop_right": "<?int>",
35
+ "?*crop_box": ["<?int>"],
36
+ "?*rotate": "<?int>",
37
+ "?*flip": "<?str>",
38
+ "?*resize": ["<?int>"],
39
+ },
40
+ },
41
+ "circle": {
42
+ "*radius": "<?int>",
43
+ "?*color": ["<?int>"],
44
+ "?*outline_color": ["<?int>"],
45
+ "?*outline_width": "<?int>",
46
+ },
47
+ "ellipse": {
48
+ "*size": ["<?int>"],
49
+ "?*color": ["<?int>"],
50
+ "?*outline_color": ["<?int>"],
51
+ "?*outline_width": "<?int>",
52
+ },
53
+ "polygon": {
54
+ "*points": [["<?int>"]],
55
+ "?*color": ["<?int>"],
56
+ "?*outline_color": ["<?int>"],
57
+ "?*outline_width": "<?int>",
58
+ },
59
+ "regular-polygon": {
60
+ "*radius": "<?int>",
61
+ "*sides": "<?int>",
62
+ "?*rotation": "<?int>",
63
+ "?*color": ["<?int>"],
64
+ "?*outline_color": ["<?int>"],
65
+ "?*outline_width": "<?int>",
66
+ },
67
+ "rectangle": {
68
+ "*size": ["<?int>"],
69
+ "?*corners": ["<?bool>"],
70
+ "?*corner_radius": "<?int>",
71
+ "?*color": ["<?int>"],
72
+ "?*outline_color": ["<?int>"],
73
+ "?*outline_width": "<?int>",
74
+ },
75
+ }
76
+
77
+ CARD_SPEC = {
78
+ "*width": "<?int>",
79
+ "*height": "<?int>",
80
+ "?*background_color": ["<?int>"],
81
+ "*elements": [],
82
+ }
83
+
84
+
85
+ def validate_element(element, element_type):
86
+ """
87
+ Validates an element of a card against a spec, raising an exception
88
+ if it does not meet the spec.
89
+ Args:
90
+ element (dict): The card element.
91
+ element_type (str): The type of the element
92
+ """
93
+ spec = ELEMENT_SPEC | SPECS_FOR_TYPE[element_type]
94
+ validate(element, spec)
95
+
96
+
97
+ def validate_card(card):
98
+ """
99
+ Validates a card against a spec, raising an exception
100
+ if it does not meet the spec.
101
+ Args:
102
+ card (dict): The card.
103
+ """
104
+ # print(f"DEBUG:\n{card=}")
105
+ validate(card, CARD_SPEC)
106
+ for element in card["elements"]:
107
+ # print(f"DEBUG: {element['type']}")
108
+ validate_element(element, element["type"])
109
+
110
+
111
+ def transform_card(card):
112
+ """
113
+ Perform certain automatic type casts on the card and its
114
+ elements. For example, cast the "text" property of elements
115
+ of type "text" to str, to support painting numbers as text.
116
+ Args:
117
+ card (dict): The card.
118
+ Return:
119
+ dict: The transformed card with all automatic casts applied.
120
+ """
121
+ for element in card.get("elements", []):
122
+ if element.get("type") == "text" and "text" in element:
123
+ element["text"] = str(element["text"])
124
+ return card
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "decksmith"
3
- version = "0.1.6"
3
+ version = "0.1.7"
4
4
  description = "A command-line application to dynamically generate decks of cards from a JSON specification and a CSV data file, inspired by nandeck."
5
5
  authors = [
6
6
  {name = "Julio Cabria", email = "juliocabria@tutanota.com"},
@@ -24,7 +24,7 @@ dev = [
24
24
 
25
25
  [tool.poetry]
26
26
  name = "decksmith"
27
- version = "0.1.6"
27
+ version = "0.1.7"
28
28
  description = "A command-line application to dynamically generate decks of cards from a JSON specification and a CSV data file, inspired by nandeck."
29
29
  authors = ["Julio Cabria <juliocabria@tutanota.com>"]
30
30
  license = "GPL-2.0-only"
@@ -1,108 +0,0 @@
1
- """
2
- Python module for validating a dictionar
3
- """
4
-
5
- from jval import validate
6
-
7
- ELEMENT_SPEC = {
8
- "?*id": "<str>",
9
- "*type": "<str>",
10
- "?*position": ["<float>"],
11
- "?*relative_to": ["<str>"],
12
- "?*anchor": "<str>",
13
- }
14
-
15
- SPECS_FOR_TYPE = {
16
- "text": {
17
- "*text": "<str>",
18
- "?*color": ["<int>"],
19
- "?*font_path": "<str>",
20
- "?*font_size": "<int>",
21
- "?*font_variant": "<str>",
22
- "?*line_spacing": "<int>",
23
- "?*width": "<int>",
24
- "?*align": "<str>",
25
- "?*stroke_width": "<int>",
26
- "?*stroke_color": ["<int>"],
27
- },
28
- "image": {
29
- "*path": "<str>",
30
- "?*filters": {
31
- "?*crop_top": "<int>",
32
- "?*crop_bottom": "<int>",
33
- "?*crop_left": "<int>",
34
- "?*crop_right": "<int>",
35
- "?*crop_box": ["<int>"],
36
- "?*rotate": "<int>",
37
- "?*flip": "<str>",
38
- "?*resize": ["<?int>"],
39
- },
40
- },
41
- "circle": {
42
- "*radius": "<int>",
43
- "?*color": ["<int>"],
44
- "?*outline_color": ["<int>"],
45
- "?*outline_width": "<int>",
46
- },
47
- "ellipse": {
48
- "*size": ["<int>"],
49
- "?*color": ["<int>"],
50
- "?*outline_color": ["<int>"],
51
- "?*outline_width": "<int>",
52
- },
53
- "polygon": {
54
- "*points": [["<int>"]],
55
- "?*color": ["<int>"],
56
- "?*outline_color": ["<int>"],
57
- "?*outline_width": "<int>",
58
- },
59
- "regular-polygon": {
60
- "*radius": "<int>",
61
- "*sides": "<int>",
62
- "?*rotation": "<int>",
63
- "?*color": ["<int>"],
64
- "?*outline_color": ["<int>"],
65
- "?*outline_width": "<int>",
66
- },
67
- "rectangle": {
68
- "*size": ["<int>"],
69
- "?*corners": ["<bool>"],
70
- "?*corner_radius": "<int>",
71
- "?*color": ["<int>"],
72
- "?*outline_color": ["<int>"],
73
- "?*outline_width": "<int>",
74
- },
75
- }
76
-
77
- CARD_SPEC = {
78
- "*width": "<int>",
79
- "*height": "<int>",
80
- "?*background_color": ["<int>"],
81
- "*elements": [],
82
- }
83
-
84
-
85
- def validate_element(element, element_type):
86
- """
87
- Validates an element of a card against a spec, raising an exception
88
- if it does not meet the spec.
89
- Args:
90
- element (dict): The card element.
91
- element_type (str): The type of the element
92
- """
93
- spec = ELEMENT_SPEC | SPECS_FOR_TYPE[element_type]
94
- validate(element, spec)
95
-
96
-
97
- def validate_card(card):
98
- """
99
- Validates a card against a spec, raising an exception
100
- if it does not meet the spec.
101
- Args:
102
- card (dict): The card.
103
- """
104
- # print(f"DEBUG:\n{card=}")
105
- validate(card, CARD_SPEC)
106
- for element in card["elements"]:
107
- # print(f"DEBUG: {element['type']}")
108
- validate_element(element, element["type"])
File without changes
File without changes
File without changes
File without changes