Skip to content

Commit daea622

Browse files
committed
fix: fixed linters so all tests should pass
1 parent f62f4a4 commit daea622

8 files changed

Lines changed: 25 additions & 14 deletions

File tree

Makefile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,3 @@ ruff:
1818

1919
flake8:
2020
flake8 ./src/python/
21-

src/python/app/command/parser.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@ def get_parser() -> ArgumentParser:
3434
subparser = parser.add_subparsers(required=True,
3535
help='Command to be performed on an image')
3636

37-
operation_class: type[Operation]
38-
for operation_class in [Rotate90Operation, IdentityOperation, FlipOperation, BGR2RGBOperation, RollOperation, GrayscaleOperation, HistogramEqualizationOperation]:
37+
for operation_class in available_commands():
3938
operation = operation_class()
4039

4140
operation_parser = subparser.add_parser(name=operation_class.name(),
@@ -46,6 +45,7 @@ def get_parser() -> ArgumentParser:
4645

4746
return parser
4847

48+
4949
def prepare_command(command: Operation) -> Callable[[Namespace], int]:
5050

5151
def wrapper(args: Namespace) -> int:
@@ -61,3 +61,15 @@ def wrapper(args: Namespace) -> int:
6161
return 0
6262

6363
return wrapper
64+
65+
66+
def available_commands():
67+
return [
68+
Rotate90Operation,
69+
IdentityOperation,
70+
FlipOperation,
71+
BGR2RGBOperation,
72+
RollOperation,
73+
GrayscaleOperation,
74+
HistogramEqualizationOperation,
75+
]

src/python/app/imcli.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1+
"""Main entrypoint for imcli program"""
2+
13
from app.command.parser import get_parser
24

35

46
def main() -> None:
57
args = get_parser().parse_args()
68
return args.func(args)
79

10+
811
if __name__ == '__main__':
912
main()

src/python/app/io/bmp.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ def read_format(self, file: BinaryIO) -> Image:
4646
assert panes == 1
4747
assert bits_per_pixel in (1, 4, 8, 16, 24, 32)
4848

49-
compression_method, raw_bitmap_data_size, horizontal_resolution, vertical_resolution, num_colors, num_important_colors = \
49+
compression_method, raw_bitmap_data_size, horizontal_resolution, vertical_resolution, \
50+
num_colors, num_important_colors = \
5051
struct.unpack('IIiiII', dib_header_no_size[12:])
5152
assert compression_method == 0
5253
assert raw_bitmap_data_size != 0
@@ -61,7 +62,8 @@ def read_format(self, file: BinaryIO) -> Image:
6162
num_colors_end = bits_per_pixel // 8
6263
return Image(data=np.flip(
6364
np.flip(
64-
np.frombuffer(bytes(image_bytes), dtype=np.uint8).reshape(image_height, image_width, num_colors_end)[:, :, ::-1],
65+
np.frombuffer(bytes(image_bytes),
66+
dtype=np.uint8).reshape(image_height, image_width, num_colors_end)[:, :, ::-1],
6567
axis=0
6668
),
6769
axis=1)

src/python/app/io/format_factory.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import enum
2-
from typing import Self
32

43
from app.error.unknown_format_exception import UnknownFormatException
54
from app.io.bmp import BMPReader, BMPWriter
@@ -11,7 +10,7 @@ class KnownFormat(enum.Enum):
1110
BMP = 0
1211

1312
@classmethod
14-
def from_string(cls, data_format: str) -> Self:
13+
def from_string(cls, data_format: str) -> 'KnownFormat':
1514
match data_format:
1615
case 'bmp':
1716
return cls.BMP
@@ -24,7 +23,7 @@ def get_available_formats(cls) -> list[str]:
2423
return [e.name.lower() for e in cls]
2524

2625
@classmethod
27-
def default(cls) -> Self:
26+
def default(cls) -> 'KnownFormat':
2827
return KnownFormat.BMP
2928

3029

@@ -37,6 +36,7 @@ def get_reader_from_format(data_format: KnownFormat) -> FormatReader:
3736
case _:
3837
assert False, "unreachable"
3938

39+
4040
def get_writer_from_format(data_format: KnownFormat) -> FormatWriter:
4141

4242
match data_format:

src/python/app/io/format_reader.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
from abc import abstractmethod, ABC
22
from typing import BinaryIO
33

4-
import numpy as np
5-
64
from app.image.image import Image
75

86

src/python/app/operation/histogram_equalization.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,4 @@ def equalize_chanel(self, image: np.ndarray) -> np.ndarray:
3737
cdf = (256 - 1) * cdf / cdf[-1]
3838

3939
image_equalized = np.interp(image.flatten(), bins[:-1], cdf)
40-
return image_equalized.reshape(image.shape)
40+
return image_equalized.reshape(image.shape)

src/python/app/operation/operation.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
from abc import ABC, abstractmethod
22
from argparse import Namespace, ArgumentParser
3-
from typing import final
4-
5-
import numpy as np
63

74
from app.image.image import Image
85

0 commit comments

Comments
 (0)