Skip to content

Commit e4eb41f

Browse files
authored
Switch Project to Ruff #179 (#180)
* [build] Switch from yapf to Ruff. * [general] Apply `ruff format` * [general] Apply `ruff check --fix` * [general] Finalize ruff lints and formatting
1 parent a9bef63 commit e4eb41f

24 files changed

+847
-586
lines changed
Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
1-
# Use YAPF to check DVR-Scan formatting (run `yapf -i -r dvr_scan tests` locally to fix)
2-
name: Check Code Format
1+
# Check DVR-Scan code lint warnings and formatting.
2+
name: Static Analysis
33

44
on:
55
pull_request:
66
paths:
7-
- .style.yapf
87
- dvr_scan/**
98
- tests/**
109
push:
1110
paths:
12-
- .style.yapf
1311
- dvr_scan/**
1412
- tests/**
1513

@@ -25,14 +23,21 @@ jobs:
2523
with:
2624
python-version: '3.13'
2725

28-
- name: Update pip
29-
run: python -m pip install --upgrade pip
30-
- name: Install yapf
31-
run: python -m pip install --upgrade yapf toml
32-
- name: Install DVR-Scan Dependencies
33-
run: python -m pip install -r requirements_headless.txt
26+
- name: Install Dependencies
27+
run: |
28+
python -m pip install --upgrade pip
29+
python -m pip install --upgrade yapf toml
30+
python -m pip install -r requirements_headless.txt
3431
35-
- name: Check Code Format (dvr_scan)
36-
run: python -m yapf --diff --recursive dvr_scan/
37-
- name: Check Code Format (tests)
38-
run: python -m yapf --diff --recursive tests/
32+
- name: Check Code Format (yapf)
33+
if: ${{ hashFiles('.style.yapf') != '' }}
34+
run: |
35+
python -m yapf --diff --recursive dvr_scan/
36+
python -m yapf --diff --recursive tests/
37+
38+
- name: Static Analysis (ruff)
39+
if: ${{ hashFiles('.style.yapf') == '' }}
40+
run: |
41+
python -m pip install --upgrade ruff
42+
python -m ruff check
43+
python -m ruff format --check

.style.yapf

Lines changed: 0 additions & 6 deletions
This file was deleted.

dist/post_release.py

Lines changed: 36 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
# -*- coding: utf-8 -*-
21
import glob
32
import os
43
import shutil
54
import sys
5+
66
sys.path.append(os.path.abspath("."))
77

88

@@ -11,39 +11,39 @@
1111

1212
# TODO: See if some these can be excluded in the .spec file.
1313
DIRECTORY_GLOBS = [
14-
'altgraph-*.dist-info',
15-
'certifi',
16-
'imageio',
17-
'imageio_ffmpeg',
18-
'importlib_metadata-*.dist-info',
19-
'matplotlib',
20-
'PIL',
21-
'PyQt5',
22-
'pip-*.dist-info',
23-
'psutil',
24-
'pyinstaller-*.dist-info',
25-
'setuptools-*.dist-info',
26-
'tcl8',
27-
'wheel-*.dist-info',
28-
'wx',
14+
"altgraph-*.dist-info",
15+
"certifi",
16+
"imageio",
17+
"imageio_ffmpeg",
18+
"importlib_metadata-*.dist-info",
19+
"matplotlib",
20+
"PIL",
21+
"PyQt5",
22+
"pip-*.dist-info",
23+
"psutil",
24+
"pyinstaller-*.dist-info",
25+
"setuptools-*.dist-info",
26+
"tcl8",
27+
"wheel-*.dist-info",
28+
"wx",
2929
]
3030

3131
FILE_GLOBS = [
32-
'_bz2.pyd',
33-
'_decimal.pyd',
34-
'_elementtree.pyd',
35-
'_hashlib.pyd',
36-
'_lzma.pyd',
37-
'_multiprocessing.pyd',
38-
'd3dcompiler*.dll',
39-
'kiwisolver.*.pyd',
40-
'libopenblas64_*', # There seems to be a second copy of this currently.
41-
'libEGL.dll',
42-
'libGLESv2.dll',
43-
'opengl32sw.dll',
44-
'Qt5*.dll',
45-
'wxbase*.dll',
46-
'wxmsw315u*.dll',
32+
"_bz2.pyd",
33+
"_decimal.pyd",
34+
"_elementtree.pyd",
35+
"_hashlib.pyd",
36+
"_lzma.pyd",
37+
"_multiprocessing.pyd",
38+
"d3dcompiler*.dll",
39+
"kiwisolver.*.pyd",
40+
"libopenblas64_*", # There seems to be a second copy of this currently.
41+
"libEGL.dll",
42+
"libGLESv2.dll",
43+
"opengl32sw.dll",
44+
"Qt5*.dll",
45+
"wxbase*.dll",
46+
"wxmsw315u*.dll",
4747
]
4848

4949
for dir_glob in DIRECTORY_GLOBS:
@@ -63,10 +63,9 @@
6363
os.rmdir(os.path.join(BASE_PATH, "dvr-scan"))
6464

6565

66-
6766
def write_version_file():
68-
6967
import dvr_scan
68+
7069
VERSION = dvr_scan.__version__
7170

7271
with open("dist/.version_info", "wb") as f:
@@ -78,7 +77,8 @@ def write_version_file():
7877
else:
7978
(maj, min, pat) = int(v[0]), int(v[1]), 0
8079

81-
f.write(f"""# UTF-8
80+
f.write(
81+
f"""# UTF-8
8282
#
8383
# For more details about fixed file info 'ffi' see:
8484
# http://msdn.microsoft.com/en-us/library/ms646997.aspx
@@ -121,4 +121,5 @@ def write_version_file():
121121
VarFileInfo([VarStruct(u'Translation', [1033, 1200])])
122122
]
123123
)
124-
""".encode())
124+
""".encode()
125+
)

dist/pre_release.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
# -*- coding: utf-8 -*-
21
import os
32
import sys
3+
44
sys.path.append(os.path.abspath("."))
55

66
import dvr_scan
7+
78
VERSION = dvr_scan.__version__
89

910
with open("dist/.version_info", "wb") as f:
@@ -13,7 +14,8 @@
1314
minor = elements[1]
1415
patch = elements[2] if len(elements) == 3 else 0
1516

16-
f.write(f"""# UTF-8
17+
f.write(
18+
f"""# UTF-8
1719
#
1820
# For more details about fixed file info 'ffi' see:
1921
# http://msdn.microsoft.com/en-us/library/ms646997.aspx
@@ -56,4 +58,5 @@
5658
VarFileInfo([VarStruct(u'Translation', [1033, 1200])])
5759
]
5860
)
59-
""".encode())
61+
""".encode()
62+
)

dvr_scan/__init__.py

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# -*- coding: utf-8 -*-
21
#
32
# DVR-Scan: Video Motion Event Detection & Extraction Tool
43
# --------------------------------------------------------------
@@ -33,13 +32,12 @@
3332
"""
3433

3534
import os
36-
import sys
3735
import pkgutil
36+
import sys
3837

3938
# Handle loading OpenCV. This **MUST** be first before any other DVR-Scan or third-party
4039
# packages are imported which might attempt to import the `cv2` module.
41-
import dvr_scan.opencv_loader as _
42-
40+
import dvr_scan.opencv_loader as _ # noqa: F401
4341
from dvr_scan.platform import init_logger
4442

4543
# Used for module/distribution identification.
@@ -54,20 +52,26 @@ def get_license_info() -> str:
5452
if getattr(sys, "frozen", False) and hasattr(sys, "_MEIPASS"):
5553
app_folder = os.path.abspath(os.path.dirname(sys.executable))
5654
license_files = ["LICENSE", "LICENSE-THIRDPARTY"]
57-
license_text = "\n".join([
58-
open(os.path.join(app_folder, license_file), "rb").read().decode("ascii", "ignore")
59-
for license_file in license_files
60-
])
55+
license_text = "\n".join(
56+
[
57+
open(os.path.join(app_folder, license_file), "rb")
58+
.read()
59+
.decode("ascii", "ignore")
60+
for license_file in license_files
61+
]
62+
)
6163
# Use the LICENSE file included with the package distribution.
6264
else:
6365
license_text = pkgutil.get_data(__name__, "LICENSE").decode("ascii", "ignore")
6466
return license_text
6567
# During development this is normal since the package paths won't be correct.
6668
except FileNotFoundError:
6769
pass
68-
return ("[DVR-Scan] Error: Missing LICENSE files.\n"
69-
"See the following URL for license/copyright information:\n"
70-
" < https://www.dvr-scan.com/resources >\n")
70+
return (
71+
"[DVR-Scan] Error: Missing LICENSE files.\n"
72+
"See the following URL for license/copyright information:\n"
73+
" < https://www.dvr-scan.com/resources >\n"
74+
)
7175

7276

7377
# Initialize logger.

dvr_scan/__main__.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# -*- coding: utf-8 -*-
21
#
32
# DVR-Scan: Video Motion Event Detection & Extraction Tool
43
# --------------------------------------------------------------
@@ -15,13 +14,13 @@
1514
"""
1615

1716
import logging
18-
from subprocess import CalledProcessError
1917
import sys
20-
21-
from dvr_scan.cli.controller import parse_settings, run_dvr_scan
18+
from subprocess import CalledProcessError
2219

2320
from scenedetect import VideoOpenFailure
24-
from scenedetect.platform import logging_redirect_tqdm, FakeTqdmLoggingRedirect
21+
from scenedetect.platform import FakeTqdmLoggingRedirect, logging_redirect_tqdm
22+
23+
from dvr_scan.cli.controller import parse_settings, run_dvr_scan
2524

2625
EXIT_SUCCESS: int = 0
2726
EXIT_ERROR: int = 1
@@ -33,9 +32,9 @@ def main():
3332
if settings is None:
3433
sys.exit(EXIT_ERROR)
3534
logger = logging.getLogger("dvr_scan")
36-
redirect = (FakeTqdmLoggingRedirect if settings.get("quiet-mode") else logging_redirect_tqdm)
35+
redirect = FakeTqdmLoggingRedirect if settings.get("quiet-mode") else logging_redirect_tqdm
3736
debug_mode = settings.get("debug")
38-
show_traceback = logging.DEBUG == getattr(logging, settings.get("verbosity").upper())
37+
show_traceback = getattr(logging, settings.get("verbosity").upper()) == logging.DEBUG
3938
with redirect(loggers=[logger]):
4039
try:
4140
run_dvr_scan(settings)
@@ -47,7 +46,7 @@ def main():
4746
logger.critical("Failed to load input: %s", str(ex), exc_info=show_traceback)
4847
if debug_mode:
4948
raise
50-
except KeyboardInterrupt as ex:
49+
except KeyboardInterrupt:
5150
logger.info("Stopping (interrupt received)...", exc_info=show_traceback)
5251
if debug_mode:
5352
raise

0 commit comments

Comments
 (0)