Skip to content

Commit b293d4a

Browse files
committed
refactor: Ruff check --fix + manual fixes
1 parent f1eb3a7 commit b293d4a

File tree

22 files changed

+89
-123
lines changed

22 files changed

+89
-123
lines changed

benchmark/benchmark_snapshot.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,7 @@ def benchmark(args, executor):
8080
image = Image.open(args.image)
8181
for resolution in [(800, 600), (1280, 720), (1920, 1080), (2560, 1440), (3840, 2160)]:
8282
image.resize(resolution).save("/tmp/platerec-benchmark.jpg")
83-
if args.blur:
84-
configs = [{}]
85-
else:
86-
configs = [{}, dict(mode="fast")]
83+
configs = [{}] if args.blur else [{}, dict(mode="fast")]
8784

8885
for config in configs:
8986
stats = list(
@@ -99,7 +96,7 @@ def benchmark(args, executor):
9996
)
10097
)
10198
yield dict(
102-
resolution="%sx%s" % resolution,
99+
resolution=f"{resolution[0]}x{resolution[1]}",
103100
mode=config.get("mode", "regular"),
104101
min=min(stats),
105102
max=max(stats),

blur/main.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,7 @@ def process(args, path: Path, output: Path, logo=None):
101101
}
102102
if args.copy_metadata:
103103
data["copy_metadata"] = "true"
104-
105-
if args.api_key:
106-
headers = {"Authorization": f"Token {args.api_key}"}
107-
else:
108-
headers = None
104+
headers = {"Authorization": f"Token {args.api_key}"} if args.api_key else None
109105

110106
response = requests.post(
111107
args.blur_url,

docker/platerec_installer/installer_helpers.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,7 @@ def verify_token(token, license_key, get_license=True, product="stream"):
117117
return False, "API token and license key is required."
118118
try:
119119
req = Request(
120-
"https://api.platerecognizer.com/v1/{}/{}/".format(
121-
path, license_key.strip()
122-
)
120+
f"https://api.platerecognizer.com/v1/{path}/{license_key.strip()}/"
123121
)
124122
req.add_header("Authorization", f"Token {token.strip()}")
125123
urlopen(req).read()

docker/platerec_installer/stream_config.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def send_request(section):
7878
if "/api/v1/webhook-receiver" not in section["webhook_target"]:
7979
return
8080
headers = {
81-
"Authorization": "Token %s" % section["webhook_header"].split("Token ")[-1]
81+
"Authorization": f"Token {section['webhook_header'].split('Token ')[-1]}"
8282
}
8383
url = section["webhook_target"].replace("webhook-receiver", "parking-list")
8484
try:
@@ -184,13 +184,13 @@ def base_config(config_path: Path, config=None):
184184
error_message = "[STR0021] The config.ini file does not seem to be formatted correctly. \n [Error details] \n"
185185
for section_list, key, error in errors:
186186
if error is False:
187-
error = "key %s is missing." % key
187+
error = f"key {key} is missing."
188188
elif key is not None:
189189
section_list.append(key)
190190
section_string = "/".join(section_list)
191191
logging.error("%s: %s", section_string, error)
192192
error = f"{section_string}, param: {key}, message: {error}"
193-
error_message += "\n%s" % error
193+
error_message += f"\n{error}"
194194
return (
195195
None,
196196
error_message

docker/sdk_manager/PlateRec_SDK_Manager.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -305,18 +305,14 @@ def uninstall():
305305
token, _ = get_token_input(get_license=False)
306306
if uninstall_choice == "1":
307307
stop_container(image)
308-
cmd = "docker run --rm -t -v license:/license -e TOKEN={} -e UNINSTALL=1 {}".format(
309-
token, image
310-
)
308+
cmd = f"docker run --rm -t -v license:/license -e TOKEN={token} -e UNINSTALL=1 {image}"
311309

312310
os.system(cmd)
313311
return main()
314312

315313
elif uninstall_choice == "2":
316314
container_id = stop_container(image)
317-
cmd = "docker run --rm -t -v license:/license -e TOKEN={} -e UNINSTALL=1 {}".format(
318-
token, image
319-
)
315+
cmd = f"docker run --rm -t -v license:/license -e TOKEN={token} -e UNINSTALL=1 {image}"
320316
os.system(cmd)
321317
container_id = get_container_id(image)
322318
if container_id:

ftp_and_sftp_processor.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -280,11 +280,7 @@ def is_linux_os(self, file_list):
280280
# check if OS is Linux or Windows
281281
for info in file_list:
282282
info_first_possition = info[0]
283-
if info_first_possition.startswith("d") or info_first_possition.startswith(
284-
"-"
285-
):
286-
return True
287-
return False
283+
return bool(info_first_possition.startswith("d") or info_first_possition.startswith("-"))
288284

289285
def set_ftp_binary_file(self, file, image):
290286
"""Retrieve a file in binary transfer mode

parkpow/auto-file-import-tool/src/config.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,9 @@ def load_config() -> dict[str, Any]:
116116
# Main reading logic (remains the same)
117117
if config.has_option(section, option):
118118
try:
119-
if data_type == int:
119+
if data_type is int:
120120
value = config.getint(section, option)
121-
elif data_type == bool:
121+
elif data_type is bool:
122122
value = config.getboolean(section, option)
123123
else:
124124
value = config.get(section, option) # type: ignore

parkpow/auto-file-import-tool/src/logger_setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,11 @@ def setup_logging():
4444
# logging.getLogger('urllib3').setLevel(logging.WARNING)
4545

4646
# Setup checker errors logger
47-
CHECKER_ERRORS_LOG_FILE = os.path.join(LOGS_FOLDER, "checker_errors.log")
47+
checker_errors_log_file = os.path.join(LOGS_FOLDER, "checker_errors.log")
4848
checker_errors_logger = logging.getLogger("checker_errors_logger")
4949
checker_errors_logger.setLevel(logging.WARNING)
5050
checker_errors_handler = RotatingFileHandler(
51-
CHECKER_ERRORS_LOG_FILE, maxBytes=1024 * 1024 * 5, backupCount=2
51+
checker_errors_log_file, maxBytes=1024 * 1024 * 5, backupCount=2
5252
)
5353
checker_errors_handler.setFormatter(log_format)
5454
checker_errors_logger.addHandler(checker_errors_handler)

parkpow/auto-file-import-tool/src/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def save_current_state(license_plates: set):
5252
logger.error(f"Error saving current state to {STATE_FILE}: {e}")
5353

5454

55-
def main():
55+
def main(): # noqa: C901 TODO: Break down to reduce cyclomatic complexity
5656
logger.info("Starting synchronization cycle.")
5757
all_monitoring_threads = []
5858

parkpow/csv-upload/main.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,7 @@ def parse_row_result(row: list):
118118
file = row[1]
119119
plate = ast.literal_eval(row[5])
120120
position_sec = row[3]
121-
if len(row[4]):
122-
direction = row[4]
123-
else:
124-
direction = None
121+
direction = row[4] if len(row[4]) else None
125122
vehicle = ast.literal_eval(row[6])
126123

127124
# if plate["props"] is None: # TODO how to handle such a case
@@ -132,10 +129,7 @@ def parse_row_result(row: list):
132129
# candidates,source_url,position_sec,direction
133130
file = row[4]
134131
position_sec = row[13]
135-
if len(row[14]):
136-
direction = row[14]
137-
else:
138-
direction = None
132+
direction = row[14] if len(row[14]) else None
139133
region = ast.literal_eval(row[9])
140134
plate = {
141135
"box": ast.literal_eval(row[5]),

0 commit comments

Comments
 (0)