Skip to content

Commit 0250782

Browse files
committed
minor bug fixes with cli
1 parent fabbe0b commit 0250782

File tree

6 files changed

+60
-181
lines changed

6 files changed

+60
-181
lines changed

build/lib/identicon/__init__.py

Lines changed: 0 additions & 4 deletions
This file was deleted.

build/lib/identicon/_generate/__init__.py

Lines changed: 0 additions & 98 deletions
This file was deleted.

build/lib/identicon/cli/__init__.py

Lines changed: 0 additions & 29 deletions
This file was deleted.

identicons/_generate/__init__.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,12 @@ def validate_and_convert_color(color):
7575

7676

7777

78-
def save(icon: np.ndarray, file: str, dir: str, height: int, width: int):
78+
def save(icon: np.ndarray, filepath: str, height: int, width: int):
7979
try:
80-
assert os.path.isdir(dir)
81-
assert file.lower().endswith(('.png', '.jpg', '.jpeg'))
80+
assert 100 <= height, f"{height} is far two small, the minimum height is 100 pixels"
81+
assert 100 <= width, f"{width} is far two small, the minimum width is 100 pixels"
82+
assert filepath.lower().endswith(('.png', '.jpg', '.jpeg'))
8283

83-
filepath = os.path.join(dir, file)
8484
i, j = icon.shape[:2]
8585
h, w = height // i, width // j
8686
large_identicon = np.repeat(icon, h, axis=0)
@@ -91,8 +91,9 @@ def save(icon: np.ndarray, file: str, dir: str, height: int, width: int):
9191
return temp
9292
except AssertionError as e:
9393
console.print("[bold red]Assertion Error:[/bold red]", e)
94+
raise e
9495
except Exception as e:
9596
console.print("[bold red]Error:[/bold red]", e)
97+
raise e
9698

97-
# Rest of your functions...
9899

identicons/cli/__init__.py

Lines changed: 54 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,63 @@
1-
__all__ = []
2-
31
import argparse
2+
43
from identicons._generate import generate, save
54

65
def main():
76

87
parser = argparse.ArgumentParser(description=f'CLI tool.')
9-
parser.add_argument('-t', '--text', required=True, help="" )
10-
parser.add_argument('-f', '--file', required=True, help="" )
11-
parser.add_argument('-p', '--primary', default='0x00', type=str, required=False, help="" )
12-
parser.add_argument('-s', '--secondary', default='0xffffff', type=str, required=False, help="" )
13-
parser.add_argument('-w', '--width', default=500, type=int, required=False, help="Specify the width of the output image.")
14-
parser.add_argument('-hi', '--height', default=500, type=int, required=False, help="Specify the height of the output image.")
15-
16-
parser.add_argument('-v', '--version', action='version', version='%(prog)s 0.1.3', help='byteTensor version ')
17-
18-
try:
19-
20-
args = parser.parse_args()
21-
primary, secondary = int(args.primary, 16), int(args.secondary, 16)
22-
icon = generate(args.text, primary, secondary)
23-
save(icon, args.file, "./", args.height, args.width)
24-
except Exception as e:
25-
raise e
8+
parser.add_argument(
9+
'-t', '--text',
10+
required=True,
11+
help="Input text from which to generate the identicon."
12+
)
13+
14+
parser.add_argument(
15+
'-f', '--file',
16+
required=True,
17+
help="Path to the output file where the identicon will be saved."
18+
)
19+
20+
parser.add_argument(
21+
'-p', '--primary',
22+
default='0xb4f8c8',
23+
type=str,
24+
required=False,
25+
help="Primary color for the identicon in hexadecimal format. Default is a mint green color."
26+
)
27+
28+
parser.add_argument(
29+
'-s', '--secondary',
30+
default='0xffffff',
31+
type=str,
32+
required=False,
33+
help="Secondary color for the identicon in hexadecimal format. Default is white."
34+
)
35+
36+
parser.add_argument(
37+
'-w', '--width',
38+
default=500,
39+
type=int,
40+
required=False,
41+
help="Specify the width of the output image in pixels. Default is 500."
42+
)
43+
44+
parser.add_argument(
45+
'-hi', '--height',
46+
default=500,
47+
type=int,
48+
required=False,
49+
help="Specify the height of the output image in pixels. Default is 500."
50+
)
51+
52+
53+
parser.add_argument('-v', '--version', action='version', version='%(prog)s 0.1.0', help='byteTensor version ')
54+
55+
56+
args = parser.parse_args()
57+
primary, secondary = int(args.primary, 16), int(args.secondary, 16)
58+
icon = generate(args.text, primary, secondary)
59+
60+
save(icon, args.file, args.height, args.width)
2661

2762

2863
if __name__ == "__name__":

identicons/cli/cli.py

Lines changed: 0 additions & 26 deletions
This file was deleted.

0 commit comments

Comments
 (0)