Skip to content

Commit ad2e3ab

Browse files
committed
[build] Add pyright checks to analysis, add moviepy as dev dep
1 parent 2d97e2d commit ad2e3ab

6 files changed

Lines changed: 54 additions & 41 deletions

File tree

.github/workflows/build.yml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,6 @@ jobs:
5959
python -m pip install --upgrade pip build wheel virtualenv setuptools
6060
pip install -e .[dev] --only-binary av,opencv-python
6161
62-
- name: Install MoviePy
63-
# TODO: We can only run MoviePy tests on systems that have ffmpeg.
64-
if: ${{ runner.arch == 'X64' }}
65-
run: |
66-
pip install moviepy
67-
6862
- name: Checkout test resources
6963
run: |
7064
git fetch --depth=1 https://github.com/Breakthrough/PySceneDetect.git refs/heads/resources:refs/remotes/origin/resources
Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,13 @@ on:
77
- scenedetect/**
88
- tests/**
99
- pyproject.toml
10-
- .style.yapf
11-
- .github/workflows/check-code-format.yml
10+
- .github/workflows/static-analysis.yml
1211
push:
1312
paths:
1413
- scenedetect/**
1514
- tests/**
1615
- pyproject.toml
17-
- .style.yapf
18-
- .github/workflows/check-code-format.yml
16+
- .github/workflows/static-analysis.yml
1917

2018
jobs:
2119
check_format:
@@ -34,16 +32,14 @@ jobs:
3432
python -m pip install --upgrade pip
3533
python -m pip install -e .[dev] --only-binary av,opencv-python
3634
37-
- name: Check Code Format (yapf)
38-
if: ${{ hashFiles('.style.yapf') != '' }}
39-
run: |
40-
python -m pip install --upgrade yapf toml
41-
python -m yapf --diff --recursive scenedetect/ tests/
42-
4335
- name: Static Analysis (ruff)
44-
if: ${{ hashFiles('.style.yapf') == '' }}
4536
run: |
4637
python -m pip install --upgrade ruff
4738
python -m ruff check
4839
python -m ruff format --check
4940
41+
- name: Type Check (pyright)
42+
run: |
43+
python -m pip install pyright==1.1.408
44+
python -m pyright
45+

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ dependencies = [
5151
[project.optional-dependencies]
5252
pyav = ["av>=9.2"]
5353
moviepy = ["moviepy"]
54-
dev = ["av>=9.2", "pytest>=7.0"]
54+
dev = ["av>=9.2", "moviepy", "pytest>=7.0"]
5555
docs = ["Sphinx==7.0.1"]
5656
website = ["mkdocs==1.5.2", "jinja2>=3.1.6"]
5757

scenedetect/detectors/hash_detector.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ def hash_frame(frame_img, hash_size, factor) -> numpy.ndarray:
143143
dct_low_freq = dct_complete[:hash_size, :hash_size]
144144

145145
# Calculate the median of the low frequency informations
146-
med = numpy.median(dct_low_freq)
146+
med = numpy.median(numpy.asarray(dct_low_freq, dtype=numpy.float32))
147147

148148
# Transform the low frequency information into a binary image based on > or < median
149149
hash_img = dct_low_freq > med

scripts/generate_assets.py

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ class LogoOutput(NamedTuple):
2121
height: int
2222
source: Path
2323

24+
2425
# Colors matching the SVG design
2526
BG = (224, 232, 240, 255) # #e0e8f0
2627
FG = (42, 53, 69, 255) # #2a3545
@@ -55,9 +56,15 @@ class LogoOutput(NamedTuple):
5556

5657
LOGO_OUTPUTS: list[LogoOutput] = [
5758
LogoOutput(REPO_DIR / "docs" / "_static" / "pyscenedetect_logo.png", 900, 422, LOGO_SVG),
58-
LogoOutput(REPO_DIR / "docs" / "_static" / "pyscenedetect_logo_small.png", 300, 141, LOGO_BG_SVG),
59-
LogoOutput(REPO_DIR / "website" / "pages" / "img" / "pyscenedetect_logo.png", 640, 300, LOGO_BG_SVG),
60-
LogoOutput(REPO_DIR / "website" / "pages" / "img" / "pyscenedetect_logo_small.png", 462, 217, LOGO_SVG),
59+
LogoOutput(
60+
REPO_DIR / "docs" / "_static" / "pyscenedetect_logo_small.png", 300, 141, LOGO_BG_SVG
61+
),
62+
LogoOutput(
63+
REPO_DIR / "website" / "pages" / "img" / "pyscenedetect_logo.png", 640, 300, LOGO_BG_SVG
64+
),
65+
LogoOutput(
66+
REPO_DIR / "website" / "pages" / "img" / "pyscenedetect_logo_small.png", 462, 217, LOGO_SVG
67+
),
6168
]
6269

6370
SVG_FOR_SIZE: dict[int, Path] = {
@@ -82,7 +89,7 @@ def make_icon_16() -> Image.Image:
8289
px[i, 0] = BG
8390
px[i, 15] = BG
8491

85-
# Arm stripe gaps (rows 24): clear pixels not part of a complete stripe.
92+
# Arm stripe gaps (rows 2-4): clear pixels not part of a complete stripe.
8693
# A stripe x+y=s spans all 3 arm rows only when 5 <= s <= 16.
8794
for y in range(2, 5):
8895
for x in range(1, 15):
@@ -93,7 +100,7 @@ def make_icon_16() -> Image.Image:
93100
if not ((x + y) % 4 < 2 and 5 <= (x + y) <= 16):
94101
px[x, y] = BG
95102

96-
# Slate interior (rows 812, cols 312)
103+
# Slate interior (rows 8-12, cols 3-12)
97104
for y in range(8, 13):
98105
for x in range(3, 13):
99106
px[x, y] = BG
@@ -117,7 +124,16 @@ def find_inkscape() -> str:
117124
def render_svg(inkscape: str, svg: Path, output: Path, width: int, height: int):
118125
"""Render an SVG to a PNG at the given dimensions using Inkscape."""
119126
subprocess.run(
120-
[inkscape, str(svg), "--export-type=png", f"--export-filename={output}", "-w", str(width), "-h", str(height)],
127+
[
128+
inkscape,
129+
str(svg),
130+
"--export-type=png",
131+
f"--export-filename={output}",
132+
"-w",
133+
str(width),
134+
"-h",
135+
str(height),
136+
],
121137
check=True,
122138
capture_output=True,
123139
)
@@ -127,7 +143,8 @@ def render_logos(inkscape: str):
127143
"""Render the logo SVG to all required PNG outputs."""
128144
print("Rendering logo PNGs...")
129145
for entry in LOGO_OUTPUTS:
130-
print(f" {entry.path.relative_to(REPO_DIR)} ({entry.width}x{entry.height}) [source: {entry.source.name}]...")
146+
rel_path = entry.path.relative_to(REPO_DIR)
147+
print(f" {rel_path} ({entry.width}x{entry.height}) [source: {entry.source.name}]...")
131148
render_svg(inkscape, entry.source, entry.path, entry.width, entry.height)
132149
print(f" Done ({len(LOGO_OUTPUTS)} files).")
133150

@@ -147,7 +164,11 @@ def render_all_sizes(inkscape: str, work_dir: Path) -> list[Image.Image]:
147164
render_svg(inkscape, svg_path, png_path, size, size)
148165
img = Image.open(png_path).copy()
149166
if size in SHARPEN_AMOUNT:
150-
img = img.filter(ImageFilter.UnsharpMask(radius=SHARPEN_RADIUS, percent=SHARPEN_AMOUNT[size], threshold=0))
167+
img = img.filter(
168+
ImageFilter.UnsharpMask(
169+
radius=SHARPEN_RADIUS, percent=SHARPEN_AMOUNT[size], threshold=0
170+
)
171+
)
151172
print(f" Sharpened {size}x{size} (USM {SHARPEN_AMOUNT[size]}%)")
152173
img.save(png_path)
153174
images.append(img)

scripts/pre_release.py

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
REPO_DIR = Path(__file__).resolve().parent.parent
2222
sys.path.insert(0, str(REPO_DIR))
2323

24-
import scenedetect
24+
import scenedetect # noqa: E402
2525

2626
PACKAGING_DIR = REPO_DIR / "packaging"
2727
WINDOWS_DIR = PACKAGING_DIR / "windows"
@@ -30,30 +30,31 @@
3030

3131
VERSION = scenedetect.__version__
3232

33-
run_version_check = ("--release" in sys.argv)
33+
run_version_check = "--release" in sys.argv
3434

3535
if run_version_check:
36-
installer_aip = INSTALLER_AIP.read_text()
37-
aip_version = f"<ROW Property=\"ProductVersion\" Value=\"{VERSION}\" Options=\"32\"/>"
38-
assert aip_version in installer_aip, f"Installer project version does not match {VERSION}."
36+
installer_aip = INSTALLER_AIP.read_text()
37+
aip_version = f'<ROW Property="ProductVersion" Value="{VERSION}" Options="32"/>'
38+
assert aip_version in installer_aip, f"Installer project version does not match {VERSION}."
3939

4040
with VERSION_INFO.open("wb") as f:
4141
v = VERSION.split(".")
4242
assert 2 <= len(v) <= 4, f"Unrecognized version format: {VERSION}"
4343
while len(v) < 4:
44-
v.append("0")
44+
v.append("0")
4545
(maj, min, pat, bld) = v[0], v[1], v[2], v[3]
4646
# If either major or minor have suffixes, assume it's a dev/beta build and set
4747
# the final component to 999.
4848
if not min.isdigit():
49-
assert "-" in min
50-
min = min[:min.find("-")]
51-
bld = 999
49+
assert "-" in min
50+
min = min[: min.find("-")]
51+
bld = 999
5252
if not pat.isdigit():
53-
assert "-" in pat
54-
pat = pat[:pat.find("-")]
55-
bld = 999
56-
f.write(f"""# UTF-8
53+
assert "-" in pat
54+
pat = pat[: pat.find("-")]
55+
bld = 999
56+
f.write(
57+
f"""# UTF-8
5758
#
5859
# For more details about fixed file info 'ffi' see:
5960
# http://msdn.microsoft.com/en-us/library/ms646997.aspx
@@ -96,4 +97,5 @@
9697
VarFileInfo([VarStruct(u'Translation', [1033, 1200])])
9798
]
9899
)
99-
""".encode())
100+
""".encode()
101+
)

0 commit comments

Comments
 (0)