Skip to content

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.md
index 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 file
diff --git a/.github/workflows/format_check.yml b/.github/workflows/format_check.yml
index 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 moviepy
run: 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.py
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
new file mode 100644
index 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.md
index 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.rst
index 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=60s
Maintainers 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 Sci
Documentation
-------------
-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/mondeja
diff --git a/docs/conf.py b/docs/conf.py
index f822fb66..2c895f80 100644
--- a/docs/conf.py
+++ b/docs/conf.py
@@ -14,10 +14,9 @@
import os
import 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.py
index 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.py
index 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_period
from 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.py
index 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 SCENE
diff --git a/examples/headblur.py b/examples/headblur.py
index 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 401
from 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.py
index 93b46cf9..30be3e96 100644
--- a/examples/logo.py
+++ b/examples/logo.py
@@ -2,6 +2,7 @@ import numpy as np
from moviepy import *
+
w, h = moviesize = (720, 380)
duration = 1
diff --git a/examples/masked_credits.py b/examples/masked_credits.py
index 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 darker
clip = (
VideoFileClip("../../videos/badl-0001.mov", audio=False)
diff --git a/examples/moving_letters.py b/examples/moving_letters.py
index fc7b0d7d..2aa252b7 100644
--- a/examples/moving_letters.py
+++ b/examples/moving_letters.py
@@ -3,6 +3,7 @@ import numpy as np
from 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.py
index 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 FREEZE
charade = VideoFileClip("../../videos/charade.mp4")
diff --git a/examples/soundtrack.py b/examples/soundtrack.py
index 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.py
index 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 tf
from moviepy import *
from moviepy.video.tools.drawing import color_gradient
-from skimage import transform as tf
+
# RESOLUTION
diff --git a/examples/the_end.py b/examples/the_end.py
index 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.py
index 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 FOOTAGE
diff --git a/find_latest_imagemagick_version.py b/find_latest_imagemagick_version.py
index 0cafba98..d3bbbc2e 100644
--- a/find_latest_imagemagick_version.py
+++ b/find_latest_imagemagick_version.py
@@ -1,6 +1,7 @@
import re
from urllib import request
+
url = "https://legacy.imagemagick.org/script/index.php"
"""This little script parses url above to extract latest image magick version
diff --git a/moviepy/__init__.py b/moviepy/__init__.py
index 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 afx
from 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 videotools
from 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_videoclips
from 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 of
diff --git a/moviepy/audio/fx/__init__.py b/moviepy/audio/fx/__init__.py
index 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_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",
diff --git a/moviepy/audio/fx/all/__init__.py b/moviepy/audio/fx/all/__init__.py
index f9d87840..c6cadf1c 100644
--- a/moviepy/audio/fx/all/__init__.py
+++ b/moviepy/audio/fx/all/__init__.py
@@ -8,4 +8,5 @@ import warnings
from .. 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.py
index 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_fx
diff --git a/moviepy/audio/io/preview.py b/moviepy/audio/io/preview.py
index 39fc7f65..0bf6231c 100644
--- a/moviepy/audio/io/preview.py
+++ b/moviepy/audio/io/preview.py
@@ -1,10 +1,11 @@
import time
import 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.py
index b8a381c3..8c2c2c6e 100644
--- a/moviepy/audio/io/readers.py
+++ b/moviepy/audio/io/readers.py
@@ -4,8 +4,8 @@ import warnings
import numpy as np
from moviepy.config import FFMPEG_BINARY
-from moviepy.video.io.ffmpeg_reader import ffmpeg_parse_infos
from moviepy.tools import cross_platform_popen_params
+from moviepy.video.io.ffmpeg_reader import ffmpeg_parse_infos
class FFMPEG_AudioReader:
diff --git a/moviepy/config.py b/moviepy/config.py
index 186cd092..8fefb60e 100644
--- a/moviepy/config.py
+++ b/moviepy/config.py
@@ -1,6 +1,6 @@
import os
-from pathlib import Path
import subprocess as sp
+from pathlib import Path
from moviepy.tools import cross_platform_popen_params
@@ -9,7 +9,7 @@ if os.name == "nt":
import winreg as wr
try:
- from dotenv import load_dotenv, find_dotenv
+ from dotenv import find_dotenv, load_dotenv
DOTENV = find_dotenv()
load_dotenv(DOTENV)
diff --git a/moviepy/editor.py b/moviepy/editor.py
index fc9037ce..707cac6a 100644
--- a/moviepy/editor.py
+++ b/moviepy/editor.py
@@ -16,6 +16,7 @@ import moviepy # So that we can access moviepy.__all__ later
from moviepy import *
from moviepy.video.io.html_tools import ipython_display
+
try:
from moviepy.video.io.sliders import sliders
except 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, show
except ImportError:
def preview(self, *args, **kwargs):
diff --git a/moviepy/utils.py b/moviepy/utils.py
index 24327637..0a596272 100644
--- a/moviepy/utils.py
+++ b/moviepy/utils.py
@@ -2,6 +2,7 @@ from moviepy.audio.io.AudioFileClip import AudioFileClip
from moviepy.video.io.VideoFileClip import VideoFileClip
from moviepy.video.VideoClip import ImageClip
+
CLIP_TYPES = {
"audio": AudioFileClip,
"video": VideoFileClip,
diff --git a/moviepy/video/VideoClip.py b/moviepy/video/VideoClip.py
index 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 _copy
import os
import subprocess as sp
import tempfile
-import copy as _copy
import numpy as np
import proglog
from imageio import imread, imsave
+from PIL import Image
+
from moviepy.Clip import Clip
from moviepy.config import IMAGEMAGICK_BINARY
from 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 Image
class VideoClip(Clip):
diff --git a/moviepy/video/compositing/CompositeVideoClip.py b/moviepy/video/compositing/CompositeVideoClip.py
index 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 Image
from moviepy.audio.AudioClip import CompositeAudioClip
from moviepy.video.VideoClip import ColorClip, VideoClip
-from PIL import Image
-
-# CompositeVideoClip
class CompositeVideoClip(VideoClip):
diff --git a/moviepy/video/compositing/transitions.py b/moviepy/video/compositing/transitions.py
index 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 CompositeVideoClip
from moviepy.video.fx.fadein import fadein
from 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__.py
index 988ef398..34b0627d 100644
--- a/moviepy/video/fx/all/__init__.py
+++ b/moviepy/video/fx/all/__init__.py
@@ -8,4 +8,5 @@ import warnings
from 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.py
index 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 crop
diff --git a/moviepy/video/fx/headblur.py b/moviepy/video/fx/headblur.py
index 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 cv2
diff --git a/moviepy/video/fx/painting.py b/moviepy/video/fx/painting.py
index 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 = True
try:
diff --git a/moviepy/video/fx/rotate.py b/moviepy/video/fx/rotate.py
index 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 Image
diff --git a/moviepy/video/fx/time_symmetrize.py b/moviepy/video/fx/time_symmetrize.py
index 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_duration
from moviepy.video.compositing.concatenate import concatenate_videoclips
-
from moviepy.video.fx.time_mirror import time_mirror
diff --git a/moviepy/video/io/gif_writers.py b/moviepy/video/io/gif_writers.py
index 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_BINARY
from moviepy.decorators import requires_duration, use_clip_fps_by_default
from moviepy.tools import cross_platform_popen_params, subprocess_call
+
try:
import imageio
diff --git a/moviepy/video/io/html_tools.py b/moviepy/video/io/html_tools.py
index a94c21dd..f6f55817 100644
--- a/moviepy/video/io/html_tools.py
+++ b/moviepy/video/io/html_tools.py
@@ -14,9 +14,9 @@ from base64 import b64encode
from moviepy.audio.AudioClip import AudioClip
from moviepy.tools import extensions_dict
-
-from moviepy.video.VideoClip import ImageClip, VideoClip
from moviepy.video.io.ffmpeg_reader import ffmpeg_parse_infos
+from moviepy.video.VideoClip import ImageClip, VideoClip
+
try:
from IPython.display import HTML
diff --git a/moviepy/video/io/preview.py b/moviepy/video/io/preview.py
index e4d6dca1..06375c46 100644
--- a/moviepy/video/io/preview.py
+++ b/moviepy/video/io/preview.py
@@ -2,12 +2,13 @@ import threading
import time
import numpy as np
-
import pygame as pg
+
from moviepy.decorators import convert_masks_to_RGB, requires_duration
from moviepy.tools import convert_to_seconds
from 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.py
index 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 np
from moviepy.decorators import convert_parameter_to_seconds, use_clip_fps_by_default
-
from moviepy.video.io.preview import imdisplay
from moviepy.video.tools.interpolators import Trajectory
+
try:
import cv2
diff --git a/setup.cfg b/setup.cfg
index 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,LOCALFOLDER
diff --git a/setup.py b/setup.py
index f28e7fdd..af2aa3d8 100644
--- a/setup.py
+++ b/setup.py
@@ -8,6 +8,7 @@ and fail with a message if neither are successful.
import sys
from codecs import open
+
try:
from setuptools import find_packages, setup
from 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.py
index 1f76d043..3bfe7b9a 100644
--- a/tests/test_AudioClips.py
+++ b/tests/test_AudioClips.py
@@ -2,8 +2,8 @@
import os
-import pytest
import numpy as np
+import pytest
from moviepy.audio.AudioClip import (
AudioArrayClip,
diff --git a/tests/test_BitmapClip.py b/tests/test_BitmapClip.py
index 527f3e99..85b81bd2 100644
--- a/tests/test_BitmapClip.py
+++ b/tests/test_BitmapClip.py
@@ -1,5 +1,5 @@
-import pytest
import numpy as np
+import pytest
from moviepy.video.VideoClip import BitmapClip
diff --git a/tests/test_VideoClip.py b/tests/test_VideoClip.py
index 5251a3ff..954361c1 100644
--- a/tests/test_VideoClip.py
+++ b/tests/test_VideoClip.py
@@ -10,7 +10,7 @@ from moviepy.utils import close_all_clips
from moviepy.video.compositing.CompositeVideoClip import CompositeVideoClip
from moviepy.video.fx.speedx import speedx
from moviepy.video.io.VideoFileClip import VideoFileClip
-from moviepy.video.VideoClip import ColorClip, BitmapClip, VideoClip
+from moviepy.video.VideoClip import BitmapClip, ColorClip, VideoClip
from tests.test_helper import TMP_DIR
diff --git a/tests/test_compositing.py b/tests/test_compositing.py
index 685970da..02b9ca66 100644
--- a/tests/test_compositing.py
+++ b/tests/test_compositing.py
@@ -4,11 +4,11 @@ import os
import pytest
-from moviepy.video.VideoClip import BitmapClip, ColorClip
-from moviepy.video.compositing.concatenate import concatenate_videoclips
+from moviepy.utils import close_all_clips
from moviepy.video.compositing.CompositeVideoClip import clips_array
+from moviepy.video.compositing.concatenate import concatenate_videoclips
from moviepy.video.fx.resize import resize
-from moviepy.utils import close_all_clips
+from moviepy.video.VideoClip import BitmapClip, ColorClip
from tests.test_helper import TMP_DIR
diff --git a/tests/test_examples.py b/tests/test_examples.py
index b9bc36d4..736bc558 100644
--- a/tests/test_examples.py
+++ b/tests/test_examples.py
@@ -8,6 +8,7 @@ from moviepy.video.VideoClip import VideoClip
from tests.test_helper import TMP_DIR
+
try:
import matplotlib
except ImportError:
diff --git a/tests/test_ffmpeg_reader.py b/tests/test_ffmpeg_reader.py
index 8a344f55..082e33b0 100644
--- a/tests/test_ffmpeg_reader.py
+++ b/tests/test_ffmpeg_reader.py
@@ -3,14 +3,14 @@
import os
import subprocess
-import pytest
import numpy as np
+import pytest
-from moviepy.config import FFMPEG_BINARY
from 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_BINARY
from moviepy.utils import close_all_clips
+from moviepy.video.io.ffmpeg_reader import FFMPEG_VideoReader, ffmpeg_parse_infos
+from moviepy.video.VideoClip import BitmapClip
from tests.test_helper import TMP_DIR
diff --git a/tests/test_ffmpeg_tools.py b/tests/test_ffmpeg_tools.py
index 8baf6e7d..d1e7c1c1 100644
--- a/tests/test_ffmpeg_tools.py
+++ b/tests/test_ffmpeg_tools.py
@@ -1,6 +1,7 @@
import os
from moviepy.video.io.ffmpeg_tools import ffmpeg_stabilize_video
+
from tests.test_helper import TMP_DIR
diff --git a/tests/test_fx.py b/tests/test_fx.py
index dbcfac9f..39076e95 100644
--- a/tests/test_fx.py
+++ b/tests/test_fx.py
@@ -5,12 +5,10 @@ import numpy as np
import pytest
from 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_volume
from moviepy.utils import close_all_clips
from 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.py
index f204fc77..ccb9fff6 100644
--- a/tests/test_helper.py
+++ b/tests/test_helper.py
@@ -3,6 +3,7 @@
import sys
import tempfile
+
PYTHON_VERSION = "%s.%s" % (sys.version_info.major, sys.version_info.minor)
TMP_DIR = tempfile.gettempdir() # because tempfile.tempdir is sometimes None
diff --git a/tests/test_issues.py b/tests/test_issues.py
index 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 pytest
import os
-from moviepy.video.VideoClip import ColorClip, ImageClip, VideoClip
+import pytest
+
+from moviepy.audio.io.AudioFileClip import AudioFileClip
+from moviepy.utils import close_all_clips
from moviepy.video.compositing.CompositeVideoClip import CompositeVideoClip
from moviepy.video.compositing.concatenate import concatenate_videoclips
from moviepy.video.compositing.transitions import crossfadein, crossfadeout
from moviepy.video.fx.resize import resize
-from moviepy.audio.io.AudioFileClip import AudioFileClip
from moviepy.video.io.VideoFileClip import VideoFileClip
-from moviepy.utils import close_all_clips
+from moviepy.video.VideoClip import ColorClip, ImageClip, VideoClip
from tests.test_helper import TMP_DIR
+
try:
import matplotlib
except ImportError:
@@ -268,10 +270,11 @@ def test_issue_359():
@pytest.mark.skipif(not matplotlib, reason="no matplotlib")
def test_issue_368():
- import numpy as np
import matplotlib.pyplot as plt
+ import numpy as np
from sklearn import svm
from sklearn.datasets import make_moons
+
from moviepy.video.io.bindings import mplfig_to_npimage
plt.switch_backend("agg")
diff --git a/tests/test_misc.py b/tests/test_misc.py
index c45a1fff..2e09459f 100644
--- a/tests/test_misc.py
+++ b/tests/test_misc.py
@@ -2,12 +2,12 @@ import os
import pytest
-from moviepy.video.tools.cuts import find_video_period
-from moviepy.video.fx.resize import resize
from moviepy.utils import close_all_clips
from moviepy.video.compositing.CompositeVideoClip import CompositeVideoClip
from moviepy.video.compositing.concatenate import concatenate_videoclips
+from moviepy.video.fx.resize import resize
from moviepy.video.io.VideoFileClip import VideoFileClip
+from moviepy.video.tools.cuts import find_video_period
from moviepy.video.tools.subtitles import SubtitlesClip, file_to_subtitles
from moviepy.video.VideoClip import ColorClip, TextClip