patlab 0.1.0__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.
patlab-0.1.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Sayam
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.
patlab-0.1.0/PKG-INFO ADDED
@@ -0,0 +1,22 @@
1
+ Metadata-Version: 2.4
2
+ Name: patlab
3
+ Version: 0.1.0
4
+ Summary: Simple pattern generation library for Python
5
+ Author-email: Sayam <sayampradhan07@outlook.com>
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/sayampradhan/patlab
8
+ Project-URL: Repository, https://github.com/sayampradhan/patlab
9
+ Project-URL: GitHub, https://github.com/sayampradhan
10
+ Requires-Python: >=3.8
11
+ Description-Content-Type: text/markdown
12
+ License-File: LICENSE
13
+ Dynamic: license-file
14
+
15
+ # patlab
16
+
17
+ Generate common patterns in Python easily.
18
+
19
+ ## Installation
20
+
21
+ ```bash
22
+ pip install patlab
patlab-0.1.0/README.md ADDED
@@ -0,0 +1,8 @@
1
+ # patlab
2
+
3
+ Generate common patterns in Python easily.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ pip install patlab
@@ -0,0 +1,6 @@
1
+ from .basic import square
2
+ from .pyramid import make as pyramid
3
+ from .right_triangle import make as right_triangle
4
+
5
+ __version__ = "0.1.0"
6
+ __all__ = ["square", "right_triangle", "pyramid"]
@@ -0,0 +1,40 @@
1
+ # basic.py
2
+
3
+ def square(n, char="*"):
4
+ """
5
+ Generate a square pattern of size `n` using the specified character.
6
+
7
+ Parameters:
8
+ -----------
9
+ n : int
10
+ The size of the square (number of rows and columns). Must be positive.
11
+ char : str, optional
12
+ The character to use for building the square. Default is '*'.
13
+ Should be a single character.
14
+
15
+ Returns:
16
+ --------
17
+ str
18
+ A string representing the square pattern, with each row separated by a newline.
19
+
20
+ Raises:
21
+ -------
22
+ ValueError
23
+ If `n` is not a positive integer.
24
+
25
+ Examples:
26
+ ---------
27
+ >>> print(square(3))
28
+ ***
29
+ ***
30
+ ***
31
+
32
+ >>> print(square(4, "#"))
33
+ ####
34
+ ####
35
+ ####
36
+ ####
37
+ """
38
+ if n <= 0:
39
+ raise ValueError("n must be positive")
40
+ return "\n".join([char * n for _ in range(n)])
@@ -0,0 +1,223 @@
1
+ """
2
+ pyramid.py
3
+
4
+ Module for generating various pyramid shapes in text form.
5
+
6
+ Available pyramid variants:
7
+ - centered: A classic centered pyramid.
8
+ - right: Right-aligned pyramid (staircase style).
9
+ - numeric: Pyramid with ascending numbers.
10
+ """
11
+
12
+ from typing import Literal
13
+
14
+
15
+ def centered(n: int, char: str = "*", hollow: bool = False) -> str:
16
+ """
17
+ Generate a centered pyramid of height `n`.
18
+
19
+ Parameters
20
+ ----------
21
+ n : int
22
+ The height of the pyramid. Must be a positive integer.
23
+ char : str, optional
24
+ The character used to build the pyramid (default is '*').
25
+ hollow : bool, optional
26
+ If True, generate a hollow pyramid (default is False).
27
+
28
+ Returns
29
+ -------
30
+ str
31
+ A string representation of the centered pyramid.
32
+
33
+ Raises
34
+ ------
35
+ ValueError
36
+ If `n` is not positive.
37
+
38
+ Examples
39
+ --------
40
+ >>> print(centered(4))
41
+ *
42
+ ***
43
+ *****
44
+ *******
45
+
46
+ >>> print(centered(4, hollow=True))
47
+ *
48
+ * *
49
+ * *
50
+ *******
51
+ """
52
+ if n <= 0:
53
+ raise ValueError("n must be positive")
54
+
55
+ lines = []
56
+ for i in range(1, n + 1):
57
+ spaces = " " * (n - i)
58
+ if not hollow:
59
+ stars = char * (2 * i - 1)
60
+ lines.append(spaces + stars)
61
+ else:
62
+ if i == 1:
63
+ line = spaces + char
64
+ elif i == n:
65
+ line = char * (2 * i - 1)
66
+ else:
67
+ line = spaces + char + " " * (2 * i - 3) + char
68
+ lines.append(line)
69
+ return "\n".join(lines)
70
+
71
+
72
+ def right_aligned(n: int, char: str = "*", hollow: bool = False) -> str:
73
+ """
74
+ Generate a right-aligned pyramid (staircase style) of height `n`.
75
+
76
+ Parameters
77
+ ----------
78
+ n : int
79
+ The height of the pyramid. Must be positive.
80
+ char : str, optional
81
+ The character used to build the pyramid (default is '*').
82
+ hollow : bool, optional
83
+ If True, generate a hollow right-aligned pyramid (default is False).
84
+
85
+ Returns
86
+ -------
87
+ str
88
+ A string representation of the right-aligned pyramid.
89
+
90
+ Raises
91
+ ------
92
+ ValueError
93
+ If `n` is not positive.
94
+
95
+ Examples
96
+ --------
97
+ >>> print(right_aligned(4))
98
+ *
99
+ **
100
+ ***
101
+ ****
102
+
103
+ >>> print(right_aligned(4, hollow=True))
104
+ *
105
+ **
106
+ * *
107
+ ****
108
+ """
109
+ if n <= 0:
110
+ raise ValueError("n must be positive")
111
+
112
+ lines = []
113
+ for i in range(1, n + 1):
114
+ if not hollow:
115
+ lines.append(char * i)
116
+ else:
117
+ if i == 1:
118
+ lines.append(char)
119
+ elif i == n:
120
+ lines.append(char * i)
121
+ else:
122
+ lines.append(char + " " * (i - 2) + char)
123
+ return "\n".join(lines)
124
+
125
+
126
+ def numeric(n: int) -> str:
127
+ """
128
+ Generate a numeric pyramid of height `n`.
129
+
130
+ Each row displays numbers from 1 up to the row number.
131
+
132
+ Parameters
133
+ ----------
134
+ n : int
135
+ The height of the pyramid. Must be positive.
136
+
137
+ Returns
138
+ -------
139
+ str
140
+ A string representation of the numeric pyramid.
141
+
142
+ Raises
143
+ ------
144
+ ValueError
145
+ If `n` is not positive.
146
+
147
+ Examples
148
+ --------
149
+ >>> print(numeric(4))
150
+ 1
151
+ 12
152
+ 123
153
+ 1234
154
+ """
155
+ if n <= 0:
156
+ raise ValueError("n must be positive")
157
+
158
+ lines = []
159
+ for i in range(1, n + 1):
160
+ line = " " * (n - i) + "".join(str(x) for x in range(1, i + 1))
161
+ lines.append(line)
162
+ return "\n".join(lines)
163
+
164
+
165
+ def make(n: int, variant: Literal["centered", "right", "numeric"] = "centered", char: str = "*") -> str:
166
+ """
167
+ Factory function to generate a pyramid of a specified variant.
168
+
169
+ Parameters
170
+ ----------
171
+ n : int
172
+ The height of the pyramid. Must be positive.
173
+ variant : {'centered', 'right', 'numeric'}, optional
174
+ The pyramid style to generate (default is 'centered'):
175
+ - 'centered': classic centered pyramid.
176
+ - 'right': right-aligned (staircase) pyramid.
177
+ - 'numeric': pyramid of ascending numbers (ignores `char`).
178
+ char : str, optional
179
+ The character used for drawing the pyramid (default is '*').
180
+ Ignored if `variant='numeric'`.
181
+
182
+ Returns
183
+ -------
184
+ str
185
+ A string representation of the chosen pyramid variant.
186
+
187
+ Raises
188
+ ------
189
+ ValueError
190
+ If `variant` is not one of the supported options.
191
+
192
+ Examples
193
+ --------
194
+ >>> print(make(4, variant='centered'))
195
+ *
196
+ ***
197
+ *****
198
+ *******
199
+
200
+ >>> print(make(4, variant='right', char='#'))
201
+ #
202
+ ##
203
+ ###
204
+ ####
205
+
206
+ >>> print(make(4, variant='numeric'))
207
+ 1
208
+ 12
209
+ 123
210
+ 1234
211
+ """
212
+ variants = {
213
+ "centered": centered,
214
+ "right": right_aligned,
215
+ "numeric": numeric,
216
+ }
217
+
218
+ if variant not in variants:
219
+ raise ValueError(
220
+ f"Unknown pyramid variant: {variant}. Available: {list(variants.keys())}"
221
+ )
222
+
223
+ return variants[variant](n, char) if variant != "numeric" else variants[variant](n)
@@ -0,0 +1,169 @@
1
+ from typing import Literal
2
+ import inspect
3
+
4
+ def classic(n: int, char: str = "*", hollow: bool = False, numeric: bool = False) -> str:
5
+ """
6
+ Generate a right-angled triangle of height `n`.
7
+
8
+ Parameters
9
+ ----------
10
+ n : int
11
+ The height of the triangle. Must be a positive integer.
12
+ char : str, optional
13
+ The character used to draw the triangle (default is '*').
14
+ hollow : bool, optional
15
+ If True, generate a hollow triangle (default is False).
16
+ numeric : bool, optional
17
+ If True, print numbers instead of characters (default is False).
18
+
19
+ Returns
20
+ -------
21
+ str
22
+ A string representation of the right-angled triangle.
23
+
24
+ Raises
25
+ ------
26
+ ValueError
27
+ If `n` is not positive or if `char` is passed while numeric=True.
28
+ """
29
+ if n <= 0:
30
+ raise ValueError("n must be positive")
31
+
32
+ # Disallow any explicit char when numeric=True
33
+ caller_args = inspect.currentframe().f_locals
34
+ if numeric and caller_args.get("char", "*") != "*":
35
+ raise ValueError("Cannot specify 'char' when numeric=True")
36
+
37
+ lines = []
38
+ for i in range(1, n + 1):
39
+ if numeric:
40
+ if not hollow:
41
+ line = "".join(str(x) for x in range(1, i + 1))
42
+ else:
43
+ if i == 1:
44
+ line = "1"
45
+ elif i == n:
46
+ line = "".join(str(x) for x in range(1, n + 1))
47
+ else:
48
+ line = "1" + " " * (i - 2) + str(i)
49
+ else:
50
+ if not hollow:
51
+ line = char * i
52
+ else:
53
+ if i == 1:
54
+ line = char
55
+ elif i == n:
56
+ line = char * n
57
+ else:
58
+ line = char + " " * (i - 2) + char
59
+ lines.append(line)
60
+ return "\n".join(lines)
61
+
62
+
63
+ def inverted(n: int, char: str = "*", hollow: bool = False, numeric: bool = False) -> str:
64
+ """
65
+ Generate an inverted right-angled triangle of height `n`.
66
+
67
+ Parameters
68
+ ----------
69
+ n : int
70
+ The height of the triangle. Must be a positive integer.
71
+ char : str, optional
72
+ The character used to draw the triangle (default is '*').
73
+ hollow : bool, optional
74
+ If True, generate a hollow triangle (default is False).
75
+
76
+ Returns
77
+ -------
78
+ str
79
+ A string representation of the inverted right-angled triangle.
80
+
81
+ Raises
82
+ ------
83
+ ValueError
84
+ If `n` is not positive or if `char` is passed while numeric=True.
85
+ """
86
+ if n <= 0:
87
+ raise ValueError("n must be positive")
88
+
89
+ # Disallow any explicit char when numeric=True
90
+ caller_args = inspect.currentframe().f_locals
91
+ if numeric and caller_args.get("char", "*") != "*":
92
+ raise ValueError("Cannot specify 'char' when numeric=True")
93
+
94
+ lines = []
95
+ for i in range(n, 0, -1):
96
+ if numeric:
97
+ if not hollow:
98
+ line = "".join(str(x) for x in range(1, i + 1))
99
+ else:
100
+ if i == 1:
101
+ line = "1"
102
+ elif i == n:
103
+ line = "".join(str(x) for x in range(1, n + 1))
104
+ else:
105
+ line = "1" + " " * (i - 2) + str(i)
106
+ else:
107
+ if not hollow:
108
+ line = char * i
109
+ else:
110
+ if i == 1:
111
+ line = char
112
+ elif i == n:
113
+ line = char * n
114
+ else:
115
+ line = char + " " * (i - 2) + char
116
+ lines.append(line)
117
+ return "\n".join(lines)
118
+
119
+
120
+ def make(n: int, variant: Literal["classic","inverted"] = "classic", char: str = "*") -> str:
121
+ """
122
+ Factory function to create a right-angled triangle of a specified variant.
123
+
124
+ Parameters
125
+ ----------
126
+ n : int
127
+ The height of the triangle. Must be positive.
128
+ variant : str, optional
129
+ The triangle variant. Options are:
130
+ - "classic": normal right-angled triangle (default)
131
+ - "inverted": inverted right-angled triangle
132
+ char : str, optional
133
+ The character used to draw the triangle (default is '*').
134
+
135
+ Returns
136
+ -------
137
+ str
138
+ A string representation of the chosen triangle variant.
139
+
140
+ Raises
141
+ ------
142
+ ValueError
143
+ If `variant` is not recognized.
144
+
145
+ Examples
146
+ --------
147
+ >>> print(make(4, variant="classic"))
148
+ *
149
+ **
150
+ ***
151
+ ****
152
+
153
+ >>> print(make(4, variant="inverted"))
154
+ ****
155
+ ***
156
+ **
157
+ *
158
+ """
159
+ variants = {
160
+ "classic": classic,
161
+ "inverted": inverted
162
+ }
163
+
164
+ if variant not in variants:
165
+ raise ValueError(
166
+ f"Unknown right-triangle variant: {variant}. Available: {list(variants.keys())}"
167
+ )
168
+
169
+ return variants[variant](n, char)
@@ -0,0 +1,22 @@
1
+ Metadata-Version: 2.4
2
+ Name: patlab
3
+ Version: 0.1.0
4
+ Summary: Simple pattern generation library for Python
5
+ Author-email: Sayam <sayampradhan07@outlook.com>
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/sayampradhan/patlab
8
+ Project-URL: Repository, https://github.com/sayampradhan/patlab
9
+ Project-URL: GitHub, https://github.com/sayampradhan
10
+ Requires-Python: >=3.8
11
+ Description-Content-Type: text/markdown
12
+ License-File: LICENSE
13
+ Dynamic: license-file
14
+
15
+ # patlab
16
+
17
+ Generate common patterns in Python easily.
18
+
19
+ ## Installation
20
+
21
+ ```bash
22
+ pip install patlab
@@ -0,0 +1,11 @@
1
+ LICENSE
2
+ README.md
3
+ pyproject.toml
4
+ patlab/__init__.py
5
+ patlab/basic.py
6
+ patlab/pyramid.py
7
+ patlab/right_triangle.py
8
+ patlab.egg-info/PKG-INFO
9
+ patlab.egg-info/SOURCES.txt
10
+ patlab.egg-info/dependency_links.txt
11
+ patlab.egg-info/top_level.txt
@@ -0,0 +1 @@
1
+ patlab
@@ -0,0 +1,18 @@
1
+ [project]
2
+ name = "patlab"
3
+ version = "0.1.0"
4
+ description = "Simple pattern generation library for Python"
5
+ authors = [{ name = "Sayam", email = "sayampradhan07@outlook.com" }]
6
+ readme = "README.md"
7
+ license = "MIT"
8
+ requires-python = ">=3.8"
9
+ dependencies = []
10
+
11
+ [build-system]
12
+ requires = ["setuptools", "wheel"]
13
+ build-backend = "setuptools.build_meta"
14
+
15
+ [project.urls]
16
+ "Homepage" = "https://github.com/sayampradhan/patlab"
17
+ "Repository" = "https://github.com/sayampradhan/patlab"
18
+ "GitHub" = "https://github.com/sayampradhan"
patlab-0.1.0/setup.cfg ADDED
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+