Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Formalize flake8 linting #1439

Merged
merged 17 commits into from
Jan 16, 2021
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 11 additions & 19 deletions .github/workflows/format_check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ on: [push, pull_request]
jobs:
black:
runs-on: ubuntu-latest
name: Black
steps:
- uses: actions/checkout@v2
- name: Set up Python
Expand All @@ -14,6 +15,7 @@ jobs:
uses: psf/black@stable # already includes args "--check --diff"
flake8:
runs-on: ubuntu-latest
name: Flake8
steps:
- uses: actions/checkout@v2
- name: Set up Python
Expand All @@ -23,22 +25,12 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install .
pip install flake8
- name: Flake8
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E901,E999,F821,F822,F823,W605 --show-source --statistics
# Some warning codes are ignored because they conflict with black's formatting, or are
# incompatible with MoviePy's structure
# E203: whitespace before ':'
# E302: expected 2 blank lines, found 0
# E402: module level import not at top of file
# W291: trailing whitespace
# W293: blank line contains whitespace
# W503: line break before binary operator
flake8 moviepy --ignore=E203,E302,E402,W291,W293,W503 --max-complexity=10 --max-line-length=127 --statistics --count --exit-zero
# Check examples and tests with slightly relaxed rules to allow 'star' imports
# F403 'from moviepy import *' used; unable to detect undefined names
# F405 'name' may be undefined, or defined from star imports: moviepy
flake8 . --ignore=E203,E302,E402,W291,W293,W503,F403,F405 --exclude moviepy/ --max-complexity=10 --max-line-length=127 --statistics --count --exit-zero
pip install .[lint]
- name: Lint examples
run: flake8 examples --show-source
- name: Lint scripts
run: flake8 setup.py find_latest_imagemagick_version.py docs/conf.py --show-source
- name: Lint tests
run: flake8 tests --show-source
- name: Lint moviepy
run: flake8 moviepy --show-source
24 changes: 24 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,28 @@ The test suite can then be executed via:
$ pytest


Linting source code
-------------------

To make sure that all the code is well formatted and consistent, we use Black_ and Flake8_. Install them by navigating to the project directory and running:

.. code:: bash

$ (sudo) pip install moviepy[lint]

You can lint all files running:

.. code:: bash

$ flake8

To format the files properly use:

.. code:: bash

$ black -t py36 .


Contribute
----------

Expand Down Expand Up @@ -212,6 +234,8 @@ Maintainers
.. _ImageMagick: https://www.imagemagick.org/script/index.php
.. _`Matplotlib`: https://matplotlib.org/
.. _`Sphinx`: https://www.sphinx-doc.org/en/master/setuptools.html
.. _`Black`: https://black.readthedocs.io/en/stable/
.. _`Flake8`: https://flake8.pycqa.org/en/latest/

.. People
.. _Zulko: https://github.com/Zulko
Expand Down
2 changes: 0 additions & 2 deletions examples/dancing_knights.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# -*- coding: utf-8 -*-

"""
Result: https://www.youtube.com/watch?v=Qu7HJrsEYFg

Expand Down
2 changes: 1 addition & 1 deletion examples/headblur.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from moviepy import *
from moviepy.video.tools.tracking import manual_tracking
from moviepy.video.tools.tracking import manual_tracking # noqa 401
from moviepy.video.tools.interpolators import Trajectory

# LOAD THE CLIP (subclip 6'51 - 7'01 of a chaplin movie)
Expand Down
2 changes: 1 addition & 1 deletion moviepy/Clip.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ def with_duration(self, duration, change_end=True):
self.end = None if (duration is None) else (self.start + duration)
else:
if self.duration is None:
raise Exception("Cannot change clip start when new" "duration is None")
raise Exception("Cannot change clip start when new duration is None")
self.start = self.end - duration

@outplace
Expand Down
22 changes: 16 additions & 6 deletions moviepy/audio/fx/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
# import every video fx function

from .audio_fadein import audio_fadein
from .audio_fadeout import audio_fadeout
from .audio_loop import audio_loop
from .audio_normalize import audio_normalize
from .multiply_stereo_volume import multiply_stereo_volume
from .multiply_volume import multiply_volume
from moviepy.audio.fx.audio_fadein import audio_fadein
from moviepy.audio.fx.audio_fadeout import audio_fadeout
from moviepy.audio.fx.audio_loop import audio_loop
from moviepy.audio.fx.audio_normalize import audio_normalize
from moviepy.audio.fx.multiply_stereo_volume import multiply_stereo_volume
from moviepy.audio.fx.multiply_volume import multiply_volume

__all__ = (
"audio_fadein",
"audio_fadeout",
"audio_left_right",
"audio_loop",
"audio_normalize",
"multiply_stereo_volume",
"multiply_volume",
)
6 changes: 3 additions & 3 deletions moviepy/audio/fx/all/__init__.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
"""
moviepy.audio.fx.all is deprecated.
moviepy.audio.fx.all is deprecated.

Use the fx method directly from the clip instance (e.g. ``clip.audio_loop(...)``)
or import the function from moviepy.audio.fx instead.
or import the function from moviepy.audio.fx instead.
"""
import warnings

from .. import *
from .. import * # noqa 401,F403

warnings.warn(f"\nMoviePy: {__doc__}", UserWarning)
2 changes: 1 addition & 1 deletion moviepy/audio/fx/audio_loop.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from ..AudioClip import concatenate_audioclips
from moviepy.audio.AudioClip import concatenate_audioclips
from moviepy.decorators import audio_video_fx


Expand Down
2 changes: 1 addition & 1 deletion moviepy/audio/fx/audio_normalize.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from moviepy.decorators import audio_video_fx

from .multiply_volume import multiply_volume
from moviepy.audio.fx.multiply_volume import multiply_volume


@audio_video_fx
Expand Down
2 changes: 0 additions & 2 deletions moviepy/audio/fx/multiply_stereo_volume.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import numpy as np

from moviepy.decorators import audio_video_fx


Expand Down
10 changes: 5 additions & 5 deletions moviepy/audio/io/AudioFileClip.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import division

from moviepy.audio.AudioClip import AudioClip
from moviepy.audio.io.readers import FFMPEG_AudioReader
from moviepy.decorators import convert_path_to_string
Expand Down Expand Up @@ -43,10 +41,12 @@ class AudioFileClip(AudioClip):
Lifetime
--------

Note that this creates subprocesses and locks files. If you construct one of these instances, you must call
close() afterwards, or the subresources will not be cleaned up until the process ends.
Note that this creates subprocesses and locks files. If you construct one
of these instances, you must call close() afterwards, or the subresources
will not be cleaned up until the process ends.

If copies are made, and close() is called on one, it may cause methods on the other copies to fail.
If copies are made, and close() is called on one, it may cause methods on
the other copies to fail.

However, coreaders must be closed separately.

Expand Down
1 change: 0 additions & 1 deletion moviepy/audio/io/ffmpeg_audiowriter.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import os
import subprocess as sp
import warnings

import proglog

Expand Down
13 changes: 7 additions & 6 deletions moviepy/editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,19 @@

>>> from moviepy.editor import *

- Starts a pygame session to enable ``clip.show()`` and ``clip.preview()`` if pygame is installed
- Starts a pygame session to enable ``clip.show()`` and ``clip.preview()``
if pygame is installed
- Enables ``clip.ipython_display()`` if in an IPython Notebook
- Allows the use of ``sliders`` if Matplotlib is installed
"""

import os

from . import *
from .video.io.html_tools import ipython_display
from moviepy import *
from moviepy.video.io.html_tools import ipython_display

try:
from .video.io.sliders import sliders
from moviepy.video.io.sliders import sliders
except ImportError:

def sliders(*args, **kwargs):
Expand All @@ -37,7 +38,7 @@ def sliders(*args, **kwargs):

# Add methods preview and show (only if pygame installed)
try:
from .video.io.preview import show, preview
from moviepy.video.io.preview import show, preview
except ImportError:

def preview(self, *args, **kwargs):
Expand All @@ -53,7 +54,7 @@ def show(self, *args, **kwargs):
VideoClip.show = show

try:
from .audio.io.preview import preview
from moviepy.audio.io.preview import preview
except ImportError:

def preview(self, *args, **kwargs):
Expand Down
1 change: 0 additions & 1 deletion moviepy/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"""
import os
import subprocess as sp
import sys
import warnings

import proglog
Expand Down
35 changes: 19 additions & 16 deletions moviepy/video/VideoClip.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 +227,8 @@ def write_videofile(
frame rate to use when generating the sound.

temp_audiofile
the name of the temporary audiofile, as a string or path-like object, to be created and
then used to write the complete video, if any.
the name of the temporary audiofile, as a string or path-like object,
to be created and then used to write the complete video, if any.

temp_audiofile_path
the location that the temporary audiofile is placed, as a
Expand Down Expand Up @@ -709,7 +709,7 @@ def on_color(self, size=None, color=(0, 0, 0), pos=None, col_opacity=None):
background.

"""
from .compositing.CompositeVideoClip import CompositeVideoClip
from moviepy.video.compositing.CompositeVideoClip import CompositeVideoClip

if size is None:
size = self.size
Expand Down Expand Up @@ -1312,12 +1312,12 @@ def list(arg):

if arg == "font":
# Slice removes first 8 characters: " Font: "
return [l[8:] for l in lines if l.startswith(" Font:")]
return [line[8:] for line in lines if line.startswith(" Font:")]
elif arg == "color":
# Each line is of the format "aqua srgb(0,255,255) SVG" so split on space and take
# the first item to get the color name.
# Each line is of the format "aqua srgb(0,255,255) SVG" so split
# on space and take the first item to get the color name.
# The first 5 lines are header information, not colors, so ignore
return [l.split(" ")[0] for l in lines[5:]]
return [line.split(" ")[0] for line in lines[5:]]
else:
raise Exception("Moviepy Error: Argument must equal 'font' or 'color'")

Expand Down Expand Up @@ -1354,14 +1354,15 @@ def __init__(
self, bitmap_frames, *, fps=None, duration=None, color_dict=None, is_mask=False
):
"""
Creates a VideoClip object from a bitmap representation. Primarily used in the test suite.
Creates a VideoClip object from a bitmap representation. Primarily used
in the test suite.

Parameters
-----------

bitmap_frames
A list of frames. Each frame is a list of strings. Each string represents a row of colors.
Each color represents an (r, g, b) tuple.
A list of frames. Each frame is a list of strings. Each string
represents a row of colors. Each color represents an (r, g, b) tuple.
Example input (2 frames, 5x3 pixel size):
[["RRRRR",
"RRBRR",
Expand All @@ -1371,16 +1372,18 @@ def __init__(
"RGGGR"]]

fps
The number of frames per second to display the clip at. `duration` will calculated from the total number of frames.
If both `fps` and `duration` are set, `duration` will be ignored.
The number of frames per second to display the clip at. `duration` will
calculated from the total number of frames. If both `fps` and `duration`
are set, `duration` will be ignored.

duration
The total duration of the clip. `fps` will be calculated from the total number of frames.
If both `fps` and `duration` are set, `duration` will be ignored.
The total duration of the clip. `fps` will be calculated from the total
number of frames. If both `fps` and `duration` are set, `duration` will
be ignored.

color_dict
A dictionary that can be used to set specific (r, g, b) values that correspond
to the letters used in ``bitmap_frames``.
A dictionary that can be used to set specific (r, g, b) values that
correspond to the letters used in ``bitmap_frames``.
eg ``{"A": (50, 150, 150)}``.

Defaults to
Expand Down
2 changes: 1 addition & 1 deletion moviepy/video/compositing/transitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from moviepy.video.fx.fadein import fadein
from moviepy.video.fx.fadeout import fadeout

from .CompositeVideoClip import CompositeVideoClip
from moviepy.video.compositing.CompositeVideoClip import CompositeVideoClip


__all__ = ["crossfadein", "crossfadeout", "slide_in", "slide_out", "make_loopable"]
Expand Down
Loading