Skip to content

Commit c6281c3

Browse files
committed
ran ruff formatter & check-fix
1 parent 1dcf8b5 commit c6281c3

78 files changed

Lines changed: 752 additions & 402 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

docsrc/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
]
4343
# Looks for objects in external projects
4444

45-
autodoc_typehints = 'description'
45+
autodoc_typehints = "description"
4646
# autodoc_type_aliases = {'AgentAssignment': 'AgentAssignment'}
4747

4848
# Add any paths that contain templates here, relative to this directory.

docsrc/examples/audio_create.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,6 @@
2121

2222
x = audio.create("sine", f=220, b=4, d=5, r=fs)
2323

24-
t = np.arange(x.shape[0],dtype=float)*fs
24+
t = np.arange(x.shape[0], dtype=float) * fs
2525
plt.plot(t, x)
26-
plt.show()
26+
plt.show()

docsrc/examples/plotting.ipynb

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@
5151
"metadata": {},
5252
"outputs": [],
5353
"source": [
54-
"sns.set() # Use seaborn's default style to make attractive graphs\n",
55-
"plt.rcParams['figure.dpi'] = 100 # Show nicely large images in this notebook"
54+
"sns.set() # Use seaborn's default style to make attractive graphs\n",
55+
"plt.rcParams[\"figure.dpi\"] = 100 # Show nicely large images in this notebook"
5656
]
5757
},
5858
{
@@ -89,7 +89,7 @@
8989
"plt.xlim([snd.xmin, snd.xmax])\n",
9090
"plt.xlabel(\"time [s]\")\n",
9191
"plt.ylabel(\"amplitude\")\n",
92-
"plt.show() # or plt.savefig(\"sound.png\"), or plt.savefig(\"sound.pdf\")"
92+
"plt.show() # or plt.savefig(\"sound.png\"), or plt.savefig(\"sound.pdf\")"
9393
]
9494
},
9595
{
@@ -138,13 +138,14 @@
138138
"def draw_spectrogram(spectrogram, dynamic_range=70):\n",
139139
" X, Y = spectrogram.x_grid(), spectrogram.y_grid()\n",
140140
" sg_db = 10 * np.log10(spectrogram.values)\n",
141-
" plt.pcolormesh(X, Y, sg_db, vmin=sg_db.max() - dynamic_range, cmap='afmhot')\n",
141+
" plt.pcolormesh(X, Y, sg_db, vmin=sg_db.max() - dynamic_range, cmap=\"afmhot\")\n",
142142
" plt.ylim([spectrogram.ymin, spectrogram.ymax])\n",
143143
" plt.xlabel(\"time [s]\")\n",
144144
" plt.ylabel(\"frequency [Hz]\")\n",
145145
"\n",
146+
"\n",
146147
"def draw_intensity(intensity):\n",
147-
" plt.plot(intensity.xs(), intensity.values.T, linewidth=3, color='w')\n",
148+
" plt.plot(intensity.xs(), intensity.values.T, linewidth=3, color=\"w\")\n",
148149
" plt.plot(intensity.xs(), intensity.values.T, linewidth=1)\n",
149150
" plt.grid(False)\n",
150151
" plt.ylim(0)\n",
@@ -190,10 +191,10 @@
190191
"def draw_pitch(pitch):\n",
191192
" # Extract selected pitch contour, and\n",
192193
" # replace unvoiced samples by NaN to not plot\n",
193-
" pitch_values = pitch.selected_array['frequency']\n",
194-
" pitch_values[pitch_values==0] = np.nan\n",
195-
" plt.plot(pitch.xs(), pitch_values, 'o', markersize=5, color='w')\n",
196-
" plt.plot(pitch.xs(), pitch_values, 'o', markersize=2)\n",
194+
" pitch_values = pitch.selected_array[\"frequency\"]\n",
195+
" pitch_values[pitch_values == 0] = np.nan\n",
196+
" plt.plot(pitch.xs(), pitch_values, \"o\", markersize=5, color=\"w\")\n",
197+
" plt.plot(pitch.xs(), pitch_values, \"o\", markersize=2)\n",
197198
" plt.grid(False)\n",
198199
" plt.ylim(0, pitch.ceiling)\n",
199200
" plt.ylabel(\"fundamental frequency [Hz]\")"
@@ -217,7 +218,9 @@
217218
"# If desired, pre-emphasize the sound fragment before calculating the spectrogram\n",
218219
"pre_emphasized_snd = snd.copy()\n",
219220
"pre_emphasized_snd.pre_emphasize()\n",
220-
"spectrogram = pre_emphasized_snd.to_spectrogram(window_length=0.03, maximum_frequency=8000)"
221+
"spectrogram = pre_emphasized_snd.to_spectrogram(\n",
222+
" window_length=0.03, maximum_frequency=8000\n",
223+
")"
221224
]
222225
},
223226
{
@@ -249,8 +252,9 @@
249252
"source": [
250253
"import pandas as pd\n",
251254
"\n",
255+
"\n",
252256
"def facet_util(data, **kwargs):\n",
253-
" digit, speaker_id = data[['digit', 'speaker_id']].iloc[0]\n",
257+
" digit, speaker_id = data[[\"digit\", \"speaker_id\"]].iloc[0]\n",
254258
" sound = parselmouth.Sound(\"audio/{}_{}.wav\".format(digit, speaker_id))\n",
255259
" draw_spectrogram(sound.to_spectrogram())\n",
256260
" plt.twinx()\n",
@@ -260,13 +264,14 @@
260264
" plt.ylabel(\"\")\n",
261265
" plt.yticks([])\n",
262266
"\n",
267+
"\n",
263268
"results = pd.read_csv(\"other/digit_list.csv\")\n",
264269
"\n",
265-
"grid = sns.FacetGrid(results, row='speaker_id', col='digit')\n",
270+
"grid = sns.FacetGrid(results, row=\"speaker_id\", col=\"digit\")\n",
266271
"grid.map_dataframe(facet_util)\n",
267272
"grid.set_titles(col_template=\"{col_name}\", row_template=\"{row_name}\")\n",
268273
"grid.set_axis_labels(\"time [s]\", \"frequency [Hz]\")\n",
269-
"grid.set(facecolor='white', xlim=(0, None))\n",
274+
"grid.set(facecolor=\"white\", xlim=(0, None))\n",
270275
"plt.show()"
271276
]
272277
}

docsrc/examples/video_create.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
im = plt.imshow(A[0, ...])
1111
i = 0
1212

13+
1314
# initialization function: plot the background of each frame
1415
def init():
1516
im.set_data(A[i, ...])
@@ -26,4 +27,4 @@ def animate(i):
2627
fig, animate, frames=A.shape[0], init_func=init, interval=1000 / 25, blit=True
2728
)
2829

29-
plt.show()
30+
plt.show()

src/ffmpegio/__init__.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,10 @@ def __getattr__(name):
5757
# isort: off
5858
# fmt: off
5959

60-
from . import ffmpegprocess
61-
6260
from .errors import FFmpegError, FFmpegioError
6361
from .utils.concat import FFConcat
6462
from .filtergraph import Graph as FilterGraph
65-
from . import devices, ffmpegprocess, caps, probe, audio, image, video, media # noqa
63+
from . import devices, ffmpegprocess, caps, probe, audio, image, video, media
6664
from .transcode import transcode
6765
from .utils.parser import FLAG
6866
from ._open import open

src/ffmpegio/_open.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
from .filtergraph import Graph as FilterGraph
99

10+
1011
def open(
1112
url_fg: str,
1213
mode: str,
@@ -24,7 +25,7 @@ def open(
2425
:type url_fg: str or seq(str)
2526
:param mode: specifies the mode in which the FFmpeg is used, see below
2627
:type mode: str
27-
:param rate_in: (write and filter only, required) input frame rate (video) or sampling rate
28+
:param rate_in: (write and filter only, required) input frame rate (video) or sampling rate
2829
(audio), defaults to None
2930
:type rate_in: Fraction, float, int, optional
3031
:param shape_in: (write and filter only) input video frame size (height x width [x ncomponents]),
@@ -61,11 +62,11 @@ def open(
6162
a corresponding stream object. If the file cannot be opened, an error is raised.
6263
See :ref:`quick-streamio` for more examples of how to use this function.
6364
64-
Just like built-in `open()`, it is good practice to use the with keyword when dealing with
65-
ffmpegio stream objects. The advantage is that the ffmpeg process and associated threads are
66-
properly closed after ffmpeg terminates, even if an exception is raised at some point.
65+
Just like built-in `open()`, it is good practice to use the with keyword when dealing with
66+
ffmpegio stream objects. The advantage is that the ffmpeg process and associated threads are
67+
properly closed after ffmpeg terminates, even if an exception is raised at some point.
6768
Using with is also much shorter than writing equivalent try-finally blocks.
68-
69+
6970
:Examples:
7071
7172
Open an MP4 file and process all the frames::

src/ffmpegio/_utils.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,13 @@ def strict_zip():
4848
if items:
4949
i = len(items)
5050
plural = " " if i == 1 else "s 1-"
51-
msg = f"zip() argument {i+1} is shorter than argument{plural}{i}"
51+
msg = f"zip() argument {i + 1} is shorter than argument{plural}{i}"
5252
raise ValueError(msg)
5353
sentinel = object()
5454
for i, iterator in enumerate(iterators[1:], 1):
5555
if next(iterator, sentinel) is not sentinel:
5656
plural = " " if i == 1 else "s 1-"
57-
msg = f"zip() argument {i+1} is longer than argument{plural}{i}"
57+
msg = f"zip() argument {i + 1} is longer than argument{plural}{i}"
5858
raise ValueError(msg)
5959

6060
return strict_zip()
@@ -242,7 +242,6 @@ def unescape(txt: str) -> str:
242242
in_quote = True
243243

244244
while i0 < n:
245-
246245
if in_quote:
247246
# find the end quote
248247
i1 = txt.find("'", i0)

src/ffmpegio/analyze.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
"""media analysis tools module
2-
3-
"""
1+
"""media analysis tools module"""
42

53
from __future__ import annotations
64
from collections import namedtuple

src/ffmpegio/audio.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
"""Audio Read/Write Module
2-
"""
1+
"""Audio Read/Write Module"""
32

43
import warnings
54
from . import ffmpegprocess, utils, configure, FFmpegError, plugins, analyze

src/ffmpegio/configure.py

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
IO,
55
Literal,
66
get_args,
7-
LiteralString,
87
Any,
98
TypedDict,
109
Unpack,
@@ -29,7 +28,8 @@
2928

3029

3130
from fractions import Fraction
32-
import re, logging
31+
import re
32+
import logging
3333

3434
logger = logging.getLogger("ffmpegio")
3535

@@ -138,7 +138,7 @@ def array_to_video_input(
138138

139139
return (
140140
pipe_id or "-",
141-
{**utils.array_to_video_options(data)[0], f"r": rate, **opts},
141+
{**utils.array_to_video_options(data)[0], "r": rate, **opts},
142142
)
143143

144144

@@ -161,7 +161,7 @@ def array_to_audio_input(
161161

162162
return (
163163
pipe_id or "-",
164-
{**utils.array_to_audio_options(data)[0], f"ar": rate, **opts},
164+
{**utils.array_to_audio_options(data)[0], "ar": rate, **opts},
165165
)
166166

167167

@@ -366,7 +366,6 @@ def finalize_video_read_opts(
366366

367367
# directly from the input url (if not forced via input options)
368368
if has_simple_filter:
369-
370369
# create a source chain with matching spec and attach it to the af graph
371370
vf = temp_video_src(*inopt_vals) + outopts.get(
372371
"filter:v", outopts.get("vf", None)
@@ -385,7 +384,6 @@ def finalize_video_read_opts(
385384

386385
# pixel format must be specified
387386
if pix_fmt is None:
388-
389387
if pix_fmt_in == "unknown":
390388
raise FFmpegioError(
391389
"input pixel format unknown. Please specify output pix_fmt (to be autoset)"
@@ -546,7 +544,6 @@ def finalize_audio_read_opts(
546544

547545
# if a simple filter is present, use the stream specs of its output
548546
if "af" in outopts or "filter:a" in outopts:
549-
550547
# create a source chain with matching specs and attach it to the af graph
551548
af = temp_audio_src(*inopt_vals)
552549
af = af + outopts.get("filter:a", outopts.get("af", None))
@@ -766,7 +763,7 @@ def finalize_avi_read_opts(args):
766763

767764
# add audio codec
768765
for k in utils.find_stream_options(options, "sample_fmt"):
769-
options[f"c:a" + k[10:]] = utils.get_audio_codec(options[k])[0]
766+
options["c:a" + k[10:]] = utils.get_audio_codec(options[k])[0]
770767

771768
return ya8 > 0
772769

@@ -794,7 +791,7 @@ def config_input_fg(expr, args, kwargs):
794791
# multi-filter input filtergraph, cannot take arguments
795792
if len(args):
796793
raise FFmpegioError(
797-
f"filtergraph input expresion cannot take ordered options."
794+
"filtergraph input expresion cannot take ordered options."
798795
)
799796
return expr, dopt, kwargs
800797

@@ -935,7 +932,6 @@ def add_filtergraph(
935932
args["outputs"][ofile] = (args["outputs"][ofile][0], {"map": map})
936933
else:
937934
if append_map and "map" in outopts:
938-
939935
existing_map = outopts["map"]
940936

941937
# remove merged streams from output map & append the output stream of the filter
@@ -1329,7 +1325,6 @@ def process_raw_outputs(
13291325
user_maps = {}
13301326
stream_maps = {}
13311327
for k, v in streams.items() if get_opts else ((s, None) for s in streams):
1332-
13331328
if isinstance(k, tuple):
13341329
k = ":".join(str(s) for s in k)
13351330

@@ -1382,7 +1377,6 @@ def process_raw_inputs(
13821377

13831378
input_info: list[InputSourceDict] = []
13841379
for i, (mtype, arg) in enumerate(zip(stream_types, stream_args)):
1385-
13861380
try:
13871381
a1, a2 = arg
13881382
if isinstance(a1, (int, float, Fraction)):
@@ -1403,7 +1397,7 @@ def process_raw_inputs(
14031397
elif "r" in opts:
14041398
mtype = "v"
14051399
else:
1406-
raise FFmpegioError(f"unknown input stream media type")
1400+
raise FFmpegioError("unknown input stream media type")
14071401
data, opts = a1, a2
14081402
except FFmpegioError:
14091403
raise
@@ -1440,7 +1434,7 @@ def process_raw_inputs(
14401434
pix_fmt, s = utils.guess_video_format(*raw_info)
14411435
more_opts = {
14421436
"f": "rawvideo",
1443-
f"c:v": "rawvideo",
1437+
"c:v": "rawvideo",
14441438
"pix_fmt": pix_fmt,
14451439
"s": s,
14461440
}
@@ -1558,7 +1552,6 @@ def process_url_outputs(
15581552
missing_map = True
15591553

15601554
if missing_map and not skip_automapping:
1561-
15621555
# some output file is missing `map` option
15631556
# add all input streams or all complex filter outputs
15641557
map_opts = [*auto_map(args, input_info, None)]
@@ -1893,7 +1886,7 @@ def init_media_write_outputs(
18931886
a_ids = [
18941887
i for i, info in enumerate(input_info) if info["media_type"] == "audio"
18951888
]
1896-
except KeyError as e:
1889+
except KeyError:
18971890
raise NotImplementedError(
18981891
"audio merging mode is not currently implemented. Please use the `complex_filtergraph=ffmpegio.filtergraph.presets.merge_audio(...)` to assign a custom filtergraph."
18991892
)
@@ -2012,7 +2005,7 @@ def init_media_filter(
20122005
if extra_inputs is not None:
20132006
try:
20142007
input_info.extend(process_url_inputs(args, extra_inputs, {}, no_pipe=True))
2015-
except FFmpegioNoPipeAllowed as e:
2008+
except FFmpegioNoPipeAllowed:
20162009
raise FFmpegioError("extra_inputs cannot be piped in.")
20172010

20182011
# make sure all inputs are complete
@@ -2123,7 +2116,7 @@ def init_media_transcoder(
21232116
if extra_inputs is not None:
21242117
try:
21252118
input_info.extend(process_url_inputs(args, extra_inputs, {}, no_pipe=True))
2126-
except FFmpegioNoPipeAllowed as e:
2119+
except FFmpegioNoPipeAllowed:
21272120
raise FFmpegioError("extra_inputs cannot be piped in.")
21282121

21292122
if not len(input_info):
@@ -2190,7 +2183,6 @@ def init_named_pipes(
21902183
has_pipeout = False
21912184
for i, (output, info) in enumerate(zip(args["outputs"], output_info)):
21922185
if output[0] is None:
2193-
21942186
has_pipeout = True
21952187

21962188
# if fileobj or buffer output, use pipe

0 commit comments

Comments
 (0)