decksmith 0.1.14__py3-none-any.whl → 0.1.15__py3-none-any.whl
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.
- decksmith/card_builder.py +627 -627
- decksmith/deck_builder.py +101 -101
- decksmith/export.py +168 -168
- decksmith/main.py +138 -138
- decksmith/templates/deck.csv +5 -5
- decksmith/templates/deck.json +31 -31
- decksmith/utils.py +69 -69
- decksmith/validate.py +132 -132
- {decksmith-0.1.14.dist-info → decksmith-0.1.15.dist-info}/METADATA +36 -8
- decksmith-0.1.15.dist-info/RECORD +13 -0
- decksmith-0.1.14.dist-info/RECORD +0 -13
- {decksmith-0.1.14.dist-info → decksmith-0.1.15.dist-info}/WHEEL +0 -0
- {decksmith-0.1.14.dist-info → decksmith-0.1.15.dist-info}/entry_points.txt +0 -0
decksmith/validate.py
CHANGED
|
@@ -1,132 +1,132 @@
|
|
|
1
|
-
"""
|
|
2
|
-
This module provides functions for validating and transforming card specifications.
|
|
3
|
-
"""
|
|
4
|
-
|
|
5
|
-
from typing import Dict, Any
|
|
6
|
-
|
|
7
|
-
import pandas as pd
|
|
8
|
-
from jval import validate
|
|
9
|
-
|
|
10
|
-
ELEMENT_SPEC: Dict[str, Any] = {
|
|
11
|
-
"?*id": "<?str>",
|
|
12
|
-
"*type": "<?str>",
|
|
13
|
-
"?*position": ["<?float>"],
|
|
14
|
-
"?*relative_to": ["<?str>"],
|
|
15
|
-
"?*anchor": "<?str>",
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
SPECS_FOR_TYPE: Dict[str, Dict[str, Any]] = {
|
|
19
|
-
"text": {
|
|
20
|
-
"*text": "<?str>",
|
|
21
|
-
"?*color": ["<?int>"],
|
|
22
|
-
"?*font_path": "<?str>",
|
|
23
|
-
"?*font_size": "<?int>",
|
|
24
|
-
"?*font_variant": "<?str>",
|
|
25
|
-
"?*line_spacing": "<?int>",
|
|
26
|
-
"?*width": "<?int>",
|
|
27
|
-
"?*align": "<?str>",
|
|
28
|
-
"?*stroke_width": "<?int>",
|
|
29
|
-
"?*stroke_color": ["<?int>"],
|
|
30
|
-
},
|
|
31
|
-
"image": {
|
|
32
|
-
"*path": "<?str>",
|
|
33
|
-
"?*filters": {
|
|
34
|
-
"?*crop_top": "<?int>",
|
|
35
|
-
"?*crop_bottom": "<?int>",
|
|
36
|
-
"?*crop_left": "<?int>",
|
|
37
|
-
"?*crop_right": "<?int>",
|
|
38
|
-
"?*crop_box": ["<?int>"],
|
|
39
|
-
"?*rotate": "<?int>",
|
|
40
|
-
"?*flip": "<?str>",
|
|
41
|
-
"?*resize": ["<?int>"],
|
|
42
|
-
},
|
|
43
|
-
},
|
|
44
|
-
"circle": {
|
|
45
|
-
"*radius": "<?int>",
|
|
46
|
-
"?*color": ["<?int>"],
|
|
47
|
-
"?*outline_color": ["<?int>"],
|
|
48
|
-
"?*outline_width": "<?int>",
|
|
49
|
-
},
|
|
50
|
-
"ellipse": {
|
|
51
|
-
"*size": ["<?int>"],
|
|
52
|
-
"?*color": ["<?int>"],
|
|
53
|
-
"?*outline_color": ["<?int>"],
|
|
54
|
-
"?*outline_width": "<?int>",
|
|
55
|
-
},
|
|
56
|
-
"polygon": {
|
|
57
|
-
"*points": [["<?int>"]],
|
|
58
|
-
"?*color": ["<?int>"],
|
|
59
|
-
"?*outline_color": ["<?int>"],
|
|
60
|
-
"?*outline_width": "<?int>",
|
|
61
|
-
},
|
|
62
|
-
"regular-polygon": {
|
|
63
|
-
"*radius": "<?int>",
|
|
64
|
-
"*sides": "<?int>",
|
|
65
|
-
"?*rotation": "<?int>",
|
|
66
|
-
"?*color": ["<?int>"],
|
|
67
|
-
"?*outline_color": ["<?int>"],
|
|
68
|
-
"?*outline_width": "<?int>",
|
|
69
|
-
},
|
|
70
|
-
"rectangle": {
|
|
71
|
-
"*size": ["<?int>"],
|
|
72
|
-
"?*corners": ["<?bool>"],
|
|
73
|
-
"?*corner_radius": "<?int>",
|
|
74
|
-
"?*color": ["<?int>"],
|
|
75
|
-
"?*outline_color": ["<?int>"],
|
|
76
|
-
"?*outline_width": "<?int>",
|
|
77
|
-
},
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
CARD_SPEC: Dict[str, Any] = {
|
|
81
|
-
"?*id": "<?str>",
|
|
82
|
-
"*width": "<?int>",
|
|
83
|
-
"*height": "<?int>",
|
|
84
|
-
"?*background_color": ["<?int>"],
|
|
85
|
-
"*elements": [],
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
def validate_element(element: Dict[str, Any], element_type: str):
|
|
90
|
-
"""
|
|
91
|
-
Validates an element of a card against a spec, raising an exception
|
|
92
|
-
if it does not meet the spec.
|
|
93
|
-
Args:
|
|
94
|
-
element (dict): The card element.
|
|
95
|
-
element_type (str): The type of the element
|
|
96
|
-
"""
|
|
97
|
-
spec = ELEMENT_SPEC | SPECS_FOR_TYPE[element_type]
|
|
98
|
-
validate(element, spec)
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
def validate_card(card: Dict[str, Any]):
|
|
102
|
-
"""
|
|
103
|
-
Validates a card against a spec, raising an exception
|
|
104
|
-
if it does not meet the spec.
|
|
105
|
-
Args:
|
|
106
|
-
card (Dict[str, Any]): The card.
|
|
107
|
-
"""
|
|
108
|
-
# print(f"DEBUG:\n{card=}")
|
|
109
|
-
validate(card, CARD_SPEC)
|
|
110
|
-
for element in card["elements"]:
|
|
111
|
-
# print(f"DEBUG: {element['type']}")
|
|
112
|
-
validate_element(element, element["type"])
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
def transform_card(card: Dict[str, Any]) -> Dict[str, Any]:
|
|
116
|
-
"""
|
|
117
|
-
Perform certain automatic type casts on the card and its
|
|
118
|
-
elements. For example, cast the "text" property of elements
|
|
119
|
-
of type "text" to str, to support painting numbers as text.
|
|
120
|
-
Args:
|
|
121
|
-
card (Dict[str, Any]): The card.
|
|
122
|
-
Return:
|
|
123
|
-
Dict[str, Any]: The transformed card with all automatic casts applied.
|
|
124
|
-
"""
|
|
125
|
-
for element in card.get("elements", []):
|
|
126
|
-
if element.get("type") == "text" and "text" in element:
|
|
127
|
-
if pd.isna(element["text"]):
|
|
128
|
-
element["text"] = None
|
|
129
|
-
else:
|
|
130
|
-
element["text"] = str(element["text"])
|
|
131
|
-
|
|
132
|
-
return card
|
|
1
|
+
"""
|
|
2
|
+
This module provides functions for validating and transforming card specifications.
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
from typing import Dict, Any
|
|
6
|
+
|
|
7
|
+
import pandas as pd
|
|
8
|
+
from jval import validate
|
|
9
|
+
|
|
10
|
+
ELEMENT_SPEC: Dict[str, Any] = {
|
|
11
|
+
"?*id": "<?str>",
|
|
12
|
+
"*type": "<?str>",
|
|
13
|
+
"?*position": ["<?float>"],
|
|
14
|
+
"?*relative_to": ["<?str>"],
|
|
15
|
+
"?*anchor": "<?str>",
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
SPECS_FOR_TYPE: Dict[str, Dict[str, Any]] = {
|
|
19
|
+
"text": {
|
|
20
|
+
"*text": "<?str>",
|
|
21
|
+
"?*color": ["<?int>"],
|
|
22
|
+
"?*font_path": "<?str>",
|
|
23
|
+
"?*font_size": "<?int>",
|
|
24
|
+
"?*font_variant": "<?str>",
|
|
25
|
+
"?*line_spacing": "<?int>",
|
|
26
|
+
"?*width": "<?int>",
|
|
27
|
+
"?*align": "<?str>",
|
|
28
|
+
"?*stroke_width": "<?int>",
|
|
29
|
+
"?*stroke_color": ["<?int>"],
|
|
30
|
+
},
|
|
31
|
+
"image": {
|
|
32
|
+
"*path": "<?str>",
|
|
33
|
+
"?*filters": {
|
|
34
|
+
"?*crop_top": "<?int>",
|
|
35
|
+
"?*crop_bottom": "<?int>",
|
|
36
|
+
"?*crop_left": "<?int>",
|
|
37
|
+
"?*crop_right": "<?int>",
|
|
38
|
+
"?*crop_box": ["<?int>"],
|
|
39
|
+
"?*rotate": "<?int>",
|
|
40
|
+
"?*flip": "<?str>",
|
|
41
|
+
"?*resize": ["<?int>"],
|
|
42
|
+
},
|
|
43
|
+
},
|
|
44
|
+
"circle": {
|
|
45
|
+
"*radius": "<?int>",
|
|
46
|
+
"?*color": ["<?int>"],
|
|
47
|
+
"?*outline_color": ["<?int>"],
|
|
48
|
+
"?*outline_width": "<?int>",
|
|
49
|
+
},
|
|
50
|
+
"ellipse": {
|
|
51
|
+
"*size": ["<?int>"],
|
|
52
|
+
"?*color": ["<?int>"],
|
|
53
|
+
"?*outline_color": ["<?int>"],
|
|
54
|
+
"?*outline_width": "<?int>",
|
|
55
|
+
},
|
|
56
|
+
"polygon": {
|
|
57
|
+
"*points": [["<?int>"]],
|
|
58
|
+
"?*color": ["<?int>"],
|
|
59
|
+
"?*outline_color": ["<?int>"],
|
|
60
|
+
"?*outline_width": "<?int>",
|
|
61
|
+
},
|
|
62
|
+
"regular-polygon": {
|
|
63
|
+
"*radius": "<?int>",
|
|
64
|
+
"*sides": "<?int>",
|
|
65
|
+
"?*rotation": "<?int>",
|
|
66
|
+
"?*color": ["<?int>"],
|
|
67
|
+
"?*outline_color": ["<?int>"],
|
|
68
|
+
"?*outline_width": "<?int>",
|
|
69
|
+
},
|
|
70
|
+
"rectangle": {
|
|
71
|
+
"*size": ["<?int>"],
|
|
72
|
+
"?*corners": ["<?bool>"],
|
|
73
|
+
"?*corner_radius": "<?int>",
|
|
74
|
+
"?*color": ["<?int>"],
|
|
75
|
+
"?*outline_color": ["<?int>"],
|
|
76
|
+
"?*outline_width": "<?int>",
|
|
77
|
+
},
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
CARD_SPEC: Dict[str, Any] = {
|
|
81
|
+
"?*id": "<?str>",
|
|
82
|
+
"*width": "<?int>",
|
|
83
|
+
"*height": "<?int>",
|
|
84
|
+
"?*background_color": ["<?int>"],
|
|
85
|
+
"*elements": [],
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
def validate_element(element: Dict[str, Any], element_type: str):
|
|
90
|
+
"""
|
|
91
|
+
Validates an element of a card against a spec, raising an exception
|
|
92
|
+
if it does not meet the spec.
|
|
93
|
+
Args:
|
|
94
|
+
element (dict): The card element.
|
|
95
|
+
element_type (str): The type of the element
|
|
96
|
+
"""
|
|
97
|
+
spec = ELEMENT_SPEC | SPECS_FOR_TYPE[element_type]
|
|
98
|
+
validate(element, spec)
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
def validate_card(card: Dict[str, Any]):
|
|
102
|
+
"""
|
|
103
|
+
Validates a card against a spec, raising an exception
|
|
104
|
+
if it does not meet the spec.
|
|
105
|
+
Args:
|
|
106
|
+
card (Dict[str, Any]): The card.
|
|
107
|
+
"""
|
|
108
|
+
# print(f"DEBUG:\n{card=}")
|
|
109
|
+
validate(card, CARD_SPEC)
|
|
110
|
+
for element in card["elements"]:
|
|
111
|
+
# print(f"DEBUG: {element['type']}")
|
|
112
|
+
validate_element(element, element["type"])
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
def transform_card(card: Dict[str, Any]) -> Dict[str, Any]:
|
|
116
|
+
"""
|
|
117
|
+
Perform certain automatic type casts on the card and its
|
|
118
|
+
elements. For example, cast the "text" property of elements
|
|
119
|
+
of type "text" to str, to support painting numbers as text.
|
|
120
|
+
Args:
|
|
121
|
+
card (Dict[str, Any]): The card.
|
|
122
|
+
Return:
|
|
123
|
+
Dict[str, Any]: The transformed card with all automatic casts applied.
|
|
124
|
+
"""
|
|
125
|
+
for element in card.get("elements", []):
|
|
126
|
+
if element.get("type") == "text" and "text" in element:
|
|
127
|
+
if pd.isna(element["text"]):
|
|
128
|
+
element["text"] = None
|
|
129
|
+
else:
|
|
130
|
+
element["text"] = str(element["text"])
|
|
131
|
+
|
|
132
|
+
return card
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: decksmith
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.15
|
|
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-Expression: GPL-2.0-only
|
|
6
6
|
Author: Julio Cabria
|
|
@@ -45,7 +45,7 @@ DeckSmith is ideal for automating the creation of all kinds of decks, including
|
|
|
45
45
|
- ✨ Consistent layout and formatting across all cards. Define once, edit anytime, generate as many cards as you need.
|
|
46
46
|
- 🍳 Pure python, with easy installation via pip.
|
|
47
47
|
- ⚡ Highly performant card generation using parallel processing.
|
|
48
|
-
- 📖 Intuitive syntax and extensive [documentation](https://github.com/Julynx/decksmith/blob/main/docs/DOCS.md) with examples to help you get started
|
|
48
|
+
- 📖 Intuitive syntax and extensive [documentation](https://github.com/Julynx/decksmith/blob/main/docs/DOCS.md) with examples to help you get started.
|
|
49
49
|
- 🧰 Tons of powerful features such as:
|
|
50
50
|
- [Start from a sample project and edit it instead of starting from scratch](https://github.com/Julynx/decksmith/blob/main/docs/DOCS.md#creating-a-project)
|
|
51
51
|
- [Extensive support for images](https://github.com/Julynx/decksmith/blob/main/docs/DOCS.md#images), [text](https://github.com/Julynx/decksmith/blob/main/docs/DOCS.md#text), [and all kinds of different shapes](https://github.com/Julynx/decksmith/blob/main/docs/DOCS.md#shapes)
|
|
@@ -56,17 +56,45 @@ DeckSmith is ideal for automating the creation of all kinds of decks, including
|
|
|
56
56
|
|
|
57
57
|
## Getting started
|
|
58
58
|
|
|
59
|
-
|
|
59
|
+
### Installation
|
|
60
60
|
|
|
61
|
-
-
|
|
61
|
+
- To begin, install DeckSmith by running:
|
|
62
62
|
|
|
63
|
-
|
|
63
|
+
```bash
|
|
64
|
+
pip install decksmith
|
|
65
|
+
```
|
|
64
66
|
|
|
65
|
-
|
|
67
|
+
### Creating a project
|
|
66
68
|
|
|
67
|
-
|
|
69
|
+
- Run the following command to start from sample `deck.json` and `deck.csv` files:
|
|
68
70
|
|
|
69
|
-
|
|
71
|
+
```text
|
|
72
|
+
decksmith init
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
- `deck.json` defines the layout for the cards in the deck.
|
|
76
|
+
- `deck.csv` holds the data for each card, like the content of the text fields and the image paths.
|
|
77
|
+
|
|
78
|
+
### Defining the layout
|
|
79
|
+
|
|
80
|
+
- Edit `deck.json` to include all the elements you want on your cards.
|
|
81
|
+
You can find a complete list of all the available elements and their properties in the [documentation](https://github.com/Julynx/decksmith/blob/main/docs/DOCS.md).
|
|
82
|
+
|
|
83
|
+
- You can reference any column from `deck.csv` in the `deck.json` file as `%column_name%`.
|
|
84
|
+
|
|
85
|
+
### Building the deck
|
|
86
|
+
|
|
87
|
+
- When you are ready to generate the deck images, run:
|
|
88
|
+
|
|
89
|
+
```text
|
|
90
|
+
decksmith build
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
- After building a deck, you can export it to PDF by running:
|
|
94
|
+
|
|
95
|
+
```text
|
|
96
|
+
decksmith export
|
|
97
|
+
```
|
|
70
98
|
|
|
71
99
|
## Documentation
|
|
72
100
|
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
decksmith/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
|
+
decksmith/card_builder.py,sha256=F8m4sMhwuSCcf16QFdWkZG3I8_n04ITeSFwIcyIWjtg,25163
|
|
3
|
+
decksmith/deck_builder.py,sha256=vWjzGPu4OaoiyOdmQ4ONYWOHmiEzOZdubPWiXrxead4,3734
|
|
4
|
+
decksmith/export.py,sha256=8hyYv4B-77OS6xnZ50VBJJNBDfBoQr_i1FR0HVXYpuQ,5463
|
|
5
|
+
decksmith/main.py,sha256=88OTPGV5pmjIrKyAk55C8fkIybYcG2AF5Khs5I3gI7w,4404
|
|
6
|
+
decksmith/templates/deck.csv,sha256=C-Fdeb_byPnGlZNoDq7VlI1aThsvfhMdkieGBA8vglQ,457
|
|
7
|
+
decksmith/templates/deck.json,sha256=Yv-Bb_PmhuMpuDMTgus4swtgFxIjItMws9bKqXTjX_s,664
|
|
8
|
+
decksmith/utils.py,sha256=UkXraPtT3HKlUUu_Cl4gs9SrZHoW-doLY5L-qNpYXFo,2232
|
|
9
|
+
decksmith/validate.py,sha256=bN_SPk08vPeeyJjkzrXnH2sqh99Z3uQBI0BHY7j8ElQ,3681
|
|
10
|
+
decksmith-0.1.15.dist-info/METADATA,sha256=q5aPwAv3Phc7XUk4CA5FY0sSag6PD2ANVXx5TSoTFhE,4150
|
|
11
|
+
decksmith-0.1.15.dist-info/WHEEL,sha256=zp0Cn7JsFoX2ATtOhtaFYIiE2rmFAD4OcMhtUki8W3U,88
|
|
12
|
+
decksmith-0.1.15.dist-info/entry_points.txt,sha256=-usRztjj2gnfmPubb8nFYHD22drzThAmSfM6geWI98Y,48
|
|
13
|
+
decksmith-0.1.15.dist-info/RECORD,,
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
decksmith/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
|
-
decksmith/card_builder.py,sha256=9pxiPqeN7_mxVFw8Ii-npseTtlD5KyF9Wg95h7OmCz0,25790
|
|
3
|
-
decksmith/deck_builder.py,sha256=WoaY2A0RDrYNvWZtBckcsR5MKHOXdCpNHaI2J5JZlKU,3835
|
|
4
|
-
decksmith/export.py,sha256=55TaK1fSL0EvtKCoAvUx-47ljNOL5zPeFJguDqL4BVU,5631
|
|
5
|
-
decksmith/main.py,sha256=upBSH8yCOiwCPjW-zf9QpqPTO-RIIaAuEACkWhUTgEw,4542
|
|
6
|
-
decksmith/templates/deck.csv,sha256=pNJebNxoDIfM8m0-aj05YrANHih1BTKOMry1kspIpPI,462
|
|
7
|
-
decksmith/templates/deck.json,sha256=BTTnmaFP5AkbbC_B7uMF6R4bOM7JizW6EATcsjjJrT4,695
|
|
8
|
-
decksmith/utils.py,sha256=vwRrzQEjpZq4x0GJLgJc7TqrC9LLJJqcHAsz1ar-vVs,2301
|
|
9
|
-
decksmith/validate.py,sha256=zA3ygyzOpx3ai6AhkSw611Qik3syZvR5ZmI_w3Pj_No,3813
|
|
10
|
-
decksmith-0.1.14.dist-info/entry_points.txt,sha256=-usRztjj2gnfmPubb8nFYHD22drzThAmSfM6geWI98Y,48
|
|
11
|
-
decksmith-0.1.14.dist-info/METADATA,sha256=sZgsT2lB0E0HGfhaEN8HQNziLVVn5trV1r9OD_l3LL0,3847
|
|
12
|
-
decksmith-0.1.14.dist-info/WHEEL,sha256=zp0Cn7JsFoX2ATtOhtaFYIiE2rmFAD4OcMhtUki8W3U,88
|
|
13
|
-
decksmith-0.1.14.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|