Skip to content

Commit b970a1e

Browse files
authored
Merge pull request #11 from ForNeus57/fix/linters
fix: fixed linters so all tests should pass
2 parents f62f4a4 + 7f3bf9a commit b970a1e

13 files changed

Lines changed: 108 additions & 89 deletions

File tree

.github/workflows/cpp_linter.yaml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: C++ Linters
2+
3+
on:
4+
push:
5+
branches:
6+
- '**'
7+
pull_request:
8+
branches:
9+
- '**'
10+
11+
jobs:
12+
cpp_linter:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: Checkout
16+
uses: actions/checkout@v3
17+
- name: Python Setup
18+
uses: actions/setup-python@v3
19+
with:
20+
python-version: 3.13
21+
22+
- name: Install libraries
23+
run: make python-install-development
24+
25+
- name: clang-tidy
26+
run: make clang-tidy

.github/workflows/cpp_linters.yaml

Lines changed: 0 additions & 34 deletions
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,32 @@
1-
name: Linters
2-
3-
on:
4-
push:
5-
branches:
6-
- '**'
7-
pull_request:
8-
branches:
9-
- '**'
10-
11-
jobs:
12-
test:
13-
runs-on: ubuntu-latest
14-
steps:
15-
- name: Checkout
16-
uses: actions/checkout@v3
17-
- name: Python Setup
18-
uses: actions/setup-python@v3
19-
with:
20-
python-version: 3.13
21-
22-
- name: Install libraries
23-
run: make python-install-development
24-
25-
- name: mypy
26-
run: make mypy
27-
28-
- name: ruff
29-
run: make ruff
30-
31-
- name: flake8
32-
run: make flake8
1+
name: Python Linters
2+
3+
on:
4+
push:
5+
branches:
6+
- '**'
7+
pull_request:
8+
branches:
9+
- '**'
10+
11+
jobs:
12+
python_linter:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: Checkout
16+
uses: actions/checkout@v3
17+
- name: Python Setup
18+
uses: actions/setup-python@v3
19+
with:
20+
python-version: 3.13
21+
22+
- name: Install libraries
23+
run: make python-install-development
24+
25+
- name: mypy
26+
run: make mypy
27+
28+
- name: ruff
29+
run: make ruff
30+
31+
- name: flake8
32+
run: make flake8

Makefile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ python-install-development:
1010
python-install-editable:
1111
pip3 install -e .[development]
1212

13+
clang-tidy:
14+
clang-tidy $(shell find ./src/cpp/ -name '*.hpp' -o -name '*.cpp') -- -I$(shell python3 -c "import sysconfig; print(sysconfig.get_path('include'))") -I$(shell python3 -c "import numpy; print(numpy.get_include())")
15+
1316
mypy:
1417
mypy ./src/python/
1518

@@ -18,4 +21,3 @@ ruff:
1821

1922
flake8:
2023
flake8 ./src/python/
21-

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# CPython-based Extension for Image Manipulation
22

3+
[![C++ Linters](https://github.com/ForNeus57/advanced-python-programming-project/actions/workflows/cpp_linter.yaml/badge.svg)](https://github.com/ForNeus57/advanced-python-programming-project/actions/workflows/cpp_linter.yaml)
4+
[![Python Linters](https://github.com/ForNeus57/advanced-python-programming-project/actions/workflows/python_linter.yaml/badge.svg)](https://github.com/ForNeus57/advanced-python-programming-project/actions/workflows/python_linter.yaml)
5+
36
<!-- TOC -->
47
* [CPython-based Extension for Image Manipulation](#cpython-based-extension-for-image-manipulation)
58
* [Team members](#team-members)

src/cpp/fast/foo.cpp

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,31 +9,39 @@ numpy_system(PyObject *self, PyObject *args)
99
int sts;
1010

1111
if (!PyArg_ParseTuple(args, "s", &command))
12+
{
1213
return NULL;
14+
}
15+
1316
sts = system(command);
1417
return PyLong_FromLong(sts);
1518
}
1619

1720
static PyObject *
18-
numpy_add(PyObject *self, PyObject *args){
21+
numpy_add(PyObject *self, PyObject *args)
22+
{
1923
PyArrayObject *arr;
2024
PyArg_ParseTuple(args, "O", &arr);
21-
if(PyErr_Occurred()){
25+
if(PyErr_Occurred())
26+
{
2227
return NULL;
2328
}
24-
if(!PyArray_Check(arr) || PyArray_TYPE(arr) != NPY_DOUBLE) {
29+
if(!PyArray_Check(arr) || PyArray_TYPE(arr) != NPY_DOUBLE)
30+
{
2531
PyErr_SetString(PyExc_TypeError, "Argument must be a numpy array of type double!");
2632
return NULL;
2733
}
2834

2935

30-
double *data = (double *) PyArray_DATA(arr);
36+
double *data = reinterpret_cast<double *>(PyArray_DATA(arr));
3137
int64_t size = PyArray_SIZE(arr);
3238

33-
double total=0;
34-
for (int i=0; i < size; i++){
39+
double total = 0;
40+
for (int i = 0; i < size; i++)
41+
{
3542
total += data[i];
3643
}
44+
3745
return PyFloat_FromDouble(total);
3846
}
3947

@@ -42,13 +50,15 @@ static PyObject *SpamError = NULL;
4250
static int
4351
numpy_module_exec(PyObject *m)
4452
{
45-
if (SpamError != NULL) {
53+
if (SpamError != NULL)
54+
{
4655
PyErr_SetString(PyExc_ImportError,
4756
"cannot initialize numpy module more than once");
4857
return -1;
4958
}
5059
SpamError = PyErr_NewException("numpy.error", NULL, NULL);
51-
if (PyModule_AddObjectRef(m, "SpamError", SpamError) < 0) {
60+
if (PyModule_AddObjectRef(m, "SpamError", SpamError) < 0)
61+
{
5262
return -1;
5363
}
5464

@@ -62,7 +72,7 @@ static PyMethodDef numpy_methods[] = {
6272
};
6373

6474
static PyModuleDef_Slot numpy_module_slots[] = {
65-
{Py_mod_exec, (void*) numpy_module_exec},
75+
{Py_mod_exec, reinterpret_cast<void*>(numpy_module_exec)},
6676
{0, NULL}
6777
};
6878

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:

0 commit comments

Comments
 (0)