Skip to content

Commit c0d7c3a

Browse files
committed
[lint] Fix E731 warnings, add W rules, and un-exclude docs/
1 parent e67b0a3 commit c0d7c3a

3 files changed

Lines changed: 34 additions & 30 deletions

File tree

docs/generate_cli_docs.py

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@
2020
currentdir = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))
2121
parentdir = os.path.dirname(currentdir)
2222
sys.path.insert(0, parentdir)
23-
# Third-party imports
24-
import click
23+
# Third-party imports (must follow sys.path mutation above).
24+
import click # noqa: E402
2525

26-
from scenedetect._cli import scenedetect
26+
from scenedetect._cli import scenedetect # noqa: E402
2727

2828
StrGenerator = ty.Generator[str, None, None]
2929

@@ -80,7 +80,7 @@ def patch_help(s: str, commands: ty.List[str]) -> str:
8080

8181
for command in [command for command in commands if command not in INFO_COMMANDS]:
8282

83-
def add_link(_match: re.Match) -> str:
83+
def add_link(_match: re.Match, command: str = command) -> str:
8484
return ":ref:`%s <command-%s>`" % (command, command)
8585

8686
s = re.sub("``%s``(?!\\n)" % command, add_link, s)
@@ -116,7 +116,7 @@ def add_backquotes_with_refs(refs: ty.Set[str]) -> ty.Callable[[str], str]:
116116

117117
def _add_backquotes(s: re.Match) -> str:
118118
to_add: str = s.string[s.start() : s.end()]
119-
flag = re.search("-+[\w-]+[^\.\=\s\/]*", to_add)
119+
flag = re.search(r"-+[\w-]+[^\.\=\s\/]*", to_add)
120120
if flag is not None and flag.string[flag.start() : flag.end()] in refs:
121121
# add cross reference
122122
cross_ref = flag.string[flag.start() : flag.end()]
@@ -129,7 +129,7 @@ def _add_backquotes(s: re.Match) -> str:
129129

130130

131131
def extract_default_value(s: str) -> ty.Tuple[str, ty.Optional[str]]:
132-
default = re.search("\[default: .*\]", s)
132+
default = re.search(r"\[default: .*\]", s)
133133
if default is not None:
134134
span = default.span()
135135
assert span[1] == len(s)
@@ -145,11 +145,11 @@ def transform_add_option_refs(s: str, refs: ty.List[str]) -> str:
145145
# TODO: Match prefix of `global option` and add ref to parent `scenedetect` command option.
146146
# Replace patch to complete this.
147147
# -c/--command
148-
s = re.sub("-\w/--\w[\w-]*", transform, s)
148+
s = re.sub(r"-\w/--\w[\w-]*", transform, s)
149149
# --arg=value, --arg=1.2.3, --arg=1,2,3
150-
s = re.sub('-+[\w-]+=[^"\s\)]+(?<![\.\,])', transform, s)
150+
s = re.sub(r'-+[\w-]+=[^"\s\)]+(?<![\.\,])', transform, s)
151151
# --args=" command with spaces"
152-
s = re.sub('--[\w-]+[=]+".*?"', transform, s)
152+
s = re.sub(r'--[\w-]+[=]+".*?"', transform, s)
153153
return s
154154

155155

@@ -252,7 +252,9 @@ def create_help() -> ty.Tuple[str, ty.List[str]]:
252252
ctx = click.Context(scenedetect, info_name=scenedetect.name)
253253

254254
commands: ty.List[str] = ctx.command.list_commands(ctx)
255-
commands = list(filter(lambda command: not ctx.command.get_command(ctx, command).hidden, commands))
255+
commands = list(
256+
filter(lambda command: not ctx.command.get_command(ctx, command).hidden, commands)
257+
)
256258
# ctx.to_info_dict lacks metavar so we have to use the context directly.
257259
actions = [
258260
generate_title("``scenedetect`` 🎬 Command", level=0),
@@ -268,7 +270,10 @@ def create_help() -> ty.Tuple[str, ty.List[str]]:
268270
def main():
269271
help, commands = create_help()
270272
help = patch_help(help, commands)
271-
help = ".. NOTE: This file is auto-generated by docs/generate_cli_docs.py and should not be modified.\n" + help
273+
help = (
274+
".. NOTE: This file is auto-generated by docs/generate_cli_docs.py and should not be modified.\n"
275+
+ help
276+
)
272277
with open("docs/cli.rst", "wb") as f:
273278
f.write(help.encode())
274279

pyproject.toml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@ requires = ["setuptools"]
1313
build-backend = "setuptools.build_meta"
1414

1515
[tool.ruff]
16-
exclude = [
17-
"docs"
18-
]
1916
line-length = 100
2017
indent-width = 4
2118

@@ -31,6 +28,7 @@ select = [
3128
"B",
3229
# pycodestyle
3330
"E",
31+
"W",
3432
# Pyflakes
3533
"F",
3634
# isort
@@ -46,8 +44,6 @@ ignore = [
4644
"F401",
4745
# TODO: Line too long
4846
"E501",
49-
# TODO: Do not assign a `lambda` expression, use a `def`
50-
"E731",
5147
]
5248
fixable = ["ALL"]
5349
unfixable = []

scenedetect/output/video.py

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -129,20 +129,23 @@ def default_formatter(template: str) -> PathFormatter:
129129
`$START_PTS`, `$END_PTS` (presentation timestamp in milliseconds, accurate for VFR video)
130130
"""
131131
MIN_DIGITS = 3
132-
format_scene_number: PathFormatter = lambda video, scene: (
133-
("%0" + str(max(MIN_DIGITS, math.floor(math.log(video.total_scenes, 10)) + 1)) + "d")
134-
% (scene.index + 1)
135-
)
136-
formatter: PathFormatter = lambda video, scene: Template(template).safe_substitute(
137-
VIDEO_NAME=video.name,
138-
SCENE_NUMBER=format_scene_number(video, scene),
139-
START_TIME=str(scene.start.get_timecode().replace(":", ";")),
140-
END_TIME=str(scene.end.get_timecode().replace(":", ";")),
141-
START_FRAME=str(scene.start.frame_num),
142-
END_FRAME=str(scene.end.frame_num),
143-
START_PTS=str(round(scene.start.seconds * 1000)),
144-
END_PTS=str(round(scene.end.seconds * 1000)),
145-
)
132+
133+
def format_scene_number(video: VideoMetadata, scene: SceneMetadata) -> str:
134+
width = max(MIN_DIGITS, math.floor(math.log(video.total_scenes, 10)) + 1)
135+
return ("%0" + str(width) + "d") % (scene.index + 1)
136+
137+
def formatter(video: VideoMetadata, scene: SceneMetadata) -> str:
138+
return Template(template).safe_substitute(
139+
VIDEO_NAME=video.name,
140+
SCENE_NUMBER=format_scene_number(video, scene),
141+
START_TIME=str(scene.start.get_timecode().replace(":", ";")),
142+
END_TIME=str(scene.end.get_timecode().replace(":", ";")),
143+
START_FRAME=str(scene.start.frame_num),
144+
END_FRAME=str(scene.end.frame_num),
145+
START_PTS=str(round(scene.start.seconds * 1000)),
146+
END_PTS=str(round(scene.end.seconds * 1000)),
147+
)
148+
146149
return formatter
147150

148151

0 commit comments

Comments
 (0)