Skip to content

Commit 6bd6dc8

Browse files
authored
Merge pull request #13 from ForNeus57/feature/pylint
feat: Added pyint linter
2 parents 9e55856 + f39e30a commit 6bd6dc8

24 files changed

+272
-125
lines changed

.github/workflows/python_linter.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,6 @@ jobs:
3232

3333
- name: Run flake8
3434
run: make flake8
35+
36+
- name: Run pylint
37+
run: make pylint

.pylintrc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[FORMAT]
2+
max-line-length=120

Makefile

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
all:
1+
all: clang-tidy mypy ruff flake8 pylint
22
echo 'All'
33

44
python-install:
@@ -23,4 +23,7 @@ ruff:
2323
ruff check ./src/python/
2424

2525
flake8:
26-
flake8 ./src/python/
26+
flake8 --ignore=E127 ./src/python/
27+
28+
pylint:
29+
pylint ./src/python/

setup.cfg

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@ console_scripts =
3535

3636
[options.extras_require]
3737
development =
38-
mypy==1.18.2,
39-
ruff==0.14.6,
40-
flake8==7.3.0,
41-
pylint==4.0.2,
38+
mypy==1.18.2
39+
ruff==0.14.6
40+
flake8==7.3.0
41+
pylint==4.0.2
4242
nbqa==1.9.1
4343
pytest==9.0.1
4444

src/python/app/command/io.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,21 @@
1+
"""Module for input/output operations related to parsing commandline"""
2+
13
from sys import stdin, stdout
24
from typing import BinaryIO
35

46

57
def map_input(input_source: str) -> BinaryIO:
8+
"""Maps input source to stdin or to the file path"""
9+
610
if input_source is None:
711
return stdin.buffer
812

913
return open(input_source, mode='rb')
1014

1115

1216
def map_output(output_source: str) -> BinaryIO:
17+
"""Maps output source to stdout or to the file path"""
18+
1319
if output_source is None:
1420
return stdout.buffer
1521

src/python/app/command/parser.py

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,23 @@
1+
"""Module containing functions that provide functionality related to commandline arguments parsing"""
2+
13
from argparse import ArgumentParser, Namespace
24
from typing import Callable
35

46
from app.command.io import map_input, map_output
57
from app.io.format_factory import get_reader_from_format, KnownFormat, get_writer_from_format
6-
from app.operation.bgr2rgb import BGR2RGBOperation
7-
from app.operation.flip import FlipOperation
8-
from app.operation.grayscale import GrayscaleOperation
9-
from app.operation.histogram_equalization import HistogramEqualizationOperation
10-
from app.operation.identity import IdentityOperation
11-
from app.operation.operation import Operation
12-
from app.operation.roll import RollOperation
13-
14-
from app.operation.rotate90 import Rotate90Operation
8+
from app.operation import Rotate90, Identity, Flip, BGR2RGB, Roll, Grayscale, HistogramEqualization, IOperation
159

1610

1711
def get_parser() -> ArgumentParser:
12+
"""Functions that initialises the Argument Parser"""
13+
1814
parser = ArgumentParser(prog='PROG',
1915
description='Image CLI that performs different image operations like scaling, rotating etc')
20-
parser.add_argument('input',
16+
parser.add_argument('--input',
2117
nargs='?',
2218
default=None,
2319
help='program input')
24-
parser.add_argument('output',
20+
parser.add_argument('--output',
2521
nargs='?',
2622
default=None,
2723
help='program output')
@@ -32,7 +28,7 @@ def get_parser() -> ArgumentParser:
3228
help='program output')
3329

3430
subparser = parser.add_subparsers(required=True,
35-
help='Command to be performed on an image')
31+
help='Command or operation to be performed on an image')
3632

3733
for operation_class in available_commands():
3834
operation = operation_class()
@@ -46,7 +42,8 @@ def get_parser() -> ArgumentParser:
4642
return parser
4743

4844

49-
def prepare_command(command: Operation) -> Callable[[Namespace], int]:
45+
def prepare_command(command: IOperation) -> Callable[[Namespace], int]:
46+
"""Function that decorates the operation in order to provide input and output to it"""
5047

5148
def wrapper(args: Namespace) -> int:
5249
data_format = KnownFormat.from_string(args.format)
@@ -64,12 +61,14 @@ def wrapper(args: Namespace) -> int:
6461

6562

6663
def available_commands():
64+
"""Function that returns all the supported commandline operations by the program"""
65+
6766
return [
68-
Rotate90Operation,
69-
IdentityOperation,
70-
FlipOperation,
71-
BGR2RGBOperation,
72-
RollOperation,
73-
GrayscaleOperation,
74-
HistogramEqualizationOperation,
67+
Rotate90,
68+
Identity,
69+
Flip,
70+
BGR2RGB,
71+
Roll,
72+
Grayscale,
73+
HistogramEqualization,
7574
]
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
1+
"""Module providing root class for all exceptions in this pacakge"""
2+
3+
14
class AppException(Exception):
2-
pass
5+
"""Root of the exceptions to provided by this package"""
Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
1+
"""Module providing invalid format exception"""
2+
13
from app.error.app_exception import AppException
24

35

4-
class UnknownFormatException(AppException):
5-
pass
6+
class InvalidFormatException(AppException):
7+
"""Class that signals that the format is known, but the is some error in the binary related to the image"""
8+
9+
def __init__(self, message: str) -> None:
10+
self.message = message
11+
12+
def __str__(self) -> str:
13+
return self.message

src/python/app/error/unknown_format_exception.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1+
"""Module providing unknown format exception"""
2+
13
from app.error.app_exception import AppException
24

35

46
class UnknownFormatException(AppException):
7+
"""The image is provided in unsupported format"""
58

69
def __init__(self, data_format: str) -> None:
710
self.data_format = data_format

src/python/app/image/image.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
"""Module implementing the image class used in the operations"""
2+
13
from dataclasses import dataclass
24
from typing import final
35

@@ -7,4 +9,6 @@
79
@final
810
@dataclass(slots=True)
911
class Image:
12+
"""Class that stores the image object as a numpy array"""
13+
1014
data: np.ndarray

0 commit comments

Comments
 (0)