decksmith 0.1.12__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/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
@@ -0,0 +1,102 @@
1
+ Metadata-Version: 2.4
2
+ Name: decksmith
3
+ Version: 0.1.15
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
+ License-Expression: GPL-2.0-only
6
+ Author: Julio Cabria
7
+ Author-email: juliocabria@tutanota.com
8
+ Requires-Python: >=3.11
9
+ Classifier: Programming Language :: Python :: 3
10
+ Classifier: Programming Language :: Python :: 3.11
11
+ Classifier: Programming Language :: Python :: 3.12
12
+ Classifier: Programming Language :: Python :: 3.13
13
+ Classifier: Programming Language :: Python :: 3.14
14
+ Provides-Extra: dev
15
+ Requires-Dist: click
16
+ Requires-Dist: jval (==1.0.6)
17
+ Requires-Dist: pandas
18
+ Requires-Dist: pillow (>=11.3.0)
19
+ Requires-Dist: poetry ; extra == "dev"
20
+ Requires-Dist: pytest ; extra == "dev"
21
+ Requires-Dist: reportlab (>=4.4.3)
22
+ Project-URL: Homepage, https://github.com/Julynx/decksmith
23
+ Description-Content-Type: text/markdown
24
+
25
+ # DeckSmith
26
+
27
+ *A command-line application to dynamically generate decks of cards from a JSON specification and a CSV data file, inspired by nandeck.*
28
+
29
+ <br>
30
+ <p align="center">
31
+ <img width="600" src="https://raw.githubusercontent.com/Julynx/decksmith/refs/heads/main/docs/assets/decksmith.png">
32
+ </p>
33
+
34
+ <br>
35
+ <p align="center">
36
+ <img width="600" src="https://raw.githubusercontent.com/Julynx/decksmith/refs/heads/main/docs/assets/banner.png">
37
+ </p>
38
+
39
+ <br>
40
+
41
+ DeckSmith is ideal for automating the creation of all kinds of decks, including TCG decks, tarot decks, business cards, and even slides.
42
+
43
+ ## Why DeckSmith?
44
+
45
+ - ✨ Consistent layout and formatting across all cards. Define once, edit anytime, generate as many cards as you need.
46
+ - 🍳 Pure python, with easy installation via pip.
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.
49
+ - 🧰 Tons of powerful features such as:
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
+ - [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)
52
+ - [Link any field to a column in the CSV file](https://github.com/Julynx/decksmith/blob/main/docs/DOCS.md#basic-example-with-deckcsv)
53
+ - [Position elements absolutely or relative to other elements, using anchors to simplify placement](https://github.com/Julynx/decksmith/blob/main/docs/DOCS.md#positioning)
54
+ - [Powerful image transformations using filters like crop, resize, rotate, or flip](https://github.com/Julynx/decksmith/blob/main/docs/DOCS.md#images)
55
+ - [Export your deck as images or as a PDF for printing](https://github.com/Julynx/decksmith/blob/main/docs/DOCS.md#building-the-deck)
56
+
57
+ ## Getting started
58
+
59
+ ### Installation
60
+
61
+ - To begin, install DeckSmith by running:
62
+
63
+ ```bash
64
+ pip install decksmith
65
+ ```
66
+
67
+ ### Creating a project
68
+
69
+ - Run the following command to start from sample `deck.json` and `deck.csv` files:
70
+
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
+ ```
98
+
99
+ ## Documentation
100
+
101
+ Check out the [full documentation](https://github.com/Julynx/decksmith/blob/main/docs/DOCS.md) for more detailed information on how to use DeckSmith.
102
+
@@ -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,54 +0,0 @@
1
- Metadata-Version: 2.4
2
- Name: decksmith
3
- Version: 0.1.12
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
- License-Expression: GPL-2.0-only
6
- Author: Julio Cabria
7
- Author-email: juliocabria@tutanota.com
8
- Requires-Python: >=3.11
9
- Classifier: Programming Language :: Python :: 3
10
- Classifier: Programming Language :: Python :: 3.11
11
- Classifier: Programming Language :: Python :: 3.12
12
- Classifier: Programming Language :: Python :: 3.13
13
- Classifier: Programming Language :: Python :: 3.14
14
- Provides-Extra: dev
15
- Requires-Dist: click
16
- Requires-Dist: jval (==1.0.6)
17
- Requires-Dist: pandas
18
- Requires-Dist: pillow (>=11.3.0)
19
- Requires-Dist: poetry ; extra == "dev"
20
- Requires-Dist: pytest ; extra == "dev"
21
- Requires-Dist: reportlab (>=4.4.3)
22
- Project-URL: Homepage, https://github.com/Julynx/decksmith
23
- Description-Content-Type: text/markdown
24
-
25
- # DeckSmith
26
-
27
- *A command-line application to dynamically generate decks of cards from a JSON specification and a CSV data file, inspired by nandeck.*
28
-
29
- <br>
30
- <p align="center">
31
- <img width="600" src="https://raw.githubusercontent.com/Julynx/decksmith/refs/heads/main/docs/assets/decksmith.png">
32
- </p>
33
- <br>
34
-
35
- DeckSmith is ideal for automating the creation of all kinds of decks, including TCG decks, tarot decks, business cards, and even slides.
36
-
37
- ## Features
38
-
39
- - [Initialize a sample project and edit it instead of starting from scratch](https://github.com/Julynx/decksmith/blob/main/docs/DOCS.md#creating-a-project)
40
-
41
- - [Include 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 different kinds of shapes](https://github.com/Julynx/decksmith/blob/main/docs/DOCS.md#shapes)
42
-
43
- - [Link any field to a column in the CSV file](https://github.com/Julynx/decksmith/blob/main/docs/DOCS.md#basic-example-with-deckcsv)
44
-
45
- - [Position elements absolutely or relative to other elements, using anchors to simplify placement](https://github.com/Julynx/decksmith/blob/main/docs/DOCS.md#positioning)
46
-
47
- - [Transform images using filters like crop, resize, rotate, or flip](https://github.com/Julynx/decksmith/blob/main/docs/DOCS.md#images)
48
-
49
- - [Build card images and export to PDF for printing](https://github.com/Julynx/decksmith/blob/main/docs/DOCS.md#building-the-deck)
50
-
51
- ## Getting started
52
-
53
- To start creating decks, check out [Getting Started](https://github.com/Julynx/decksmith/blob/main/docs/DOCS.md/#getting-started).
54
-
@@ -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.12.dist-info/entry_points.txt,sha256=-usRztjj2gnfmPubb8nFYHD22drzThAmSfM6geWI98Y,48
11
- decksmith-0.1.12.dist-info/METADATA,sha256=Ann7yKRK27_obgKvXnds1dBQ-9omU2JAaTDUw4jxn9g,2507
12
- decksmith-0.1.12.dist-info/WHEEL,sha256=zp0Cn7JsFoX2ATtOhtaFYIiE2rmFAD4OcMhtUki8W3U,88
13
- decksmith-0.1.12.dist-info/RECORD,,