Skip to content

Commit 3f50609

Browse files
committed
Add all needed noqa statements - to be removed in the future, one by one
1 parent b6f25e5 commit 3f50609

32 files changed

+189
-163
lines changed

src/zimscraperlib/download.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def download(
4242
self,
4343
url: str,
4444
options: Optional[Dict],
45-
wait: Optional[bool] = True,
45+
wait: Optional[bool] = True, # noqa: FBT002
4646
) -> Union[bool, Future]:
4747
"""Downloads video using initialized executor.
4848
@@ -63,8 +63,8 @@ def download(
6363

6464

6565
class YoutubeConfig(dict):
66-
options = {}
67-
defaults = {
66+
options = {} # noqa: RUF012
67+
defaults = { # noqa: RUF012
6868
"writethumbnail": True,
6969
"write_all_thumbnails": True,
7070
"writesubtitles": True,
@@ -105,14 +105,14 @@ def get_options(
105105

106106

107107
class BestWebm(YoutubeConfig):
108-
options = {
108+
options = { # noqa: RUF012
109109
"preferredcodec": "webm",
110110
"format": "best[ext=webm]/bestvideo[ext=webm]+bestaudio[ext=webm]/best",
111111
}
112112

113113

114114
class BestMp4(YoutubeConfig):
115-
options = {
115+
options = { # noqa: RUF012
116116
"preferredcodec": "mp4",
117117
"format": "best[ext=mp4]/bestvideo[ext=mp4]+bestaudio[ext=m4a]/best",
118118
}
@@ -171,7 +171,7 @@ def stream_file(
171171
byte_stream: Optional[io.BytesIO] = None,
172172
block_size: Optional[int] = 1024,
173173
proxies: Optional[dict] = None,
174-
only_first_block: Optional[bool] = False,
174+
only_first_block: Optional[bool] = False, # noqa: FBT002
175175
max_retries: Optional[int] = 5,
176176
headers: Optional[Dict[str, str]] = None,
177177
session: Optional[requests.Session] = None,

src/zimscraperlib/fix_ogvjs_dist.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ def fix_source_dir(source_vendors_path: Union[pathlib.Path, str]):
3434

3535

3636
def run():
37-
if len(sys.argv) < 2:
38-
print(f"Usage: {sys.argv[0]} <source_vendors_path>")
39-
print(
37+
if len(sys.argv) < 2: # noqa: PLR2004
38+
print(f"Usage: {sys.argv[0]} <source_vendors_path>") # noqa: T201
39+
print( # noqa: T201
4040
"\t<source_vendors_path>\tpath to your folder containing "
4141
"ogvjs/videojs/videojs-ogvjs."
4242
)

src/zimscraperlib/i18n.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
ISO_LEVELS = ["1", "2b", "2t", "3", "5"]
1414

1515

16-
class NotFound(ValueError):
16+
class NotFound(ValueError): # noqa: N818
1717
pass
1818

1919

@@ -126,7 +126,9 @@ def update_with_macro(lang_data: Dict, macro_data: Dict):
126126
return lang_data
127127

128128

129-
def get_language_details(query: str, failsafe: Optional[bool] = False) -> Dict:
129+
def get_language_details(
130+
query: str, failsafe: Optional[bool] = False # noqa: FBT002
131+
) -> Dict:
130132
"""language details dict from query.
131133
132134
Raises NotFound or return `und` language details if failsafe
@@ -142,7 +144,7 @@ def get_language_details(query: str, failsafe: Optional[bool] = False) -> Dict:
142144
143145
"""
144146

145-
if query.isalpha() and (2 <= len(query) <= 3):
147+
if query.isalpha() and (2 <= len(query) <= 3): # noqa: PLR2004
146148
# possibility of iso-639 code
147149
adjusted_query = query
148150
native_query = query

src/zimscraperlib/image/convertion.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def convert_image(
3030
fmt = format_for(dst)
3131
with PIL.Image.open(src) as image:
3232
if image.mode == "RGBA" and fmt in ALPHA_NOT_SUPPORTED or colorspace:
33-
image = image.convert(colorspace or "RGB")
33+
image = image.convert(colorspace or "RGB") # noqa: PLW2901
3434
save_image(image, dst, fmt, **params)
3535

3636

src/zimscraperlib/image/optimization.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,12 @@ def ensure_matches(
5353
def optimize_png(
5454
src: Union[pathlib.Path, io.BytesIO],
5555
dst: Optional[pathlib.Path] = None,
56-
reduce_colors: Optional[bool] = False,
56+
reduce_colors: Optional[bool] = False, # noqa: FBT002
5757
max_colors: Optional[int] = 256,
58-
fast_mode: Optional[bool] = True,
59-
remove_transparency: Optional[bool] = False,
58+
fast_mode: Optional[bool] = True, # noqa: FBT002
59+
remove_transparency: Optional[bool] = False, # noqa: FBT002
6060
background_color: Optional[Tuple[int, int, int]] = (255, 255, 255),
61-
**options,
61+
**options, # noqa: ARG001
6262
) -> Union[pathlib.Path, io.BytesIO]:
6363
"""method to optimize PNG files using a pure python external optimizer
6464
@@ -101,9 +101,9 @@ def optimize_jpeg(
101101
src: Union[pathlib.Path, io.BytesIO],
102102
dst: Optional[pathlib.Path] = None,
103103
quality: Optional[int] = 85,
104-
fast_mode: Optional[bool] = True,
105-
keep_exif: Optional[bool] = True,
106-
**options,
104+
fast_mode: Optional[bool] = True, # noqa: FBT002
105+
keep_exif: Optional[bool] = True, # noqa: FBT002
106+
**options, # noqa: ARG001
107107
) -> Union[pathlib.Path, io.BytesIO]:
108108
"""method to optimize JPEG files using a pure python external optimizer
109109
quality: JPEG quality (integer between 1 and 100)
@@ -130,7 +130,7 @@ def optimize_jpeg(
130130
had_exif = True
131131

132132
# only use progressive if file size is bigger
133-
use_progressive_jpg = orig_size > 10240 # 10KiB
133+
use_progressive_jpg = orig_size > 10240 # 10KiB # noqa: PLR2004
134134

135135
if fast_mode:
136136
quality_setting = quality
@@ -168,10 +168,10 @@ def optimize_jpeg(
168168
def optimize_webp(
169169
src: Union[pathlib.Path, io.BytesIO],
170170
dst: Optional[pathlib.Path] = None,
171-
lossless: Optional[bool] = False,
171+
lossless: Optional[bool] = False, # noqa: FBT002
172172
quality: Optional[int] = 60,
173173
method: Optional[int] = 6,
174-
**options,
174+
**options, # noqa: ARG001
175175
) -> Union[pathlib.Path, io.BytesIO]:
176176
"""method to optimize WebP using Pillow options
177177
lossless: Whether to use lossless compression (boolean)
@@ -213,10 +213,10 @@ def optimize_gif(
213213
dst: pathlib.Path,
214214
optimize_level: Optional[int] = 1,
215215
lossiness: Optional[int] = None,
216-
interlace: Optional[bool] = True,
217-
no_extensions: Optional[bool] = True,
216+
interlace: Optional[bool] = True, # noqa: FBT002
217+
no_extensions: Optional[bool] = True, # noqa: FBT002
218218
max_colors: Optional[int] = None,
219-
**options,
219+
**options, # noqa: ARG001
220220
) -> pathlib.Path:
221221
"""method to optimize GIFs using gifsicle >= 1.92
222222
optimize_level: Optimization level;
@@ -264,8 +264,8 @@ def optimize_gif(
264264
def optimize_image(
265265
src: pathlib.Path,
266266
dst: pathlib.Path,
267-
delete_src: Optional[bool] = False,
268-
convert: Optional[Union[bool, str]] = False,
267+
delete_src: Optional[bool] = False, # noqa: FBT002
268+
convert: Optional[Union[bool, str]] = False, # noqa: FBT002
269269
**options,
270270
) -> bool:
271271
"""Optimize image, automatically selecting correct optimizer

src/zimscraperlib/image/presets.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class WebpLow:
1818
ext = "webp"
1919
mimetype = f"{preset_type}/webp"
2020

21-
options = {
21+
options = { # noqa: RUF012
2222
"lossless": False,
2323
"quality": 40,
2424
"method": 6,
@@ -37,7 +37,7 @@ class WebpMedium:
3737
ext = "webp"
3838
mimetype = f"{preset_type}/webp"
3939

40-
options = {
40+
options = { # noqa: RUF012
4141
"lossless": False,
4242
"quality": 50,
4343
"method": 6,
@@ -56,7 +56,7 @@ class WebpHigh:
5656
ext = "webp"
5757
mimetype = f"{preset_type}/webp"
5858

59-
options = {
59+
options = { # noqa: RUF012
6060
"lossless": False,
6161
"quality": 90,
6262
"method": 6,
@@ -77,7 +77,7 @@ class GifLow:
7777
ext = "gif"
7878
mimetype = f"{preset_type}/gif"
7979

80-
options = {
80+
options = { # noqa: RUF012
8181
"optimize_level": 3,
8282
"max_colors": 256,
8383
"lossiness": 80,
@@ -100,7 +100,7 @@ class GifMedium:
100100
ext = "gif"
101101
mimetype = f"{preset_type}/gif"
102102

103-
options = {
103+
options = { # noqa: RUF012
104104
"optimize_level": 3,
105105
"lossiness": 20,
106106
"no_extensions": True,
@@ -122,7 +122,7 @@ class GifHigh:
122122
ext = "gif"
123123
mimetype = f"{preset_type}/gif"
124124

125-
options = {
125+
options = { # noqa: RUF012
126126
"optimize_level": 2,
127127
"lossiness": None,
128128
"no_extensions": True,
@@ -141,7 +141,7 @@ class PngLow:
141141
ext = "png"
142142
mimetype = f"{preset_type}/png"
143143

144-
options = {
144+
options = { # noqa: RUF012
145145
"reduce_colors": True,
146146
"remove_transparency": False,
147147
"max_colors": 256,
@@ -160,7 +160,7 @@ class PngMedium:
160160
ext = "png"
161161
mimetype = f"{preset_type}/png"
162162

163-
options = {
163+
options = { # noqa: RUF012
164164
"reduce_colors": False,
165165
"remove_transparency": False,
166166
"fast_mode": False,
@@ -178,7 +178,7 @@ class PngHigh:
178178
ext = "png"
179179
mimetype = f"{preset_type}/png"
180180

181-
options = {
181+
options = { # noqa: RUF012
182182
"reduce_colors": False,
183183
"remove_transparency": False,
184184
"fast_mode": True,
@@ -197,7 +197,7 @@ class JpegLow:
197197
ext = "png"
198198
mimetype = f"{preset_type}/png"
199199

200-
options = {
200+
options = { # noqa: RUF012
201201
"quality": 45,
202202
"keep_exif": False,
203203
"fast_mode": True,
@@ -216,7 +216,7 @@ class JpegMedium:
216216
ext = "jpg"
217217
mimetype = f"{preset_type}/jpeg"
218218

219-
options = {
219+
options = { # noqa: RUF012
220220
"quality": 65,
221221
"keep_exif": False,
222222
"fast_mode": True,
@@ -235,7 +235,7 @@ class JpegHigh:
235235
ext = "jpg"
236236
mimetype = f"{preset_type}/jpeg"
237237

238-
options = {
238+
options = { # noqa: RUF012
239239
"quality": 80,
240240
"keep_exif": True,
241241
"fast_mode": True,

src/zimscraperlib/image/probing.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313

1414
def get_colors(
15-
src: pathlib.Path, use_palette: Optional[bool] = True
15+
src: pathlib.Path, use_palette: Optional[bool] = True # noqa: FBT002
1616
) -> Tuple[str, str]:
1717
"""(main, secondary) HTML color codes from an image path"""
1818

@@ -22,7 +22,9 @@ def rgb_to_hex(r: int, g: int, b: int) -> str:
2222

2323
def solarize(r: int, g: int, b: int) -> Tuple[int, int, int]:
2424
# calculate solarized color for main
25-
h, l, s = colorsys.rgb_to_hls(float(r) / 256, float(g) / 256, float(b) / 256)
25+
h, l, s = colorsys.rgb_to_hls( # noqa: E741
26+
float(r) / 256, float(g) / 256, float(b) / 256
27+
)
2628
r2, g2, b2 = (int(x * 256) for x in colorsys.hls_to_rgb(h, 0.95, s))
2729
return r2, g2, b2
2830

@@ -48,13 +50,16 @@ def is_hex_color(text: str) -> bool:
4850
return re.search(r"^#(?:[0-9a-fA-F]{3}){1,2}$", text)
4951

5052

51-
def format_for(src: Union[pathlib.Path, io.BytesIO], from_suffix: bool = True) -> str:
53+
def format_for(
54+
src: Union[pathlib.Path, io.BytesIO],
55+
from_suffix: bool = True, # noqa: FBT001, FBT002
56+
) -> str:
5257
"""Pillow format of a given filename, either Pillow-detected or from suffix"""
5358
if not from_suffix:
5459
with PIL.Image.open(src) as img:
5560
return img.format
5661

57-
from PIL.Image import EXTENSION as ext_fmt_map
62+
from PIL.Image import EXTENSION as ext_fmt_map # noqa: N811
5863
from PIL.Image import init as init_pil
5964

6065
init_pil()

src/zimscraperlib/image/transformation.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def resize_image(
1818
height: Optional[int] = None,
1919
dst: Optional[Union[pathlib.Path, io.BytesIO]] = None,
2020
method: Optional[str] = "width",
21-
allow_upscaling: Optional[bool] = True,
21+
allow_upscaling: Optional[bool] = True, # noqa: FBT002
2222
**params: Optional[dict],
2323
) -> None:
2424
"""resize an image to requested dimensions
@@ -34,9 +34,13 @@ def resize_image(
3434
if allow_upscaling:
3535
height_width_ratio = float(image.size[1]) / float(image.size[0])
3636
if image.size[0] < width:
37-
image = image.resize((width, int(width * height_width_ratio)))
37+
image = image.resize( # noqa: PLW2901
38+
(width, int(width * height_width_ratio))
39+
)
3840
if height and image.size[1] < height:
39-
image = image.resize((int(height / height_width_ratio), height))
41+
image = image.resize( # noqa: PLW2901
42+
(int(height / height_width_ratio), height)
43+
)
4044

4145
# resize using the requested method
4246
if method == "width":

src/zimscraperlib/inputs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def handle_user_provided_file(
2020
source: Optional[Union[pathlib.Path, str]] = None,
2121
dest: Optional[pathlib.Path] = None,
2222
in_dir: Optional[pathlib.Path] = None,
23-
nocopy: bool = False,
23+
nocopy: bool = False, # noqa: FBT001, FBT002
2424
) -> Union[pathlib.Path, None]:
2525
"""path to downloaded or copied a user provided file (URL or path)
2626

src/zimscraperlib/logging.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,17 @@
1414
VERBOSE_DEPENDENCIES = ["urllib3", "PIL", "boto3", "botocore", "s3transfer"]
1515

1616

17-
def getLogger(
17+
def getLogger( # noqa: N802
1818
name: str,
1919
level: Optional[int] = logging.INFO,
2020
console: Optional[io.TextIOBase] = sys.stdout,
2121
log_format: Optional[str] = DEFAULT_FORMAT,
22-
file: Optional[pathlib.Path] = False,
22+
file: Optional[pathlib.Path] = False, # noqa: FBT002
2323
file_level: Optional[int] = None,
2424
file_format: Optional[str] = None,
2525
file_max: Optional[int] = 2**20,
2626
file_nb_backup: Optional[int] = 1,
27-
deps_level: Optional[int] = logging.WARNING,
27+
deps_level: Optional[int] = logging.WARNING, # noqa: ARG001
2828
additional_deps: Optional[Iterable] = None,
2929
):
3030
"""configured logger for most usages

0 commit comments

Comments
 (0)