Skip to content

Commit

Permalink
lint: add and update configs
Browse files Browse the repository at this point in the history
120char line limit time
  • Loading branch information
tomato39 committed Jun 6, 2020
1 parent a5adeb2 commit 9158fc3
Show file tree
Hide file tree
Showing 9 changed files with 72 additions and 30 deletions.
7 changes: 7 additions & 0 deletions .flake8
@@ -0,0 +1,7 @@
[flake8]
count = True
ignore = W503,E226
max-line-length = 120
exclude = stubs/*
show-source = True
statistics = True
4 changes: 2 additions & 2 deletions .github/workflows/lint.yml
Expand Up @@ -23,6 +23,6 @@ jobs:
pip install .
pip install -U git+https://github.com/Irrational-Encoding-Wizardry/vsutil.git@stux-switch-to-package#egg=vsutil
- name: Running flake8
run: flake8 lvsfunc --count --ignore=E501,W503,E226 --show-source --statistics
run: flake8 lvsfunc
- name: Running mypy
run: mypy -p lvsfunc --show-column-numbers --show-error-codes --hide-error-context --no-error-summary
run: mypy -p lvsfunc
9 changes: 6 additions & 3 deletions lvsfunc/aa.py
Expand Up @@ -69,7 +69,8 @@ def nneedi3_clamp(clip: vs.VideoNode, strength: int = 1,
mask = kgf.retinex_edgemask(clip, 1).std.Binarize()
merged = clip.std.MaskedMerge(aa, mask, planes=0)
else:
mask = clip.std.Prewitt(planes=0).std.Binarize(planes=0).std.Maximum(planes=0).std.Convolution([1] * 9, planes=0)
mask = clip.std.Prewitt(planes=0).std.Binarize(planes=0) \
.std.Maximum(planes=0).std.Convolution([1] * 9, planes=0)
mask = get_y(mask)
merged = clip.std.MaskedMerge(aa, mask, planes=0)

Expand Down Expand Up @@ -165,7 +166,8 @@ def upscaled_sraa(clip: vs.VideoNode,
luma = get_y(clip)

nnargs: Dict[str, Any] = dict(nsize=0, nns=4, qual=2)
eeargs: Dict[str, Any] = dict(alpha=0.2, beta=0.6, gamma=40, nrad=2, mdis=20) # TAAmbk defaults are 0.5, 0.2, 20, 3, 30
# TAAmbk defaults are 0.5, 0.2, 20, 3, 30
eeargs: Dict[str, Any] = dict(alpha=0.2, beta=0.6, gamma=40, nrad=2, mdis=20)

ssw = round(clip.width * rfactor)
ssh = round(clip.height * rfactor)
Expand Down Expand Up @@ -195,7 +197,8 @@ def upscaled_sraa(clip: vs.VideoNode,
aa_y = core.eedi3m.EEDI3(aa_y, 0, 0, 0, sclip=core.nnedi3.nnedi3(aa_y, 0, 0, 0, **nnargs), **eeargs)

# Back to source clip height or given height
scaled = core.fmtc.resample(aa_y, w, h, kernel='gauss', invks=True, invkstaps=2, taps=1, a1=32) if sharp_downscale else core.resize.Spline36(aa_y, w, h)
scaled = (core.fmtc.resample(aa_y, w, h, kernel='gauss', invks=True, invkstaps=2, taps=1, a1=32)
if sharp_downscale else core.resize.Spline36(aa_y, w, h))

if rep:
scaled = util.pick_repair(scaled)(scaled, luma.resize.Spline36(w, h), rep)
Expand Down
15 changes: 10 additions & 5 deletions lvsfunc/comparison.py
Expand Up @@ -116,7 +116,9 @@ def stack_compare(*clips: vs.VideoNode,
stack = core.std.StackHorizontal(clips)
if warn:
if len(set([c.num_frames for c in clips])) != 1:
stack = core.text.Text(stack, "Clip Length Mismatch Detected! \nPlease make sure the lengths of all clips match!\n"+"".join(f"\nClip {i+1}: {c.num_frames} Frames" for i, c in enumerate(clips)), 2)
stack = core.text.Text(stack,
"Clip Length Mismatch Detected!\nPlease make sure the lengths of all clips match!\n"
+ "".join(f"\nClip {i+1}: {c.num_frames} Frames" for i, c in enumerate(clips)), 2)
return stack


Expand Down Expand Up @@ -170,7 +172,8 @@ def tvbd_diff(tv: vs.VideoNode, bd: vs.VideoNode,
:param tv: TV clip
:param bd: BD clip
:param thr: Threshold, <= 1 uses PlaneStatsDiff, >1 uses Max/Min. Max is 128 (Default: 72)
:param return_array: Return frames as an interleaved comparison (using py:func:`lvsfunc.comparison.compare`) (Default: False)
:param return_array: Return frames as an interleaved comparison (using py:func:`lvsfunc.comparison.compare`)
(Default: False)
"""
if thr > 128:
raise ValueError("tvbd_diff: \"thr\" should neither be nor exceed 128!'")
Expand All @@ -185,7 +188,9 @@ def tvbd_diff(tv: vs.VideoNode, bd: vs.VideoNode,
if diff.format is None:
raise ValueError("tvbd_diff: 'Variable-format clips not supported'")
t = float if diff.format.sample_type == vs.FLOAT else int
frames = [i for i, f in enumerate(diff.frames()) if get_prop(f, "PlaneStatsMin", t) <= thr or get_prop(f, "PlaneStatsMax", t) >= 255 - thr]
frames = [i for i, f in enumerate(diff.frames())
if get_prop(f, "PlaneStatsMin", t) <= thr
or get_prop(f, "PlaneStatsMax", t) >= 255 - thr]

if not frames:
raise ValueError("tvbd_diff: 'No differences found'")
Expand All @@ -198,8 +203,8 @@ def tvbd_diff(tv: vs.VideoNode, bd: vs.VideoNode,
if thr <= 1:
diff = core.std.MakeDiff(tv, bd)
diff = core.resize.Spline36(diff, get_w(576), 576).text.FrameNum(8)
tv, bd = core.resize.Spline36(tv, int(diff.width / 2), int(diff.height / 2)), core.resize.Spline36(bd, int(diff.width / 2), int(diff.height / 2))
tv, bd = tv.text.Text("Clip A", 3), bd.text.Text("Clip B", 1)
tv = core.resize.Spline36(tv, int(diff.width / 2), int(diff.height / 2)).text.Text("Clip A", 3)
bd = core.resize.Spline36(bd, int(diff.width / 2), int(diff.height / 2)).text.Text("Clip B", 3)
stacked = core.std.StackVertical([core.std.StackHorizontal([tv, bd]), diff])
return core.std.Splice([stacked[f] for f in frames])

Expand Down
3 changes: 2 additions & 1 deletion lvsfunc/deinterlace.py
Expand Up @@ -96,7 +96,8 @@ def _pp(n: int, f: vs.VideoFrame, clip: vs.VideoNode, pp: vs.VideoNode

clip = core.vivtc.VFM(clip, order=VFM_TFF, mode=1)
combmask = core.comb.CombMask(clip, cthresh=1, mthresh=3)
combmask = core.std.Maximum(combmask, threshold=250).std.Maximum(threshold=250).std.Maximum(threshold=250).std.Maximum(threshold=250)
combmask = core.std.Maximum(combmask, threshold=250).std.Maximum(threshold=250) \
.std.Maximum(threshold=250).std.Maximum(threshold=250)
combmask = core.std.BoxBlur(combmask, hradius=2, vradius=2)

qtgmc = QTGMC(clip, TFF=TFF, SourceMatch=3, Lossless=2, TR0=1, TR1=2, TR2=3, FPSDivisor=2)
Expand Down
6 changes: 4 additions & 2 deletions lvsfunc/denoise.py
Expand Up @@ -143,8 +143,10 @@ def detail_mask(clip: vs.VideoNode, pre_denoise: Optional[float] = None,
if clip.format is None:
raise ValueError("detail_mask: 'Variable-format clips not supported'")

den_a = core.knlm.KNLMeansCL(clip, d=2, a=3, h=pre_denoise, device_type='GPU') if pre_denoise is not None else clip
den_b = core.knlm.KNLMeansCL(clip, d=2, a=3, h=pre_denoise/2, device_type='GPU') if pre_denoise is not None else clip
den_a = (core.knlm.KNLMeansCL(clip, d=2, a=3, h=pre_denoise, device_type='GPU')
if pre_denoise is not None else clip)
den_b = (core.knlm.KNLMeansCL(clip, d=2, a=3, h=pre_denoise/2, device_type='GPU')
if pre_denoise is not None else clip)

mask_a = depth(get_y(den_a), 16) if clip.format.bits_per_sample < 32 else get_y(den_a)
mask_a = rangemask(mask_a, rad=rad, radc=radc)
Expand Down
26 changes: 17 additions & 9 deletions lvsfunc/misc.py
Expand Up @@ -33,7 +33,8 @@ def source(file: str, ref: Optional[vs.VideoNode] = None,
* vapoursynth-readmpls (optional: mpls sources)
:param file: Input file
:param ref: Use another clip as reference for the clip's format, resolution, and framerate (Default: None)
:param ref: Use another clip as reference for the clip's format,
resolution, and framerate (Default: None)
:param force_lsmas: Force files to be imported with L-SMASH (Default: False)
:param mpls: Load in a mpls file (Default: False)
:param mpls_playlist: Playlist number, which is the number in mpls file name (Default: 0)
Expand All @@ -49,7 +50,7 @@ def source(file: str, ref: Optional[vs.VideoNode] = None,

# Error handling for some file types
if file.endswith('.mpls') and mpls is False:
raise ValueError("source: 'Please set \"mpls = True\" and give a path to the base Blu-ray directory when trying to load in mpls files'")
raise ValueError("source: 'Please set \"mpls = True\" and give a path to the base Blu-ray directory when trying to load in mpls files'") # noqa: E501
if file.endswith('.vob') or file.endswith('.ts'):
raise ValueError("source: 'Please index VOB and TS files with d2v before importing them'")

Expand Down Expand Up @@ -81,7 +82,8 @@ def source(file: str, ref: Optional[vs.VideoNode] = None,
if ref.format is None:
raise ValueError("source: 'Variable-format clips not supported.'")
clip = core.std.AssumeFPS(clip, fpsnum=ref.fps.numerator, fpsden=ref.fps.denominator)
clip = core.resize.Bicubic(clip, width=ref.width, height=ref.height, format=ref.format.id, matrix_s=str(GetMatrix(ref)))
clip = core.resize.Bicubic(clip, width=ref.width, height=ref.height,
format=ref.format.id, matrix_s=str(GetMatrix(ref)))
if is_image(file):
clip = clip * (ref.num_frames - 1)

Expand Down Expand Up @@ -206,10 +208,11 @@ def _diff(n: int, f: vs.VideoFrame, clip: vs.VideoNode,
return clip if psa > threshold else filtered

if threshold_range and threshold_range > threshold:
raise ValueError(f"limit_dark: '\"threshold_range\" ({threshold_range}) must be a lower value than \"threshold\" ({threshold})'")
raise ValueError(f"limit_dark: '\"threshold_range\" ({threshold_range}) must be a lower value than \"threshold\" ({threshold})'") # noqa: E501

avg = core.std.PlaneStats(clip)
return core.std.FrameEval(clip, partial(_diff, clip=clip, filtered=filtered, threshold=threshold, threshold_range=threshold_range), avg)
return core.std.FrameEval(clip, partial(_diff, clip=clip, filtered=filtered,
threshold=threshold, threshold_range=threshold_range), avg)


def wipe_row(clip: vs.VideoNode, secondary: vs.VideoNode = Optional[None],
Expand Down Expand Up @@ -424,7 +427,9 @@ def colored_clips(amount: int,
**kwargs: Any
) -> List[vs.VideoNode]:
"""
Returns a list of BlankClips with unique colors (equally spaced in the HSL's hue domain) in sequential or random order.
Returns a list of BlankClips with unique colors in sequential or random order.
The colors will be evenly spaced by hue in the HSL colorspace.
Useful maybe for comparison functions or just for getting multiple uniquely colored BlankClips for testing purposes.
Will always return a pure red clip in the list as this is the RGB equivalent of the lowest HSL hue possible (0).
Expand All @@ -433,10 +438,13 @@ def colored_clips(amount: int,
:param amount: Number of ``vapoursynth.VideoNode``s to return
:param max_hue: Maximum hue (0 < hue <= 360) in degrees to generate colors from (uses the HSL color model).
Setting this higher than ``315`` will result in the clip colors looping back towards red and is not recommended for visually distinct colors.
If the `amount` of clips is higher than the `max_hue` expect there to be identical or visually similar colored clips returned (Default: 300)
Setting this higher than ``315`` will result in the clip colors looping back towards red
and is not recommended for visually distinct colors.
If the `amount` of clips is higher than the `max_hue` expect there to be identical
or visually similar colored clips returned (Default: 300)
:param rand: Randomizes order of the returned list (Default: True)
:param seed: Bytes-like object passed to ``random.seed`` which allows for consistent randomized order of the clips (Default: None)
:param seed: Bytes-like object passed to ``random.seed`` which allows for consistent randomized order
of the resulting clips (Default: None)
:param kwargs: Arguments passed to ``vapoursynth.core.std.BlankClip`` (Default: keep=1)
:return: List of uniquely colored clips in sequential or random order.
Expand Down
23 changes: 15 additions & 8 deletions lvsfunc/scale.py
Expand Up @@ -101,7 +101,8 @@ def reupscale(clip: vs.VideoNode,
:param clip: Input clip
:param width: Upscale width. If None, determine from `height` assuming 16:9 aspect ratio (Default: None)
:param height: Upscale height (Default: 1080)
:param kernel: Kernel used to downscale the doubled clip (see :py:class:`lvsfunc.kernels.Kernel`, Default: kernels.Bicubic(b=0, c=1/2))
:param kernel: Kernel used to downscale the doubled clip (see :py:class:`lvsfunc.kernels.Kernel`,
Default: kernels.Bicubic(b=0, c=1/2))
:param kwargs: Arguments passed to znedi3 (Default: nsize=4, nns=4, qual=2, pscrn=2)
:return: Reupscaled clip
Expand Down Expand Up @@ -173,15 +174,20 @@ def descale(clip: vs.VideoNode,
Dependencies: vapoursynth-descale, znedi3
:param clip: Clip to descale
:param upscaler: Callable function with signature upscaler(clip, width, height) -> vs.VideoNode to be used for reupscaling.
Must be capable of handling variable res clips for multiple heights and conditional scaling.
If a single height is given and upscaler is None, a constant resolution GRAY clip will be returned instead.
Note that if upscaler is None, no upscaling will be performed and neither detail masking nor
proper fractional descaling can be preformed. (Default: :py:func:`lvsfunc.scale.reupscale`)
:param upscaler: Callable function with signature upscaler(clip, width, height)
-> vs.VideoNode to be used for reupscaling.
Must be capable of handling variable res clips
for multiple heights and conditional scaling.
If a single height is given and upscaler is None,
a constant resolution GRAY clip will be returned instead.
Note that if upscaler is None, no upscaling will be performed
and neither detail masking nor proper fractional descaling can be preformed.
(Default: :py:func:`lvsfunc.scale.reupscale`)
:param width: Width to descale to (if None, auto-calculated)
:param height: Height(s) to descale to. List indicates multiple resolutions,
the function will determine the best. (Default: 720)
:param kernel: Kernel used to descale (see :py:class:`lvsfunc.kernels.Kernel`, Default: kernels.Bicubic(b=0, c=1/2))
:param kernel: Kernel used to descale (see :py:class:`lvsfunc.kernels.Kernel`,
(Default: kernels.Bicubic(b=0, c=1/2))
:param threshold: Error threshold for conditional descaling (Default: 0.0, always descale)
:param mask: Function used to mask detail. If ``None``, no masking.
Function must accept a clip and a reupscaled clip and return a mask.
Expand Down Expand Up @@ -296,7 +302,8 @@ def test_descale(clip: vs.VideoNode,
:param clip: Input clip
:param width: Target descale width. If None, determine from `height`
:param height: Target descale height (Default: 720)
:param kernel: Kernel used to descale (see :py:class:`lvsfunc.kernels.Kernel`, Default: kernels.Bicubic(b=0, c=1/2))
:param kernel: Kernel used to descale (see :py:class:`lvsfunc.kernels.Kernel`,
Default: kernels.Bicubic(b=0, c=1/2))
:param show_error: Render PlaneStatsDiff on the reupscaled frame (Default: True)
:return: A tuple containing a clip re-upscaled with the same kernel and
Expand Down
9 changes: 9 additions & 0 deletions mypy.ini
Expand Up @@ -5,8 +5,12 @@ python_version = 3.8

ignore_missing_imports = False

disallow_any_generics = True

disallow_untyped_defs = True
disallow_incomplete_defs = True
check_untyped_defs = True
disallow_untyped_decorators = True

no_implicit_optional = True
strict_optional = True
Expand All @@ -25,7 +29,12 @@ allow_redefinition = False
implicit_reexport = False
strict_equality = True

show_error_context = False
show_column_numbers = True
show_error_codes = True
color_output = True
error_summary = True
pretty = True

[mypy-cytoolz.*]
ignore_errors = True

0 comments on commit 9158fc3

Please sign in to comment.