Video editing with Python
Setup 'isort' and 'pre-commit' (#1479)
Álvaro Mondéjar8cc3eebb0950
diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.mdindex 1784a1dc..20d16a8c 100644--- a/.github/PULL_REQUEST_TEMPLATE.md+++ b/.github/PULL_REQUEST_TEMPLATE.md@@ -6,4 +6,3 @@ Delete them if they are not appropriate for this pull request.- [ ] I have added suitable tests demonstrating a fixed bug or new/changed feature to the test suite in `tests/`- [ ] I have properly documented new or changed features in the documentation or in the docstrings- [ ] I have properly explained unusual or unexpected code in the comments around it-- [ ] I have formatted my code using `black -t py36`\ No newline at end of filediff --git a/.github/workflows/format_check.yml b/.github/workflows/format_check.ymlindex 3375d95d..3c881a01 100644--- a/.github/workflows/format_check.yml+++ b/.github/workflows/format_check.yml@@ -34,3 +34,18 @@ jobs:run: flake8 tests --show-source- name: Lint moviepyrun: flake8 moviepy --show-source+ isort:+ runs-on: ubuntu-latest+ name: isort+ steps:+ - uses: actions/checkout@v2+ - name: Set up Python+ uses: actions/setup-python@v2+ with:+ python-version: '3.x'+ - name: Install dependencies+ run: |+ python -m pip install --upgrade pip+ pip install isort+ - name: Check imports+ run: isort --check-only moviepy tests examples docs/conf.pydiff --git a/.pre-commit-config.yaml b/.pre-commit-config.yamlnew file mode 100644index 00000000..1eb96a28--- /dev/null+++ b/.pre-commit-config.yaml@@ -0,0 +1,22 @@+repos:+ - repo: https://gitlab.com/pycqa/flake8+ rev: master+ hooks:+ - id: flake8+ additional_dependencies:+ - flake8-implicit-str-concat+ - flake8-absolute-import+ name: flake8-test+ files: \.py$+ - repo: https://github.com/PyCQA/isort+ rev: master+ hooks:+ - id: isort+ args: ['--check-only', '--filter-files']+ files: \.py$+ - repo: https://github.com/psf/black+ rev: stable+ hooks:+ - id: black+ language_version: python3.6+ files: \.py$diff --git a/CONTRIBUTING.md b/CONTRIBUTING.mdindex 7b6d9fbb..1e866241 100644--- a/CONTRIBUTING.md+++ b/CONTRIBUTING.md@@ -8,6 +8,7 @@- Do not push any commit that changes the API without prior discussion.## Preparing for development+- Fork the official MoviePy repository to your own GitHub account:Use the "Fork" button in the top right corner of the GitHub interface while viewing [the official MoviePy](https://github.com/Zulko/moviepy) repository.- Use your fork as the basis for cloning the repository to your local machine: `$ git clone URL_TO_YOUR_FORK`@@ -15,15 +16,15 @@ You can get the appropriate URL (SSH- or HTTPS-based) by using the green "Code"- Enter your local clone and add the official MoviePy repository as a second remote, with alias `upstream`:`$ git remote add upstream [email protected]:Zulko/moviepy.git` (using SSL) _or_`$ git remote add upstream https://github.com/Zulko/moviepy.git` (using HTTPS).+- Install the library inside a [virtual environment](https://docs.python.org/3/tutorial/venv.html) with all dependencies included using `$ pip install -e ".[optional,doc,test,lint]"`+- Configure pre-commit hooks running `$ pre-commit install`## Coding conventions, code quality- Respect [PEP8](https://www.python.org/dev/peps/pep-0008/) conventions.- Add just the "right" amount of comments. Try to write auto-documented code with very explicit variable names.- If you introduce new functionality or fix a bug, document it in the docstring or with code comments.-- MoviePy's team adopted [black](https://github.com/psf/black) to autoformat code. This is enforced for any pull request.--> Tip: use `black -t py36 .` to autoformat your code, or set black as a [plugin for your editor](https://black.readthedocs.io/en/stable/editor_integration.html).+- MoviePy's team adopted [pre-commit](https://pre-commit.com/) to run code checks using black, flake8 and isort, so make sure that you've configured the pre-commit hooks with `pre-commit install`.## Standard contribution workflow@@ -48,7 +49,6 @@ You do not have to have finished your feature or bug fix before submitting a PR;Before submitting PRs:-- make sure your code still conforms to the formatting standard (using Black formatter: `$ black -t py36 .`)- run the test suite over your code to expose any problems: `$ pytest`- push your local develop branch to your GitHub fork `$ git push origin YOUR_DEVELOP_BRANCH`diff --git a/README.rst b/README.rstindex c578ca4b..416169ff 100644--- a/README.rst+++ b/README.rst@@ -48,7 +48,7 @@ In this example we open a video file, select the subclip between t=50s and t=60sMaintainers wanted!--------------------As there are more and more people seeking support (320 open issues as of Sept. 2019!) and all the MoviePy maintainers seem busy, we'd love to hear about developers interested in giving a hand and solving some of the issues (especially the ones that affect you) or reviewing pull requests. Open an issue or contact us directly if you are interested. Thanks!+As there are more and more people seeking support (270 open issues as of Jan. 2021!) and all the MoviePy maintainers seem busy, we'd love to hear about developers interested in giving a hand and solving some of the issues (especially the ones that affect you) or reviewing pull requests. Open an issue or contact us directly if you are interested. Thanks!Installation------------@@ -103,7 +103,7 @@ For instance, using the method ``clip.resize`` requires that at least one of SciDocumentation--------------Running `build_docs` has additional dependencies that require installation.+Building the documentation has additional dependencies that require installation... code:: bash@@ -148,44 +148,6 @@ Then at the beginning of your notebook enter:Have a look at the Proglog project page for more options.-Running Tests----------------In order to run the test suite locally, first install the dependencies by navigating to the project directory and running:--.. code:: bash-- $ (sudo) pip install moviepy[test]--The test suite can then be executed via:--.. code:: bash-- $ pytest---Linting and formatting-------------------------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----------@@ -205,6 +167,7 @@ Maintainers- `@overdrivr`_- `@keikoro`_- `@ryanfox`_+- `@mondeja`_.. MoviePy links@@ -234,8 +197,6 @@ 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@@ -245,4 +206,5 @@ Maintainers.. _`@mbeacom`: https://github.com/mbeacom.. _`@overdrivr`: https://github.com/overdrivr.. _`@keikoro`: https://github.com/keikoro-.. _`@ryanfox`: https://github.com/ryanfox\ No newline at end of file+.. _`@ryanfox`: https://github.com/ryanfox+.. _`@mondeja`: https://github.com/mondejadiff --git a/docs/conf.py b/docs/conf.pyindex f822fb66..2c895f80 100644--- a/docs/conf.py+++ b/docs/conf.py@@ -14,10 +14,9 @@import osimport sys-# The theme to use for HTML and HTML Help pages. See the documentation for-# a list of builtin themes.import sphinx_rtd_theme+# If extensions (or modules to document with autodoc) are in another directory,# add these directories to sys.path here. If the directory is relative to the# documentation root, use os.path.abspath to make it absolute, like shown here.diff --git a/examples/compo_from_image.py b/examples/compo_from_image.pyindex 5acb4544..7147c29f 100644--- a/examples/compo_from_image.py+++ b/examples/compo_from_image.py@@ -1,6 +1,7 @@from moviepy import *from moviepy.video.tools.segmenting import find_objects+# Load the image specifying the regions.im = ImageClip("../../ultracompositing/motif.png")diff --git a/examples/dancing_knights.py b/examples/dancing_knights.pyindex 299171f1..8e676386 100644--- a/examples/dancing_knights.py+++ b/examples/dancing_knights.py@@ -26,6 +26,7 @@ from moviepy import *from moviepy.audio.tools.cuts import find_audio_periodfrom moviepy.video.tools.cuts import find_video_period+# Next lines are for downloading the required videos from Youtube.# To do this you must have youtube-dl installed, otherwise you will need to# download the videos by hand and rename them, as follows:diff --git a/examples/example_with_sound.py b/examples/example_with_sound.pyindex ee1298d0..37159838 100644--- a/examples/example_with_sound.py+++ b/examples/example_with_sound.py@@ -8,6 +8,7 @@ movie put together.from moviepy import *from moviepy.video.tools.drawing import color_split+duration = 6 # duration of the final clip# LOAD THE MAIN SCENEdiff --git a/examples/headblur.py b/examples/headblur.pyindex 191ddbbf..ab6e3db4 100644--- a/examples/headblur.py+++ b/examples/headblur.py@@ -1,6 +1,7 @@from moviepy import *-from moviepy.video.tools.tracking import manual_tracking # noqa 401from moviepy.video.tools.interpolators import Trajectory+from moviepy.video.tools.tracking import manual_tracking # noqa 401+# LOAD THE CLIP (subclip 6'51 - 7'01 of a chaplin movie)clip = VideoFileClip("media/chaplin.mp4")diff --git a/examples/logo.py b/examples/logo.pyindex 93b46cf9..30be3e96 100644--- a/examples/logo.py+++ b/examples/logo.py@@ -2,6 +2,7 @@ import numpy as npfrom moviepy import *+w, h = moviesize = (720, 380)duration = 1diff --git a/examples/masked_credits.py b/examples/masked_credits.pyindex 96357203..2c130410 100644--- a/examples/masked_credits.py+++ b/examples/masked_credits.py@@ -1,6 +1,7 @@from moviepy import *from moviepy.video.tools.credits import credits1+# Load the mountains clip, cut it, slow it down, make it look darkerclip = (VideoFileClip("../../videos/badl-0001.mov", audio=False)diff --git a/examples/moving_letters.py b/examples/moving_letters.pyindex fc7b0d7d..2aa252b7 100644--- a/examples/moving_letters.py+++ b/examples/moving_letters.py@@ -3,6 +3,7 @@ import numpy as npfrom moviepy import *from moviepy.video.tools.segmenting import find_objects+# WE CREATE THE TEXT THAT IS GOING TO MOVE, WE CENTER IT.screensize = (720, 460)diff --git a/examples/painting_effect.py b/examples/painting_effect.pyindex 989aa984..8f8e20ab 100644--- a/examples/painting_effect.py+++ b/examples/painting_effect.py@@ -2,6 +2,7 @@from moviepy import *+# WE TAKE THE SUBCLIPS WHICH ARE 2 SECONDS BEFORE & AFTER THE FREEZEcharade = VideoFileClip("../../videos/charade.mp4")diff --git a/examples/soundtrack.py b/examples/soundtrack.pyindex 9a1a6f63..20f8c5b0 100644--- a/examples/soundtrack.py+++ b/examples/soundtrack.py@@ -1,6 +1,7 @@""" A simple test script on how to put a soundtrack to a movie """from moviepy import *+# We load a movie and replace the sound with some music:movie = VideoFileClip("../../videos/dam.mov").with_audio(diff --git a/examples/star_worms.py b/examples/star_worms.pyindex 8094adcc..b33ba209 100644--- a/examples/star_worms.py+++ b/examples/star_worms.py@@ -7,10 +7,11 @@ background made of stars. Slight fading effect on the text."""import numpy as np+from skimage import transform as tffrom moviepy import *from moviepy.video.tools.drawing import color_gradient-from skimage import transform as tf+# RESOLUTIONdiff --git a/examples/the_end.py b/examples/the_end.pyindex 237bafda..18608b0c 100644--- a/examples/the_end.py+++ b/examples/the_end.py@@ -1,6 +1,7 @@from moviepy import *from moviepy.video.tools.drawing import circle+clip = (VideoFileClip("../../videos/badl-0006.mov", audio=False).subclip(26, 31).add_mask())diff --git a/examples/ukulele_concerto.py b/examples/ukulele_concerto.pyindex ddae9cd3..dca60a7b 100644--- a/examples/ukulele_concerto.py+++ b/examples/ukulele_concerto.py@@ -1,5 +1,6 @@from moviepy import *+# UKULELE CLIP, OBTAINED BY CUTTING AND CROPPING# RAW FOOTAGEdiff --git a/find_latest_imagemagick_version.py b/find_latest_imagemagick_version.pyindex 0cafba98..d3bbbc2e 100644--- a/find_latest_imagemagick_version.py+++ b/find_latest_imagemagick_version.py@@ -1,6 +1,7 @@import refrom urllib import request+url = "https://legacy.imagemagick.org/script/index.php""""This little script parses url above to extract latest image magick versiondiff --git a/moviepy/__init__.py b/moviepy/__init__.pyindex f9612e14..a210f510 100644--- a/moviepy/__init__.py+++ b/moviepy/__init__.py@@ -11,40 +11,31 @@ you can write ``clip.resize(2)``.import inspect-from moviepy.version import __version__--# Clips-from moviepy.video.VideoClip import (- VideoClip,- ImageClip,- ColorClip,- TextClip,- BitmapClip,-)-from moviepy.video.io.VideoFileClip import VideoFileClip-from moviepy.video.compositing.CompositeVideoClip import CompositeVideoClip, clips_array-from moviepy.video.io.ImageSequenceClip import ImageSequenceClip--from moviepy.video.compositing.concatenate import concatenate_videoclips--from moviepy.video.io.downloader import download_webfile-+from moviepy.audio import fx as afxfrom moviepy.audio.AudioClip import (AudioClip,CompositeAudioClip,concatenate_audioclips,)from moviepy.audio.io.AudioFileClip import AudioFileClip--# FX-from moviepy.video import fx as vfx-from moviepy.audio import fx as afx+from moviepy.tools import convert_to_seconds+from moviepy.version import __version__+from moviepy.video import fx as vfx, tools as videotoolsfrom moviepy.video.compositing import transitions as transfx--# Tools-from moviepy.video import tools as videotools+from moviepy.video.compositing.CompositeVideoClip import CompositeVideoClip, clips_array+from moviepy.video.compositing.concatenate import concatenate_videoclipsfrom moviepy.video.io import ffmpeg_tools-from moviepy.tools import convert_to_seconds+from moviepy.video.io.downloader import download_webfile+from moviepy.video.io.ImageSequenceClip import ImageSequenceClip+from moviepy.video.io.VideoFileClip import VideoFileClip+from moviepy.video.VideoClip import (+ BitmapClip,+ ColorClip,+ ImageClip,+ TextClip,+ VideoClip,+)+# Transforms the effects into Clip methods so that# they can be called with clip.resize(width=500) instead ofdiff --git a/moviepy/audio/fx/__init__.py b/moviepy/audio/fx/__init__.pyindex e395d134..1d16ddb9 100644--- a/moviepy/audio/fx/__init__.py+++ b/moviepy/audio/fx/__init__.py@@ -7,6 +7,7 @@ from moviepy.audio.fx.audio_normalize import audio_normalizefrom moviepy.audio.fx.multiply_stereo_volume import multiply_stereo_volumefrom moviepy.audio.fx.multiply_volume import multiply_volume+__all__ = ("audio_fadein","audio_fadeout",diff --git a/moviepy/audio/fx/all/__init__.py b/moviepy/audio/fx/all/__init__.pyindex f9d87840..c6cadf1c 100644--- a/moviepy/audio/fx/all/__init__.py+++ b/moviepy/audio/fx/all/__init__.py@@ -8,4 +8,5 @@ import warningsfrom .. import * # noqa 401,F403+warnings.warn(f"\nMoviePy: {__doc__}", UserWarning)diff --git a/moviepy/audio/fx/audio_normalize.py b/moviepy/audio/fx/audio_normalize.pyindex 31aad7ce..ea706113 100644--- a/moviepy/audio/fx/audio_normalize.py+++ b/moviepy/audio/fx/audio_normalize.py@@ -1,6 +1,5 @@-from moviepy.decorators import audio_video_fx-from moviepy.audio.fx.multiply_volume import multiply_volume+from moviepy.decorators import audio_video_fx@audio_video_fxdiff --git a/moviepy/audio/io/preview.py b/moviepy/audio/io/preview.pyindex 39fc7f65..0bf6231c 100644--- a/moviepy/audio/io/preview.py+++ b/moviepy/audio/io/preview.py@@ -1,10 +1,11 @@import timeimport numpy as np-import pygame as pg+from moviepy.decorators import requires_duration+pg.init()pg.display.set_caption("MoviePy")diff --git a/moviepy/audio/io/readers.py b/moviepy/audio/io/readers.pyindex b8a381c3..8c2c2c6e 100644--- a/moviepy/audio/io/readers.py+++ b/moviepy/audio/io/readers.py@@ -4,8 +4,8 @@ import warningsimport numpy as npfrom moviepy.config import FFMPEG_BINARY-from moviepy.video.io.ffmpeg_reader import ffmpeg_parse_infosfrom moviepy.tools import cross_platform_popen_params+from moviepy.video.io.ffmpeg_reader import ffmpeg_parse_infosclass FFMPEG_AudioReader:diff --git a/moviepy/config.py b/moviepy/config.pyindex 186cd092..8fefb60e 100644--- a/moviepy/config.py+++ b/moviepy/config.py@@ -1,6 +1,6 @@import os-from pathlib import Pathimport subprocess as sp+from pathlib import Pathfrom moviepy.tools import cross_platform_popen_params@@ -9,7 +9,7 @@ if os.name == "nt":import winreg as wrtry:- from dotenv import load_dotenv, find_dotenv+ from dotenv import find_dotenv, load_dotenvDOTENV = find_dotenv()load_dotenv(DOTENV)diff --git a/moviepy/editor.py b/moviepy/editor.pyindex fc9037ce..707cac6a 100644--- a/moviepy/editor.py+++ b/moviepy/editor.py@@ -16,6 +16,7 @@ import moviepy # So that we can access moviepy.__all__ laterfrom moviepy import *from moviepy.video.io.html_tools import ipython_display+try:from moviepy.video.io.sliders import slidersexcept ImportError:@@ -39,7 +40,7 @@ os.environ["PYGAME_HIDE_SUPPORT_PROMPT"] = "1"# Add methods preview and show (only if pygame installed)try:- from moviepy.video.io.preview import show, preview+ from moviepy.video.io.preview import preview, showexcept ImportError:def preview(self, *args, **kwargs):diff --git a/moviepy/utils.py b/moviepy/utils.pyindex 24327637..0a596272 100644--- a/moviepy/utils.py+++ b/moviepy/utils.py@@ -2,6 +2,7 @@ from moviepy.audio.io.AudioFileClip import AudioFileClipfrom moviepy.video.io.VideoFileClip import VideoFileClipfrom moviepy.video.VideoClip import ImageClip+CLIP_TYPES = {"audio": AudioFileClip,"video": VideoFileClip,diff --git a/moviepy/video/VideoClip.py b/moviepy/video/VideoClip.pyindex e5f5dfc2..71a1283c 100644--- a/moviepy/video/VideoClip.py+++ b/moviepy/video/VideoClip.py@@ -4,22 +4,24 @@ main subclasses:- Animated clips: VideofileClip, ImageSequenceClip- Static image clips: ImageClip, ColorClip, TextClip,"""+import copy as _copyimport osimport subprocess as spimport tempfile-import copy as _copyimport numpy as npimport proglogfrom imageio import imread, imsave+from PIL import Image+from moviepy.Clip import Clipfrom moviepy.config import IMAGEMAGICK_BINARYfrom moviepy.decorators import (add_mask_if_none,apply_to_mask,convert_masks_to_RGB,- convert_path_to_string,convert_parameter_to_seconds,+ convert_path_to_string,outplace,requires_duration,requires_fps,@@ -38,7 +40,6 @@ from moviepy.video.io.gif_writers import (write_gif_with_tempfiles,)from moviepy.video.tools.drawing import blit-from PIL import Imageclass VideoClip(Clip):diff --git a/moviepy/video/compositing/CompositeVideoClip.py b/moviepy/video/compositing/CompositeVideoClip.pyindex 3915de71..8ae04c26 100644--- a/moviepy/video/compositing/CompositeVideoClip.py+++ b/moviepy/video/compositing/CompositeVideoClip.py@@ -1,10 +1,8 @@import numpy as np+from PIL import Imagefrom moviepy.audio.AudioClip import CompositeAudioClipfrom moviepy.video.VideoClip import ColorClip, VideoClip-from PIL import Image--# CompositeVideoClipclass CompositeVideoClip(VideoClip):diff --git a/moviepy/video/compositing/transitions.py b/moviepy/video/compositing/transitions.pyindex e5b0c83e..da7901e1 100644--- a/moviepy/video/compositing/transitions.py+++ b/moviepy/video/compositing/transitions.py@@ -4,11 +4,10 @@ to be used with clip.fx. There are available as transfx.crossfadein etc."""from moviepy.decorators import add_mask_if_none, requires_duration+from moviepy.video.compositing.CompositeVideoClip import CompositeVideoClipfrom moviepy.video.fx.fadein import fadeinfrom moviepy.video.fx.fadeout import fadeout-from moviepy.video.compositing.CompositeVideoClip import CompositeVideoClip-__all__ = ["crossfadein", "crossfadeout", "slide_in", "slide_out", "make_loopable"]diff --git a/moviepy/video/fx/all/__init__.py b/moviepy/video/fx/all/__init__.pyindex 988ef398..34b0627d 100644--- a/moviepy/video/fx/all/__init__.py+++ b/moviepy/video/fx/all/__init__.py@@ -8,4 +8,5 @@ import warningsfrom moviepy.video.fx import * # noqa F401,F403+warnings.warn(f"\nMoviePy: {__doc__}", UserWarning)diff --git a/moviepy/video/fx/freeze_region.py b/moviepy/video/fx/freeze_region.pyindex 718b93b4..4e6156f5 100644--- a/moviepy/video/fx/freeze_region.py+++ b/moviepy/video/fx/freeze_region.py@@ -1,5 +1,4 @@from moviepy.video.compositing.CompositeVideoClip import CompositeVideoClip-from moviepy.video.fx.crop import cropdiff --git a/moviepy/video/fx/headblur.py b/moviepy/video/fx/headblur.pyindex a3f5552e..fa0d50b9 100644--- a/moviepy/video/fx/headblur.py+++ b/moviepy/video/fx/headblur.py@@ -1,5 +1,6 @@import numpy as np+# ------- CHECKING DEPENDENCIES -----------------------------------------try:import cv2diff --git a/moviepy/video/fx/painting.py b/moviepy/video/fx/painting.pyindex 97d61d81..442d9926 100644--- a/moviepy/video/fx/painting.py+++ b/moviepy/video/fx/painting.py@@ -1,5 +1,6 @@import numpy as np+# ------- CHECKING DEPENDENCIES -----------------------------------------painting_possible = Truetry:diff --git a/moviepy/video/fx/rotate.py b/moviepy/video/fx/rotate.pyindex 81557fd1..7288a78e 100644--- a/moviepy/video/fx/rotate.py+++ b/moviepy/video/fx/rotate.py@@ -1,5 +1,6 @@import numpy as np+try:from PIL import Imagediff --git a/moviepy/video/fx/time_symmetrize.py b/moviepy/video/fx/time_symmetrize.pyindex e561776f..688ecc42 100644--- a/moviepy/video/fx/time_symmetrize.py+++ b/moviepy/video/fx/time_symmetrize.py@@ -1,6 +1,5 @@from moviepy.decorators import apply_to_mask, requires_durationfrom moviepy.video.compositing.concatenate import concatenate_videoclips-from moviepy.video.fx.time_mirror import time_mirrordiff --git a/moviepy/video/io/gif_writers.py b/moviepy/video/io/gif_writers.pyindex 9c530094..c217e429 100644--- a/moviepy/video/io/gif_writers.py+++ b/moviepy/video/io/gif_writers.py@@ -8,6 +8,7 @@ from moviepy.config import FFMPEG_BINARY, IMAGEMAGICK_BINARYfrom moviepy.decorators import requires_duration, use_clip_fps_by_defaultfrom moviepy.tools import cross_platform_popen_params, subprocess_call+try:import imageiodiff --git a/moviepy/video/io/html_tools.py b/moviepy/video/io/html_tools.pyindex a94c21dd..f6f55817 100644--- a/moviepy/video/io/html_tools.py+++ b/moviepy/video/io/html_tools.py@@ -14,9 +14,9 @@ from base64 import b64encodefrom moviepy.audio.AudioClip import AudioClipfrom moviepy.tools import extensions_dict--from moviepy.video.VideoClip import ImageClip, VideoClipfrom moviepy.video.io.ffmpeg_reader import ffmpeg_parse_infos+from moviepy.video.VideoClip import ImageClip, VideoClip+try:from IPython.display import HTMLdiff --git a/moviepy/video/io/preview.py b/moviepy/video/io/preview.pyindex e4d6dca1..06375c46 100644--- a/moviepy/video/io/preview.py+++ b/moviepy/video/io/preview.py@@ -2,12 +2,13 @@ import threadingimport timeimport numpy as np-import pygame as pg+from moviepy.decorators import convert_masks_to_RGB, requires_durationfrom moviepy.tools import convert_to_secondsfrom moviepy.video.compositing.CompositeVideoClip import CompositeVideoClip+pg.init()pg.display.set_caption("MoviePy")diff --git a/moviepy/video/tools/tracking.py b/moviepy/video/tools/tracking.pyindex 07aaf98a..8445e258 100644--- a/moviepy/video/tools/tracking.py+++ b/moviepy/video/tools/tracking.py@@ -11,10 +11,10 @@ of the tracking time interval).import numpy as npfrom moviepy.decorators import convert_parameter_to_seconds, use_clip_fps_by_default-from moviepy.video.io.preview import imdisplayfrom moviepy.video.tools.interpolators import Trajectory+try:import cv2diff --git a/setup.cfg b/setup.cfgindex 7f5ffeb9..53da2ff5 100644--- a/setup.cfg+++ b/setup.cfg@@ -15,3 +15,14 @@ per-file-ignores =# Complexity should be decreased before uncomment:#max-complexity = 10++[isort]+lines_after_imports = 2+multi_line_output = 3+line_length = 88+use_parentheses = True+combine_as_imports = True+include_trailing_comma = True+py_version = 36+known_tests = tests+sections = STDLIB,THIRDPARTY,FIRSTPARTY,TESTS,LOCALFOLDERdiff --git a/setup.py b/setup.pyindex f28e7fdd..af2aa3d8 100644--- a/setup.py+++ b/setup.py@@ -8,6 +8,7 @@ and fail with a message if neither are successful.import sysfrom codecs import open+try:from setuptools import find_packages, setupfrom setuptools.command.test import test as TestCommand@@ -109,6 +110,8 @@ lint_reqs = ["flake8>3.7.0,<4.0.0","flake8-implicit-str-concat==0.2.0","flake8-absolute-import>=1.0",+ "isort>=5.7.0",+ "pre-commit>=2.9.3",]extra_reqs = {diff --git a/tests/test_AudioClips.py b/tests/test_AudioClips.pyindex 1f76d043..3bfe7b9a 100644--- a/tests/test_AudioClips.py+++ b/tests/test_AudioClips.py@@ -2,8 +2,8 @@import os-import pytestimport numpy as np+import pytestfrom moviepy.audio.AudioClip import (AudioArrayClip,diff --git a/tests/test_BitmapClip.py b/tests/test_BitmapClip.pyindex 527f3e99..85b81bd2 100644--- a/tests/test_BitmapClip.py+++ b/tests/test_BitmapClip.py@@ -1,5 +1,5 @@-import pytestimport numpy as np+import pytestfrom moviepy.video.VideoClip import BitmapClipdiff --git a/tests/test_VideoClip.py b/tests/test_VideoClip.pyindex 5251a3ff..954361c1 100644--- a/tests/test_VideoClip.py+++ b/tests/test_VideoClip.py@@ -10,7 +10,7 @@ from moviepy.utils import close_all_clipsfrom moviepy.video.compositing.CompositeVideoClip import CompositeVideoClipfrom moviepy.video.fx.speedx import speedxfrom moviepy.video.io.VideoFileClip import VideoFileClip-from moviepy.video.VideoClip import ColorClip, BitmapClip, VideoClip+from moviepy.video.VideoClip import BitmapClip, ColorClip, VideoClipfrom tests.test_helper import TMP_DIRdiff --git a/tests/test_compositing.py b/tests/test_compositing.pyindex 685970da..02b9ca66 100644--- a/tests/test_compositing.py+++ b/tests/test_compositing.py@@ -4,11 +4,11 @@ import osimport pytest-from moviepy.video.VideoClip import BitmapClip, ColorClip-from moviepy.video.compositing.concatenate import concatenate_videoclips+from moviepy.utils import close_all_clipsfrom moviepy.video.compositing.CompositeVideoClip import clips_array+from moviepy.video.compositing.concatenate import concatenate_videoclipsfrom moviepy.video.fx.resize import resize-from moviepy.utils import close_all_clips+from moviepy.video.VideoClip import BitmapClip, ColorClipfrom tests.test_helper import TMP_DIRdiff --git a/tests/test_examples.py b/tests/test_examples.pyindex b9bc36d4..736bc558 100644--- a/tests/test_examples.py+++ b/tests/test_examples.py@@ -8,6 +8,7 @@ from moviepy.video.VideoClip import VideoClipfrom tests.test_helper import TMP_DIR+try:import matplotlibexcept ImportError:diff --git a/tests/test_ffmpeg_reader.py b/tests/test_ffmpeg_reader.pyindex 8a344f55..082e33b0 100644--- a/tests/test_ffmpeg_reader.py+++ b/tests/test_ffmpeg_reader.py@@ -3,14 +3,14 @@import osimport subprocess-import pytestimport numpy as np+import pytest-from moviepy.config import FFMPEG_BINARYfrom moviepy.audio.AudioClip import AudioClip-from moviepy.video.VideoClip import BitmapClip-from moviepy.video.io.ffmpeg_reader import ffmpeg_parse_infos, FFMPEG_VideoReader+from moviepy.config import FFMPEG_BINARYfrom moviepy.utils import close_all_clips+from moviepy.video.io.ffmpeg_reader import FFMPEG_VideoReader, ffmpeg_parse_infos+from moviepy.video.VideoClip import BitmapClipfrom tests.test_helper import TMP_DIRdiff --git a/tests/test_ffmpeg_tools.py b/tests/test_ffmpeg_tools.pyindex 8baf6e7d..d1e7c1c1 100644--- a/tests/test_ffmpeg_tools.py+++ b/tests/test_ffmpeg_tools.py@@ -1,6 +1,7 @@import osfrom moviepy.video.io.ffmpeg_tools import ffmpeg_stabilize_video+from tests.test_helper import TMP_DIRdiff --git a/tests/test_fx.py b/tests/test_fx.pyindex dbcfac9f..39076e95 100644--- a/tests/test_fx.py+++ b/tests/test_fx.py@@ -5,12 +5,10 @@ import numpy as npimport pytestfrom moviepy import AudioClip, AudioFileClip, BitmapClip, ColorClip, VideoFileClip-from moviepy.audio.fx import audio_normalize-from moviepy.audio.fx import multiply_stereo_volume+from moviepy.audio.fx import audio_normalize, multiply_stereo_volumefrom moviepy.utils import close_all_clipsfrom moviepy.video.fx import (blackwhite,- multiply_color,crop,even_size,fadein,@@ -24,6 +22,7 @@ from moviepy.video.fx import (margin,mirror_x,mirror_y,+ multiply_color,resize,rotate,speedx,diff --git a/tests/test_helper.py b/tests/test_helper.pyindex f204fc77..ccb9fff6 100644--- a/tests/test_helper.py+++ b/tests/test_helper.py@@ -3,6 +3,7 @@import sysimport tempfile+PYTHON_VERSION = "%s.%s" % (sys.version_info.major, sys.version_info.minor)TMP_DIR = tempfile.gettempdir() # because tempfile.tempdir is sometimes Nonediff --git a/tests/test_issues.py b/tests/test_issues.pyindex dbcc5157..1a8ca7f8 100644--- a/tests/test_issues.py+++ b/tests/test_issues.py@@ -1,19 +1,21 @@"""Issue tests meant to be run with pytest."""-import pytestimport os-from moviepy.video.VideoClip import ColorClip, ImageClip, VideoClip+import pytest++from moviepy.audio.io.AudioFileClip import AudioFileClip+from moviepy.utils import close_all_clipsfrom moviepy.video.compositing.CompositeVideoClip import CompositeVideoClipfrom moviepy.video.compositing.concatenate import concatenate_videoclipsfrom moviepy.video.compositing.transitions import crossfadein, crossfadeoutfrom moviepy.video.fx.resize import resize-from moviepy.audio.io.AudioFileClip import AudioFileClipfrom moviepy.video.io.VideoFileClip import VideoFileClip-from moviepy.utils import close_all_clips+from moviepy.video.VideoClip import ColorClip, ImageClip, VideoClipfrom tests.test_helper import TMP_DIR+try:import matplotlibexcept ImportError:@@ -268,10 +270,11 @@ def test_issue_359():@pytest.mark.skipif(not matplotlib, reason="no matplotlib")def test_issue_368():- import numpy as npimport matplotlib.pyplot as plt+ import numpy as npfrom sklearn import svmfrom sklearn.datasets import make_moons+from moviepy.video.io.bindings import mplfig_to_npimageplt.switch_backend("agg")diff --git a/tests/test_misc.py b/tests/test_misc.pyindex c45a1fff..2e09459f 100644--- a/tests/test_misc.py+++ b/tests/test_misc.py@@ -2,12 +2,12 @@ import osimport pytest-from moviepy.video.tools.cuts import find_video_period-from moviepy.video.fx.resize import resizefrom moviepy.utils import close_all_clipsfrom moviepy.video.compositing.CompositeVideoClip import CompositeVideoClipfrom moviepy.video.compositing.concatenate import concatenate_videoclips+from moviepy.video.fx.resize import resizefrom moviepy.video.io.VideoFileClip import VideoFileClip+from moviepy.video.tools.cuts import find_video_periodfrom moviepy.video.tools.subtitles import SubtitlesClip, file_to_subtitlesfrom moviepy.video.VideoClip import ColorClip, TextClip