Skip to content

Commit

Permalink
Switch Project to Ruff #179 (#180)
Browse files Browse the repository at this point in the history
* [build] Switch from yapf to Ruff.

* [general] Apply `ruff format`

* [general] Apply `ruff check --fix`

* [general] Finalize ruff lints and formatting
  • Loading branch information
Breakthrough authored Nov 29, 2024
1 parent a9bef63 commit e4eb41f
Show file tree
Hide file tree
Showing 24 changed files with 847 additions and 586 deletions.
33 changes: 19 additions & 14 deletions .github/workflows/check-code-format.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
# Use YAPF to check DVR-Scan formatting (run `yapf -i -r dvr_scan tests` locally to fix)
name: Check Code Format
# Check DVR-Scan code lint warnings and formatting.
name: Static Analysis

on:
pull_request:
paths:
- .style.yapf
- dvr_scan/**
- tests/**
push:
paths:
- .style.yapf
- dvr_scan/**
- tests/**

Expand All @@ -25,14 +23,21 @@ jobs:
with:
python-version: '3.13'

- name: Update pip
run: python -m pip install --upgrade pip
- name: Install yapf
run: python -m pip install --upgrade yapf toml
- name: Install DVR-Scan Dependencies
run: python -m pip install -r requirements_headless.txt
- name: Install Dependencies
run: |
python -m pip install --upgrade pip
python -m pip install --upgrade yapf toml
python -m pip install -r requirements_headless.txt
- name: Check Code Format (dvr_scan)
run: python -m yapf --diff --recursive dvr_scan/
- name: Check Code Format (tests)
run: python -m yapf --diff --recursive tests/
- name: Check Code Format (yapf)
if: ${{ hashFiles('.style.yapf') != '' }}
run: |
python -m yapf --diff --recursive dvr_scan/
python -m yapf --diff --recursive tests/
- name: Static Analysis (ruff)
if: ${{ hashFiles('.style.yapf') == '' }}
run: |
python -m pip install --upgrade ruff
python -m ruff check
python -m ruff format --check
6 changes: 0 additions & 6 deletions .style.yapf

This file was deleted.

71 changes: 36 additions & 35 deletions dist/post_release.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# -*- coding: utf-8 -*-
import glob
import os
import shutil
import sys

sys.path.append(os.path.abspath("."))


Expand All @@ -11,39 +11,39 @@

# TODO: See if some these can be excluded in the .spec file.
DIRECTORY_GLOBS = [
'altgraph-*.dist-info',
'certifi',
'imageio',
'imageio_ffmpeg',
'importlib_metadata-*.dist-info',
'matplotlib',
'PIL',
'PyQt5',
'pip-*.dist-info',
'psutil',
'pyinstaller-*.dist-info',
'setuptools-*.dist-info',
'tcl8',
'wheel-*.dist-info',
'wx',
"altgraph-*.dist-info",
"certifi",
"imageio",
"imageio_ffmpeg",
"importlib_metadata-*.dist-info",
"matplotlib",
"PIL",
"PyQt5",
"pip-*.dist-info",
"psutil",
"pyinstaller-*.dist-info",
"setuptools-*.dist-info",
"tcl8",
"wheel-*.dist-info",
"wx",
]

FILE_GLOBS = [
'_bz2.pyd',
'_decimal.pyd',
'_elementtree.pyd',
'_hashlib.pyd',
'_lzma.pyd',
'_multiprocessing.pyd',
'd3dcompiler*.dll',
'kiwisolver.*.pyd',
'libopenblas64_*', # There seems to be a second copy of this currently.
'libEGL.dll',
'libGLESv2.dll',
'opengl32sw.dll',
'Qt5*.dll',
'wxbase*.dll',
'wxmsw315u*.dll',
"_bz2.pyd",
"_decimal.pyd",
"_elementtree.pyd",
"_hashlib.pyd",
"_lzma.pyd",
"_multiprocessing.pyd",
"d3dcompiler*.dll",
"kiwisolver.*.pyd",
"libopenblas64_*", # There seems to be a second copy of this currently.
"libEGL.dll",
"libGLESv2.dll",
"opengl32sw.dll",
"Qt5*.dll",
"wxbase*.dll",
"wxmsw315u*.dll",
]

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



def write_version_file():

import dvr_scan

VERSION = dvr_scan.__version__

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

f.write(f"""# UTF-8
f.write(
f"""# UTF-8
#
# For more details about fixed file info 'ffi' see:
# http://msdn.microsoft.com/en-us/library/ms646997.aspx
Expand Down Expand Up @@ -121,4 +121,5 @@ def write_version_file():
VarFileInfo([VarStruct(u'Translation', [1033, 1200])])
]
)
""".encode())
""".encode()
)
9 changes: 6 additions & 3 deletions dist/pre_release.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
# -*- coding: utf-8 -*-
import os
import sys

sys.path.append(os.path.abspath("."))

import dvr_scan

VERSION = dvr_scan.__version__

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

f.write(f"""# UTF-8
f.write(
f"""# UTF-8
#
# For more details about fixed file info 'ffi' see:
# http://msdn.microsoft.com/en-us/library/ms646997.aspx
Expand Down Expand Up @@ -56,4 +58,5 @@
VarFileInfo([VarStruct(u'Translation', [1033, 1200])])
]
)
""".encode())
""".encode()
)
26 changes: 15 additions & 11 deletions dvr_scan/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
#
# DVR-Scan: Video Motion Event Detection & Extraction Tool
# --------------------------------------------------------------
Expand Down Expand Up @@ -33,13 +32,12 @@
"""

import os
import sys
import pkgutil
import sys

# Handle loading OpenCV. This **MUST** be first before any other DVR-Scan or third-party
# packages are imported which might attempt to import the `cv2` module.
import dvr_scan.opencv_loader as _

import dvr_scan.opencv_loader as _ # noqa: F401
from dvr_scan.platform import init_logger

# Used for module/distribution identification.
Expand All @@ -54,20 +52,26 @@ def get_license_info() -> str:
if getattr(sys, "frozen", False) and hasattr(sys, "_MEIPASS"):
app_folder = os.path.abspath(os.path.dirname(sys.executable))
license_files = ["LICENSE", "LICENSE-THIRDPARTY"]
license_text = "\n".join([
open(os.path.join(app_folder, license_file), "rb").read().decode("ascii", "ignore")
for license_file in license_files
])
license_text = "\n".join(
[
open(os.path.join(app_folder, license_file), "rb")
.read()
.decode("ascii", "ignore")
for license_file in license_files
]
)
# Use the LICENSE file included with the package distribution.
else:
license_text = pkgutil.get_data(__name__, "LICENSE").decode("ascii", "ignore")
return license_text
# During development this is normal since the package paths won't be correct.
except FileNotFoundError:
pass
return ("[DVR-Scan] Error: Missing LICENSE files.\n"
"See the following URL for license/copyright information:\n"
" < https://www.dvr-scan.com/resources >\n")
return (
"[DVR-Scan] Error: Missing LICENSE files.\n"
"See the following URL for license/copyright information:\n"
" < https://www.dvr-scan.com/resources >\n"
)


# Initialize logger.
Expand Down
15 changes: 7 additions & 8 deletions dvr_scan/__main__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
#
# DVR-Scan: Video Motion Event Detection & Extraction Tool
# --------------------------------------------------------------
Expand All @@ -15,13 +14,13 @@
"""

import logging
from subprocess import CalledProcessError
import sys

from dvr_scan.cli.controller import parse_settings, run_dvr_scan
from subprocess import CalledProcessError

from scenedetect import VideoOpenFailure
from scenedetect.platform import logging_redirect_tqdm, FakeTqdmLoggingRedirect
from scenedetect.platform import FakeTqdmLoggingRedirect, logging_redirect_tqdm

from dvr_scan.cli.controller import parse_settings, run_dvr_scan

EXIT_SUCCESS: int = 0
EXIT_ERROR: int = 1
Expand All @@ -33,9 +32,9 @@ def main():
if settings is None:
sys.exit(EXIT_ERROR)
logger = logging.getLogger("dvr_scan")
redirect = (FakeTqdmLoggingRedirect if settings.get("quiet-mode") else logging_redirect_tqdm)
redirect = FakeTqdmLoggingRedirect if settings.get("quiet-mode") else logging_redirect_tqdm
debug_mode = settings.get("debug")
show_traceback = logging.DEBUG == getattr(logging, settings.get("verbosity").upper())
show_traceback = getattr(logging, settings.get("verbosity").upper()) == logging.DEBUG
with redirect(loggers=[logger]):
try:
run_dvr_scan(settings)
Expand All @@ -47,7 +46,7 @@ def main():
logger.critical("Failed to load input: %s", str(ex), exc_info=show_traceback)
if debug_mode:
raise
except KeyboardInterrupt as ex:
except KeyboardInterrupt:
logger.info("Stopping (interrupt received)...", exc_info=show_traceback)
if debug_mode:
raise
Expand Down
Loading

0 comments on commit e4eb41f

Please sign in to comment.