8000 Re-apply Black formatting, and wrap docstrings at ~88 columns. (#639) · nicecoding1/ffmpeg-python@fd1da13 · GitHub
[go: up one dir, main page]

Skip to content

Commit fd1da13

Browse files
authored
Re-apply Black formatting, and wrap docstrings at ~88 columns. (kkroening#639)
1 parent f307972 commit fd1da13

File tree

9 files changed

+340
-223
lines changed

9 files changed

+340
-223
lines changed

ffmpeg/_ffmpeg.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@ def input(filename, **kwargs):
3434

3535
@output_operator()
3636
def global_args(stream, *args):
37-
"""Add extra global command-line argument(s), e.g. ``-progress``.
38-
"""
37+
"""Add extra global command-line argument(s), e.g. ``-progress``."""
3938
return GlobalNode(stream, global_args.__name__, args).stream()
4039

4140

@@ -50,8 +49,7 @@ def overwrite_output(stream):
5049

5150
@output_operator()
5251
def merge_outputs(*streams):
53-
"""Include all given outputs in one ffmpeg command line
54-
"""
52+
"""Include all given outputs in one ffmpeg command line"""
5553
return MergeOutputsNode(streams, merge_outputs.__name__).stream()
5654

5755

ffmpeg/_filters.py

Lines changed: 202 additions & 153 deletions
Large diffs are not rendered by default.

ffmpeg/_run.py

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,8 @@ def _allocate_filter_stream_names(filter_nodes, outgoing_edge_maps, stream_name_
8888
if len(downstreams) > 1:
8989
# TODO: automatically insert `splits` ahead of time via graph transformation.
9090
raise ValueError(
91-
'Encountered {} with multiple outgoing edges with same upstream label {!r}; a '
92-
'`split` filter is probably required'.format(
91+
'Encountered {} with multiple outgoing edges with same upstream '
92+
'label {!r}; a `split` filter is probably required'.format(
9393
upstream_node, upstream_label
9494
)
9595
)
@@ -199,7 +199,7 @@ def run_async(
199199
pipe_stderr=False,
200200
quiet=False,
201201
overwrite_output=False,
202-
cwd=None
202+
cwd=None,
203203
):
204204
"""Asynchronously invoke ffmpeg for the supplied node graph.
205205
@@ -286,8 +286,11 @@ def run_async(
286286
stderr_stream = subprocess.STDOUT
287287
stdout_stream = subprocess.DEVNULL
288288
return subprocess.Popen(
289-
args, stdin=stdin_stream, stdout=stdout_stream, stderr=stderr_stream,
290-
cwd=cwd
289+
args,
290+
stdin=stdin_stream,
291+
stdout=stdout_stream,
292+
stderr=stderr_stream,
293+
cwd=cwd,
291294
)
292295

293296

@@ -300,7 +303,7 @@ def run(
300303
input=None,
301304
quiet=False,
302305
overwrite_output=False,
303-
cwd=None
306+
cwd=None,
304307
):
305308
"""Invoke ffmpeg for the supplied node graph.
306309
@@ -324,7 +327,7 @@ def run(
324327
pipe_stderr=capture_stderr,
325328
quiet=quiet,
326329
overwrite_output=overwrite_output,
327-
cwd=cwd
330+
cwd=cwd,
328331
)
329332
out, err = process.communicate(input)
330333
retcode = process.poll()
@@ -333,4 +336,10 @@ def run(
333336
return out, err
334337

335338

336-
__all__ = ['compile', 'Error', 'get_args', 'run', 'run_async']
339+
__all__ = [
340+
'compile',
341+
'Error',
342+
'get_args',
343+
'run',
344+
'run_async',
345+
]

ffmpeg/_utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ class basestring(with_metaclass(BaseBaseString)):
4949
def _recursive_repr(item):
5050
"""Hack around python `repr` to deterministically represent dictionaries.
5151
52-
This is able to represent more things than json.dumps, since it does not require things to be JSON serializable
53-
(e.g. datetimes).
52+
This is able to represent more things than json.dumps, since it does not require
53+
things to be JSON serializable (e.g. datetimes).
5454
"""
5555
if isinstance(item, basestring):
5656
result = str(item)

ffmpeg/_view.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ def view(stream_spec, detail=False, filename=None, pipe=False, **kwargs):
3535
import graphviz
3636
except ImportError:
3737
raise ImportError(
38-
'failed to import graphviz; please make sure graphviz is installed (e.g. `pip install '
39-
'graphviz`)'
38+
'failed to import graphviz; please make sure graphviz is installed (e.g. '
39+
'`pip install graphviz`)'
4040
)
4141

4242
show_labels = kwargs.pop('show_labels', True)

ffmpeg/dag.py

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,46 +9,55 @@ class DagNode(object):
99
"""Node in a directed-acyclic graph (DAG).
1010
1111
Edges:
12-
DagNodes are connected by edges. An edge connects two nodes with a label for each side:
12+
DagNodes are connected by edges. An edge connects two nodes with a label for
13+
each side:
1314
- ``upstream_node``: upstream/parent node
1415
- ``upstream_label``: label on the outgoing side of the upstream node
1516
- ``downstream_node``: downstream/child node
1617
- ``downstream_label``: label on the incoming side of the downstream node
1718
18-
For example, DagNode A may be connected to DagNode B with an edge labelled "foo" on A's side, and "bar" on B's
19-
side:
19+
For example, DagNode A may be connected to DagNode B with an edge labelled
20+
"foo" on A's side, and "bar" on B's side:
2021
2122
_____ _____
2223
| | | |
2324
| A >[foo]---[bar]> B |
2425
|_____| |_____|
2526
26-
Edge labels may be integers or strings, and nodes cannot have more than one incoming edge with the same label.
27+
Edge labels may be integers or strings, and nodes cannot have more than one
28+
incoming edge with the same label.
2729
28-
DagNodes may have any number of incoming edges and any number of outgoing edges. DagNodes keep track only of
29-
their incoming edges, but the entire graph structure can be inferred by looking at the furthest downstream
30-
nodes and working backwards.
30+
DagNodes may have any number of incoming edges and any number of outgoing
31+
edges. DagNodes keep track only of their incoming edges, but the entire graph
32+
structure can be inferred by looking at the furthest downstream nodes and
33+
working backwards.
3134
3235
Hashing:
33-
DagNodes must be hashable, and two nodes are considered to be equivalent if they have the same hash value.
36+
DagNodes must be hashable, and two nodes are considered to be equivalent if
37+
they have the same hash value.
3438
35-
Nodes are immutable, and the hash should remain constant as a result. If a node with new contents is required,
36-
create a new node and throw the old one away.
39+
Nodes are immutable, and the hash should remain constant as a result. If a
40+
node with new contents is required, create a new node and throw the old one
41+
away.
3742
3843
String representation:
39-
In order for graph visualization tools to show useful information, nodes must be representable as strings. The
40-
``repr`` operator should provide a more or less "full" representation of the node, and the ``short_repr``
41-
property should be a shortened, concise representation.
44+
In order for graph visualization tools to show useful information, nodes must
45+
be representable as strings. The ``repr`` operator should provide a more or
46+
less "full" representation of the node, and the ``short_repr`` property should
47+
be a shortened, concise representation.
4248
43-
Again, because nodes are immutable, the string representations should remain constant.
49+
Again, because nodes are immutable, the string representations should remain
50+
constant.
4451
"""
4552

4653
def __hash__(self):
4754
"""Return an integer hash of the node."""
4855
raise NotImplementedError()
4956

5057
def __eq__(self, other):
51-
"""Compare two nodes; implementations should return True if (and only if) hashes match."""
58+
"""Compare two nodes; implementations should return True if (and only if)
59+
hashes match.
60+
"""
5261
raise NotImplementedError()
5362

5463
def __repr__(self, other):
@@ -64,8 +73,9 @@ def short_repr(self):
6473
def incoming_edge_map(self):
6574
"""Provides information about all incoming edges that connect to this node.
6675
67-
The edge map is a dictionary that maps an ``incoming_label`` to ``(outgoing_node, outgoing_label)``. Note that
68-
implicity, ``incoming_node`` is ``self``. See "Edges" section above.
76+
The edge map is a dictionary that maps an ``incoming_label`` to
77+
``(outgoing_node, outgoing_label)``. Note that implicity, ``incoming_node`` is
78+
``self``. See "Edges" section above.
6979
"""
7080
raise NotImplementedError()
7181

@@ -116,8 +126,7 @@ def get_outgoing_edges(upstream_node, outgoing_edge_map):
116126

117127

118128
class KwargReprNode(DagNode):
119-
"""A DagNode that can be represented as a set of args+kwargs.
120-
"""
129+
"""A DagNode that can be represented as a set of args+kwargs."""
121130

122131
@property
123132
def __upstream_hashes(self):

ffmpeg/nodes.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ def _get_types_str(types):
2121

2222

2323
class Stream(object):
24-
"""Represents the outgoing edge of an upstream node; may be used to create more downstream nodes."""
24+
"""Represents the outgoing edge of an upstream node; may be used to create more
25+
downstream nodes.
26+
"""
2527

2628
def __init__(
2729
self, upstream_node, upstream_label, node_types, upstream_selector=None
@@ -214,9 +216,10 @@ def stream(self, label=None, selector=None):
214216
return self.__outgoing_stream_type(self, label, upstream_selector=selector)
215217

216218
def __getitem__(self, item):
217-
"""Create an outgoing stream originating from this node; syntactic sugar for ``self.stream(label)``.
218-
It can also be used to apply a selector: e.g. ``node[0:'a']`` returns a stream with label 0 and
219-
selector ``'a'``, which is the same as ``node.stream(label=0, selector='a')``.
219+
"""Create an outgoing stream originating from this node; syntactic sugar for
220+
``self.stream(label)``. It can also be used to apply a selector: e.g.
221+
``node[0:'a']`` returns a stream with label 0 and selector ``'a'``, which is
222+
the same as ``node.stream(label=0, selector='a')``.
220223
221224
Example:
222225
Process the audio and video portions of a stream independently::

ffmpeg/tests/test_ffmpeg.py

Lines changed: 65 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,20 @@ def test_stream_repr():
116116
dummy_out.label, dummy_out.node.short_hash
117117
)
118118

119+
119120
def test_repeated_args():
120-
out_file = ffmpeg.input('dummy.mp4').output('dummy2.mp4', streamid=['0:0x101', '1:0x102'])
121-
assert out_file.get_args() == ['-i', 'dummy.mp4', '-streamid', '0:0x101', '-streamid', '1:0x102', 'dummy2.mp4']
121+
out_file = ffmpeg.input('dummy.mp4').output(
122+
'dummy2.mp4', streamid=['0:0x101', '1:0x102']
123+
)
124+
assert out_file.get_args() == [
125+
'-i',
126+
'dummy.mp4',
127+
'-streamid',
128+
'0:0x101',
129+
'-streamid',
130+
'1:0x102',
131+
'dummy2.mp4',
132+
]
122133

123134

124135
def test__get_args__simple():
@@ -332,8 +343,13 @@ def test_filter_asplit():
332343
'-i',
333344
TEST_INPUT_FILE1,
334345
'-filter_complex',
335-
'[0]vflip[s0];[s0]asplit=2[s1][s2];[s1]atrim=end=20:start=10[s3];[s2]atrim=end=40:start=30[s4];[s3]'
336-
'[s4]concat=n=2[s5]',
346+
(
347+
'[0]vflip[s0];'
348+
'[s0]asplit=2[s1][s2];'
349+
'[s1]atrim=end=20:start=10[s3];'
350+
'[s2]atrim=end=40:start=30[s4];'
351+
'[s3][s4]concat=n=2[s5]'
352+
),
337353
'-map',
338354
'[s5]',
339355
TEST_OUTPUT_FILE1,
@@ -357,10 +373,14 @@ def test__output__video_size(video_size):
357373

358374

359375
def test_filter_normal_arg_escape():
360-
"""Test string escaping of normal filter args (e.g. ``font`` param of ``drawtext`` filter)."""
376+
"""Test string escaping of normal filter args (e.g. ``font`` param of ``drawtext``
377+
filter).
378+
"""
361379

362380
def _get_drawtext_font_repr(font):
363-
"""Build a command-line arg using drawtext ``font`` param and extract the ``-filter_complex`` arg."""
381+
"""Build a command-line arg using drawtext ``font`` param and extract the
382+
``-filter_complex`` arg.
383+
"""
364384
args = (
365385
ffmpeg.input('in')
366386
.drawtext('test', font='a{}b'.format(font))
@@ -370,7 +390,9 @@ def _get_drawtext_font_repr(font):
370390
assert args[:3] == ['-i', 'in', '-filter_complex']
371391
assert args[4:] == ['-map', '[s0]', 'out']
372392
match = re.match(
373-
r'\[0\]drawtext=font=a((.|\n)*)b:text=test\[s0\]', args[3], re.MULTILINE
393+
r'\[0\]drawtext=font=a((.|\n)*)b:text=test\[s0\]',
394+
args[3],
395+
re.MULTILINE,
374396
)
375397
assert match is not None, 'Invalid -filter_complex arg: {!r}'.format(args[3])
376398
return match.group(1)
@@ -394,10 +416,14 @@ def _get_drawtext_font_repr(font):
394416

395417

396418
def test_filter_text_arg_str_escape():
397-
"""Test string escaping of normal filter args (e.g. ``text`` param of ``drawtext`` filter)."""
419+
"""Test string escaping of normal filter args (e.g. ``text`` param of ``drawtext``
420+
filter).
421+
"""
398422

399423
def _get_drawtext_text_repr(text):
400-
"""Build a command-line arg using drawtext ``text`` param and extract the ``-filter_complex`` arg."""
424+
"""Build a command-line arg using drawtext ``text`` param and extract the
425+
``-filter_complex`` arg.
426+
"""
401427
args = ffmpeg.input('in').drawtext('a{}b'.format(text)).output('out').get_args()
402428
assert args[:3] == ['-i', 'in', '-filter_complex']
403429
assert args[4:] == ['-map', '[s0]', 'out']
@@ -447,8 +473,11 @@ def test__run_async(mocker, pipe_stdin, pipe_stdout, pipe_stderr, cwd):
447473
popen__mock = mocker.patch.object(subprocess, 'Popen', return_value=process__mock)
448474
stream = _get_simple_example()
449475
process = ffmpeg.run_async(
450-
stream, pipe_stdin=pipe_stdin, pipe_stdout=pipe_stdout,
451-
pipe_stderr=pipe_stderr, cwd=cwd
476+
stream,
477+
pipe_stdin=pipe_stdin,
478+
pipe_stdout=pipe_stdout,
479+
pipe_stderr=pipe_stderr,
480+
cwd=cwd,
452481
)
453482
assert process is process__mock
454483

@@ -458,8 +487,10 @@ def test__run_async(mocker, pipe_stdin, pipe_stdout, pipe_stderr, cwd):
458487
(args,), kwargs = popen__mock.call_args
459488
assert args == ffmpeg.compile(stream)
460489
assert kwargs == dict(
461-
stdin=expected_stdin, stdout=expected_stdout, stderr=expected_stderr,
462-
cwd=cwd
490+
stdin=expected_stdin,
491+
stdout=expected_stdout,
492+
stderr=expected_stderr,
493+
cwd=cwd,
463494
)
464495

465496

@@ -695,7 +726,10 @@ def test_pipe():
695726

696727
cmd = ['ffmpeg'] + args
697728
p = subprocess.Popen(
698-
cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE
729+
cmd,
730+
stdin=subprocess.PIPE,
731+
stdout=subprocess.PIPE,
732+
stderr=subprocess.PIPE,
699733
)
700734

701735
in_data = bytes(
@@ -715,10 +749,10 @@ def test__probe():
715749
assert data['format']['duration'] == '7.036000'
716750

717751

718-
@pytest.mark.skipif(sys.version_info < (3, 3), reason="requires python3.3 or higher")
752+
@pytest.mark.skipif(sys.version_info < (3, 3), reason='requires python3.3 or higher')
719753
def test__probe_timeout():
720754
with pytest.raises(subprocess.TimeoutExpired) as excinfo:
721-
data = ffmpeg.probe(TEST_INPUT_FILE1, timeout=0)
755+
ffmpeg.probe(TEST_INPUT_FILE1, timeout=0)
722756
assert 'timed out after 0 seconds' in str(excinfo.value)
723757

724758

@@ -751,24 +785,24 @@ def get_filter_complex_outputs(flt, name):
751785

752786

753787
def test__get_filter_complex_input():
754-
assert get_filter_complex_input("", "scale") is None
755-
assert get_filter_complex_input("scale", "scale") is None
756-
assert get_filter_complex_input("scale[s3][s4];etc", "scale") is None
757-
assert get_filter_complex_input("[s2]scale", "scale") == "s2"
758-
assert get_filter_complex_input("[s2]scale;etc", "scale") == "s2"
759-
assert get_filter_complex_input("[s2]scale[s3][s4];etc", "scale") == "s2"
788+
assert get_filter_complex_input('', 'scale') is None
789+
assert get_filter_complex_input('scale', 'scale') is None
790+
assert get_filter_complex_input('scale[s3][s4];etc', 'scale') is None
791+
assert get_filter_complex_input('[s2]scale', 'scale') == 's2'
792+
assert get_filter_complex_input('[s2]scale;etc', 'scale') == 's2'
793+
assert get_filter_complex_input('[s2]scale[s3][s4];etc', 'scale') == 's2'
760794

761795

762796
def test__get_filter_complex_outputs():
763-
assert get_filter_complex_outputs("", "scale") is None
764-
assert get_filter_complex_outputs("scale", "scale") is None
765-
assert get_filter_complex_outputs("scalex[s0][s1]", "scale") is None
766-
assert get_filter_complex_outputs("scale[s0][s1]", "scale") == ['s0', 's1']
767-
assert get_filter_complex_outputs("[s5]scale[s0][s1]", "scale") == ['s0', 's1']
768-
assert get_filter_complex_outputs("[s5]scale[s1][s0]", "scale") == ['s1', 's0']
769-
assert get_filter_complex_outputs("[s5]scale[s1]", "scale") == ['s1']
770-
assert get_filter_complex_outputs("[s5]scale[s1];x", "scale") == ['s1']
771-
assert get_filter_complex_outputs("y;[s5]scale[s1];x", "scale") == ['s1']
797+
assert get_filter_complex_outputs('', 'scale') is None
798+
assert get_filter_complex_outputs('scale', 'scale') is None
799+
assert get_filter_complex_outputs('scalex[s0][s1]', 'scale') is None
800+
assert get_filter_complex_outputs('scale[s0][s1]', 'scale') == ['s0', 's1']
801+
assert get_filter_complex_outputs('[s5]scale[s0][s1]', 'scale') == ['s0', 's1']
802+
assert get_filter_complex_outputs('[s5]scale[s1][s0]', 'scale') == ['s1', 's0']
803+
assert get_filter_complex_outputs('[s5]scale[s1]', 'scale') == ['s1']
804+
assert get_filter_complex_outputs('[s5]scale[s1];x', 'scale') == ['s1']
805+
assert get_filter_complex_outputs('y;[s5]scale[s1];x', 'scale') == ['s1']
772806

773807

774808
def test__multi_output_edge_label_order():

0 commit comments

Comments
 (0)
0