Skip to content

Commit

Permalink
applies isort to code base, adds check in CI (#304)
Browse files Browse the repository at this point in the history
  • Loading branch information
fakufaku authored Feb 7, 2023
1 parent b73182a commit 0ccf8ae
Show file tree
Hide file tree
Showing 115 changed files with 260 additions and 149 deletions.
7 changes: 6 additions & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,16 @@ jobs:
python-version: 3.8

- name: Install Python dependencies
run: pip install black flake8
run: pip install black flake8 isort

- name: Run linters
uses: wearerequired/lint-action@v2
with:
black: true
black_args: "--check"
flake8: false

- name: Sort imports
uses: isort/[email protected]
with:
configuration: --check-only --diff --profile black
9 changes: 8 additions & 1 deletion CONTRIBUTING.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,16 @@ We try to stick to `PEP8 <https://www.python.org/dev/peps/pep-0008/>`__
as much as possible. Variables, functions, modules and packages should
be in lowercase with underscores. Class names in CamelCase.

We use `Black <https://github.com/psf/black>`__ to format the code.
We use `Black <https://github.com/psf/black>`__ to format the code and `isort <https://pycqa.github.io/isort/>`__ to sort the imports.
The format will be automatically checked when doing a pull request so it is
recommended to regularly run Black on the code.
Please format your code as follows prior to commiting.

.. code-block:: shell
pip install black isort
black .
isort --profile black .
Documentation
~~~~~~~~~~~~~
Expand Down
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
# All configuration values have a default; values that are commented out
# serve to show the default.

import sys
import os
import sys

# mock modules for compilation without installing all packages
MOCK_MODULES = [
Expand Down
3 changes: 2 additions & 1 deletion examples/adaptive_filter_stft_domain.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@
"""
from __future__ import division, print_function

import matplotlib.pyplot as plt
import numpy as np
from scipy.signal import fftconvolve
import matplotlib.pyplot as plt

import pyroomacoustics as pra

# parameters
Expand Down
3 changes: 2 additions & 1 deletion examples/adaptive_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
"""
from __future__ import division, print_function

import matplotlib.pyplot as plt
import numpy as np
from scipy.signal import fftconvolve
import matplotlib.pyplot as plt

import pyroomacoustics as pra

# parameters
Expand Down
5 changes: 3 additions & 2 deletions examples/beamforming_delay_and_sum.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
"""
This example shows how to create delay and sum beamformers
"""
from __future__ import print_function, division
from __future__ import division, print_function

import numpy as np
import matplotlib.pyplot as plt
import numpy as np

import pyroomacoustics as pra

# Create a 4 by 6 metres anechoic room
Expand Down
3 changes: 2 additions & 1 deletion examples/beamforming_time_domain.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
from __future__ import division, print_function

import os
import numpy as np

import matplotlib.pyplot as plt
import numpy as np
from scipy.io import wavfile

import pyroomacoustics as pra
Expand Down
7 changes: 4 additions & 3 deletions examples/bss_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@
This script requires the `mir_eval` to run, and `tkinter` and `sounddevice` packages for the GUI option.
"""
import time
import numpy as np
from scipy.io import wavfile

import numpy as np
from mir_eval.separation import bss_eval_sources
from scipy.io import wavfile

# We concatenate a few samples to make them long enough
wav_files = [
Expand Down Expand Up @@ -292,7 +292,8 @@ def convergence_callback(Y):

if args.gui:
# Make a simple GUI to listen to the separated samples
from tkinter import Tk, Button, Label
from tkinter import Button, Label, Tk

import sounddevice as sd

# Now comes the GUI part
Expand Down
7 changes: 3 additions & 4 deletions examples/bss_live.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,18 +53,17 @@
This script requires the `sounddevice` packages to run.
"""

import numpy as np

# important to avoid a crash when tkinter is called
import matplotlib
import numpy as np

matplotlib.use("TkAgg")

import pyroomacoustics as pra
from tkinter import Button, Label, Tk

from tkinter import Tk, Label, Button
import sounddevice as sd

import pyroomacoustics as pra

if __name__ == "__main__":
choices = ["ilrma", "auxiva", "sparseauxiva", "fastmnmf", "fastmnmf2"]
Expand Down
3 changes: 2 additions & 1 deletion examples/cmu_arctic_corpus.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@
CMU, 2003.
"""

import pyroomacoustics as pra
import argparse
import os

import pyroomacoustics as pra

if __name__ == "__main__":
parser = argparse.ArgumentParser(
description="Example of using the CMUArcticCorpus wrapper"
Expand Down
2 changes: 1 addition & 1 deletion examples/datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Example of the basic operations with ``pyroomacoustics.datasets.Dataset``
and ``pyroomacoustics.datasets.Sample`` classes
"""
from pyroomacoustics.datasets import Sample, Dataset
from pyroomacoustics.datasets import Dataset, Sample

# Prepare a few artificial samples
samples = [
Expand Down
5 changes: 2 additions & 3 deletions examples/directivities/cardioid_function.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import numpy as np
import matplotlib.pyplot as plt
import numpy as np

from pyroomacoustics import dB, all_combinations
from pyroomacoustics import all_combinations, dB
from pyroomacoustics.directivities import cardioid_func
from pyroomacoustics.doa import spher2cart


azimuth = np.radians(np.linspace(start=0, stop=360, num=361, endpoint=True))
colatitude = np.radians(np.linspace(start=0, stop=180, num=180, endpoint=True))
lower_gain = -40
Expand Down
6 changes: 3 additions & 3 deletions examples/directivities/circular_mic_array.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import matplotlib.pyplot as plt

import pyroomacoustics as pra
from pyroomacoustics.directivities import (
DirectionVector,
CardioidFamily,
DirectionVector,
DirectivityPattern,
)
import matplotlib.pyplot as plt


three_dim = True # 2D or 3D

Expand Down
10 changes: 5 additions & 5 deletions examples/directivities/mic_array.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import pyroomacoustics as pra
import numpy as np
import matplotlib.pyplot as plt
import numpy as np

import pyroomacoustics as pra
from pyroomacoustics.directivities import (
DirectivityPattern,
DirectionVector,
CardioidFamily,
DirectionVector,
DirectivityPattern,
)


pattern = DirectivityPattern.HYPERCARDIOID
orientation = DirectionVector(azimuth=0, colatitude=0, degrees=True)

Expand Down
10 changes: 5 additions & 5 deletions examples/directivities/mic_array_diff_directivities.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import pyroomacoustics as pra
import numpy as np
import matplotlib.pyplot as plt
import numpy as np

import pyroomacoustics as pra
from pyroomacoustics.directivities import (
DirectivityPattern,
DirectionVector,
CardioidFamily,
DirectionVector,
DirectivityPattern,
)


dir_1 = CardioidFamily(
orientation=DirectionVector(azimuth=180, colatitude=30, degrees=True),
pattern_enum=DirectivityPattern.HYPERCARDIOID,
Expand Down
6 changes: 3 additions & 3 deletions examples/directivities/plot_directivity_2D.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import numpy as np
import matplotlib.pyplot as plt
import numpy as np

from pyroomacoustics import dB
from pyroomacoustics.directivities import (
DirectivityPattern,
DirectionVector,
CardioidFamily,
DirectionVector,
DirectivityPattern,
)

orientation = DirectionVector(azimuth=0, colatitude=90, degrees=True)
Expand Down
7 changes: 3 additions & 4 deletions examples/directivities/plot_directivity_3D.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import numpy as np
import matplotlib.pyplot as plt
import numpy as np

from pyroomacoustics.directivities import (
DirectivityPattern,
DirectionVector,
CardioidFamily,
DirectionVector,
DirectivityPattern,
)


pattern = DirectivityPattern.HYPERCARDIOID
orientation = DirectionVector(azimuth=0, colatitude=45, degrees=True)

Expand Down
9 changes: 5 additions & 4 deletions examples/directivities/source_and_microphone.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import pyroomacoustics as pra
import numpy as np
import matplotlib.pyplot as plt
import numpy as np

import pyroomacoustics as pra
from pyroomacoustics.directivities import (
DirectivityPattern,
DirectionVector,
CardioidFamily,
DirectionVector,
DirectivityPattern,
)

three_dim = True # 2D or 3D
Expand Down
2 changes: 1 addition & 1 deletion examples/doa_algorithms.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@
"""

import matplotlib.pyplot as plt
import numpy as np
from scipy.signal import fftconvolve
import matplotlib.pyplot as plt

import pyroomacoustics as pra
from pyroomacoustics.doa import circ_dist
Expand Down
1 change: 1 addition & 0 deletions examples/google_speech_commands_corpus.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

import argparse
import os

import pyroomacoustics as pra

if __name__ == "__main__":
Expand Down
4 changes: 3 additions & 1 deletion examples/hmm_training.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@
Then we train a second models on these examples.
"""

from __future__ import print_function, division
from __future__ import division, print_function

import numpy as np

from pyroomacoustics import HMM, CircularGaussianEmission, GaussianEmission

if __name__ == "__main__":
Expand Down
6 changes: 4 additions & 2 deletions examples/noise_reduction_spectral_subtraction.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,13 @@
`pyroomacoustics.denoise.apply_spectral_sub` can be used.
"""

import os

import matplotlib.pyplot as plt
import numpy as np
from scipy.io import wavfile
import os

import pyroomacoustics as pra
import matplotlib.pyplot as plt
from pyroomacoustics.denoise import SpectralSub

"""
Expand Down
8 changes: 5 additions & 3 deletions examples/noise_reduction_subspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@
`pyroomacoustics.denoise.apply_subspace` can be used.
"""

import os
import time

import matplotlib.pyplot as plt
import numpy as np
from scipy.io import wavfile
import os

import pyroomacoustics as pra
import matplotlib.pyplot as plt
import time
from pyroomacoustics.denoise import Subspace

"""
Expand Down
9 changes: 5 additions & 4 deletions examples/noise_reduction_wiener_filtering.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import os
import time

import matplotlib.pyplot as plt
import numpy as np
from scipy.io import wavfile
import os

import pyroomacoustics as pra
import matplotlib.pyplot as plt
import time
from pyroomacoustics.denoise import IterativeWiener


"""
Test and algorithm parameters
"""
Expand Down
8 changes: 4 additions & 4 deletions examples/randomized_image_method.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
image method to remove sweeping echoes in RIRs simulated with ISM.
"""

import numpy as np
import pyroomacoustics as pra
import matplotlib.pyplot as plt
from pyroomacoustics.transform import stft
from pyroomacoustics import metrics as met
import numpy as np
from mpl_toolkits.mplot3d import Axes3D

import pyroomacoustics as pra
from pyroomacoustics import metrics as met
from pyroomacoustics.transform import stft

# create an example with sweeping echo - from Enzo's paper
room_size = [4, 4, 4]
Expand Down
1 change: 1 addition & 0 deletions examples/room_complex_wall_materials.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"""
import matplotlib.pyplot as plt
import numpy as np

import pyroomacoustics as pra

# Define the materials array
Expand Down
3 changes: 2 additions & 1 deletion examples/room_from_rt60.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@

import matplotlib.pyplot as plt
import numpy as np
import pyroomacoustics as pra
from scipy.io import wavfile

import pyroomacoustics as pra

methods = ["ism", "hybrid"]

if __name__ == "__main__":
Expand Down
Loading

0 comments on commit 0ccf8ae

Please sign in to comment.