Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Transition from yapf to ruff #418

Merged
merged 8 commits into from
Sep 8, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions .github/workflows/build-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ jobs:
git checkout refs/remotes/origin/resources -- tests/resources/

- name: Download FFMPEG ${{ env.ffmpeg-version }}
uses: dsaltares/[email protected].1
uses: dsaltares/[email protected].2
with:
repo: 'GyanD/codexffmpeg'
version: 'tags/${{ env.ffmpeg-version }}'
Expand Down Expand Up @@ -91,10 +91,11 @@ jobs:
./dist/scenedetect/scenedetect -i tests/resources/goldeneye.mp4 detect-content time -e 2s

- name: Upload Artifact
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: PySceneDetect-win64_portable
path: dist/scenedetect
include-hidden-files: true

test:
runs-on: windows-latest
Expand All @@ -104,7 +105,7 @@ jobs:
with:
ref: resources

- uses: actions/download-artifact@v3
- uses: actions/download-artifact@v4.1.7
with:
name: PySceneDetect-win64_portable
path: build
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ jobs:

- name: Upload Package
if: ${{ matrix.python-version == '3.12' && matrix.os == 'ubuntu-latest' }}
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: scenedetect-dist
path: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/check-code-format.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
steps:
- uses: actions/checkout@v4
- name: Set up Python 3.12
uses: actions/setup-python@v3
uses: actions/setup-python@v5
with:
python-version: '3.12'
cache: 'pip'
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,15 @@ jobs:
uses: actions/checkout@v4

- name: Initialize CodeQL
uses: github/codeql-action/init@v2
uses: github/codeql-action/init@v3
with:
languages: ${{ matrix.language }}
queries: +security-and-quality

- name: Autobuild
uses: github/codeql-action/autobuild@v2
uses: github/codeql-action/autobuild@v3

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
uses: github/codeql-action/analyze@v3
with:
category: "/language:${{ matrix.language }}"
2 changes: 1 addition & 1 deletion .github/workflows/dependency-review.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ jobs:
- name: 'Checkout Repository'
uses: actions/checkout@v4
- name: 'Dependency Review'
uses: actions/dependency-review-action@v3
uses: actions/dependency-review-action@v4
29 changes: 20 additions & 9 deletions dist/pre_release.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@
sys.path.append(os.path.abspath("."))

import scenedetect


VERSION = scenedetect.__version__

if len(sys.argv) <= 2 or not ("--ignore-installer" in sys.argv):
run_version_check = ("--ignore-installer" not in sys.argv)

if run_version_check:
installer_aip = ''
with open("dist/installer/PySceneDetect.aip", "r") as f:
installer_aip = f.read()
Expand All @@ -16,12 +20,19 @@
with open("dist/.version_info", "wb") as f:
v = VERSION.split(".")
assert 2 <= len(v) <= 3, f"Unrecognized version format: {VERSION}"

if len(v) == 3:
(maj, min, pat) = int(v[0]), int(v[1]), int(v[2])
else:
(maj, min, pat) = int(v[0]), int(v[1]), 0

if len(v) < 3:
v.append("0")
(maj, min, pat, bld) = v[0], v[1], v[2], 0
# If either major or minor have suffixes, assume it's a dev/beta build and set
# the final component to 999.
if not min.isdigit():
assert "-" in min
min = min[:min.find("-")]
bld = 999
if not pat.isdigit():
assert "-" in pat
pat = pat[:pat.find("-")]
bld = 999
f.write(f"""# UTF-8
#
# For more details about fixed file info 'ffi' see:
Expand All @@ -30,8 +41,8 @@
ffi=FixedFileInfo(
# filevers and prodvers should be always a tuple with four items: (1, 2, 3, 4)
# Set not needed items to zero 0.
filevers=(0, {maj}, {min}, {pat}),
prodvers=(0, {maj}, {min}, {pat}),
filevers=({maj}, {min}, {pat}, {bld}),
prodvers=({maj}, {min}, {pat}, {bld}),
# Contains a bitmask that specifies the valid bits 'flags'r
mask=0x3f,
# Contains a bitmask that specifies the Boolean attributes of the file.
Expand Down
12 changes: 6 additions & 6 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,26 +27,26 @@ docstring-code-format = true

[tool.ruff.lint]
select = [
# flake8-bugbear
"B",
# pycodestyle
"E",
# Pyflakes
"F",
# isort
"I",
# TODO - Rule sets to enable:
# pyupgrade
#"UP",
# flake8-bugbear
#"B",
# flake8-simplify
#"SIM",
# isort
#"I",
]
ignore = [
# TODO: Determine if we should use __all__, a reudndant alias, or keep this suppressed.
"F401",
# Line too long
# TODO: Line too long
"E501",
# Do not assign a `lambda` expression, use a `def`
# TODO: Do not assign a `lambda` expression, use a `def`
"E731",
]
fixable = ["ALL"]
Expand Down
7 changes: 2 additions & 5 deletions scenedetect/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
can be used to open a video for a
:class:`SceneManager <scenedetect.scene_manager.SceneManager>`.
"""
# ruff: noqa: I001

from logging import getLogger
from typing import List, Optional, Tuple, Union
Expand All @@ -31,7 +30,7 @@
) from ex

# Commonly used classes/functions exported under the `scenedetect` namespace for brevity.
from scenedetect.platform import init_logger
from scenedetect.platform import init_logger # noqa: I001
from scenedetect.frame_timecode import FrameTimecode
from scenedetect.video_stream import VideoStream, VideoOpenFailure
from scenedetect.video_splitter import split_video_ffmpeg, split_video_mkvmerge
Expand All @@ -52,9 +51,7 @@
)
from scenedetect.stats_manager import StatsManager, StatsFileCorrupt
from scenedetect.scene_manager import SceneManager, save_images

# [DEPRECATED] DO NOT USE.
from scenedetect.video_manager import VideoManager
from scenedetect.video_manager import VideoManager # [DEPRECATED] DO NOT USE.

# Used for module identification and when printing version & about info
# (e.g. calling `scenedetect version` or `scenedetect about`).
Expand Down
2 changes: 1 addition & 1 deletion scenedetect/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def main():
raise
else:
logger.critical("Unhandled exception:", exc_info=ex)
raise SystemExit(1)
raise SystemExit(1) from None


if __name__ == "__main__":
Expand Down
5 changes: 0 additions & 5 deletions scenedetect/_cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
"""

# Some parts of this file need word wrap to be displayed.
# pylint: disable=line-too-long

import inspect
import logging
Expand Down Expand Up @@ -263,7 +262,6 @@ def _print_command_help(ctx: click.Context, command: click.Command):
help="Suppress output to terminal/stdout. Equivalent to setting --verbosity=none.",
)
@click.pass_context
# pylint: disable=redefined-builtin
def scenedetect(
ctx: click.Context,
input: ty.Optional[ty.AnyStr],
Expand Down Expand Up @@ -327,9 +325,6 @@ def scenedetect(
)


# pylint: enable=redefined-builtin


@click.command("help", cls=_Command)
@click.argument(
"command_name",
Expand Down
6 changes: 3 additions & 3 deletions scenedetect/_cli/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ def format(self, timecode: FrameTimecode) -> str:
return timecode.get_timecode()
if self == TimecodeFormat.SECONDS:
return "%.3f" % timecode.get_seconds()
assert False
raise RuntimeError("Unhandled format specifier.")


ConfigValue = Union[bool, int, float, str]
Expand Down Expand Up @@ -558,9 +558,9 @@ def _load_from_disk(self, path=None):
config_file_contents = config_file.read()
config.read_string(config_file_contents, source=path)
except ParsingError as ex:
raise ConfigLoadFailure(self._init_log, reason=ex)
raise ConfigLoadFailure(self._init_log, reason=ex) from None
except OSError as ex:
raise ConfigLoadFailure(self._init_log, reason=ex)
raise ConfigLoadFailure(self._init_log, reason=ex) from None
# At this point the config file syntax is correct, but we need to still validate
# the parsed options (i.e. that the options have valid values).
errors = _validate_structure(config)
Expand Down
11 changes: 6 additions & 5 deletions scenedetect/_cli/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ def check_split_video_requirements(use_mkvmerge: bool) -> None:
raise click.BadParameter(error_str, param_hint="split-video")


# pylint: disable=too-many-instance-attributes,too-many-arguments,too-many-locals
class CliContext:
"""Context of the command-line interface and config file parameters passed between sub-commands.
Expand Down Expand Up @@ -324,7 +323,7 @@ def handle_options(
scene_manager.downscale = downscale
except ValueError as ex:
logger.debug(str(ex))
raise click.BadParameter(str(ex), param_hint="downscale factor")
raise click.BadParameter(str(ex), param_hint="downscale factor") from None
scene_manager.interpolation = Interpolation[
self.config.get_value("global", "downscale-method").upper()
]
Expand Down Expand Up @@ -357,7 +356,7 @@ def get_detect_content_params(
weights = ContentDetector.Components(*weights)
except ValueError as ex:
logger.debug(str(ex))
raise click.BadParameter(str(ex), param_hint="weights")
raise click.BadParameter(str(ex), param_hint="weights") from None

return {
"weights": self.config.get_value("detect-content", "weights", weights),
Expand Down Expand Up @@ -415,7 +414,7 @@ def get_detect_adaptive_params(
weights = ContentDetector.Components(*weights)
except ValueError as ex:
logger.debug(str(ex))
raise click.BadParameter(str(ex), param_hint="weights")
raise click.BadParameter(str(ex), param_hint="weights") from None
return {
"adaptive_threshold": self.config.get_value("detect-adaptive", "threshold", threshold),
"weights": self.config.get_value("detect-adaptive", "weights", weights),
Expand Down Expand Up @@ -903,7 +902,9 @@ def _open_video_stream(
param_hint="-i/--input",
) from ex
except OSError as ex:
raise click.BadParameter("Input error:\n\n\t%s\n" % str(ex), param_hint="-i/--input")
raise click.BadParameter(
"Input error:\n\n\t%s\n" % str(ex), param_hint="-i/--input"
) from None

def _on_duplicate_command(self, command: str) -> None:
"""Called when a command is duplicated to stop parsing and raise an error.
Expand Down
1 change: 0 additions & 1 deletion scenedetect/backends/pyav.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
from logging import getLogger
from typing import AnyStr, BinaryIO, Optional, Tuple, Union

# pylint: disable=c-extension-no-member
import av
import numpy as np

Expand Down Expand Up @@ -100,7 +99,7 @@
try:
if isinstance(path_or_io, (str, bytes)):
self._path = path_or_io
self._io = open(path_or_io, "rb")
Dismissed Show dismissed Hide dismissed
if not self._name:
self._name = get_file_name(self.path, include_extension=False)
else:
Expand Down
4 changes: 1 addition & 3 deletions scenedetect/detectors/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@
processing videos, however they can also be used to process frames directly.
"""

# ruff: noqa: I001

from scenedetect.detectors.content_detector import ContentDetector
from scenedetect.detectors.content_detector import ContentDetector # noqa: I001
from scenedetect.detectors.threshold_detector import ThresholdDetector
from scenedetect.detectors.adaptive_detector import AdaptiveDetector
from scenedetect.detectors.hash_detector import HashDetector
Expand Down
12 changes: 0 additions & 12 deletions scenedetect/platform.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
class FakeTqdmObject:
"""Provides a no-op tqdm-like object."""

# pylint: disable=unused-argument
def __init__(self, **kawrgs):
"""No-op."""

Expand All @@ -49,13 +48,10 @@ def close(self):
def set_description(self, desc=None, refresh=True):
"""No-op."""

# pylint: enable=unused-argument


class FakeTqdmLoggingRedirect:
"""Provides a no-op tqdm context manager for redirecting log messages."""

# pylint: disable=redefined-builtin,unused-argument
def __init__(self, **kawrgs):
"""No-op."""

Expand All @@ -65,20 +61,14 @@ def __enter__(self):
def __exit__(self, type, value, traceback):
"""No-op."""

# pylint: enable=redefined-builtin,unused-argument


# Try to import tqdm and the logging redirect, otherwise provide fake implementations..
try:
# pylint: disable=unused-import
from tqdm import tqdm
from tqdm.contrib.logging import logging_redirect_tqdm
# pylint: enable=unused-import
except ModuleNotFoundError:
# pylint: disable=invalid-name
tqdm = FakeTqdmObject
logging_redirect_tqdm = FakeTqdmLoggingRedirect
# pylint: enable=invalid-name

##
## OpenCV imwrite Supported Image Types & Quality/Compression Parameters
Expand Down Expand Up @@ -254,10 +244,8 @@ def get_ffmpeg_path() -> Optional[str]:

# Try invoking ffmpeg using the one from `imageio_ffmpeg` if available.
try:
# pylint: disable=import-outside-toplevel
from imageio_ffmpeg import get_ffmpeg_exe

# pylint: enable=import-outside-toplevel
subprocess.call([get_ffmpeg_exe(), "-v", "quiet"])
return get_ffmpeg_exe()
# Gracefully handle case where imageio_ffmpeg is not available.
Expand Down
3 changes: 1 addition & 2 deletions scenedetect/scene_detector.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
from scenedetect.stats_manager import StatsManager


# pylint: disable=unused-argument, no-self-use
class SceneDetector:
"""Base class to inherit from when implementing a scene detection algorithm.
Expand Down Expand Up @@ -184,7 +183,7 @@ def filter(self, frame_num: int, above_threshold: bool) -> ty.List[int]:
return self._filter_merge(frame_num=frame_num, above_threshold=above_threshold)
elif self._mode == FlashFilter.Mode.SUPPRESS:
return self._filter_suppress(frame_num=frame_num, above_threshold=above_threshold)
assert False, "unhandled FlashFilter Mode!"
raise RuntimeError("Unhandled FlashFilter mode.")

def _filter_suppress(self, frame_num: int, above_threshold: bool) -> ty.List[int]:
min_length_met: bool = (frame_num - self._last_above) >= self._filter_length
Expand Down
Loading
Loading