From 35d0c825f72d7b24f17095573923fe418f5249b6 Mon Sep 17 00:00:00 2001 From: Alastair Porter Date: Tue, 17 Sep 2024 15:17:26 +0200 Subject: [PATCH] Order imports and add action to check --- .github/workflows/isort.yaml | 10 ++++++++++ setup.py | 5 +++-- smstools/models/dftModel.py | 4 +++- smstools/models/harmonicModel.py | 8 +++++--- smstools/models/hprModel.py | 10 ++++++---- smstools/models/hpsModel.py | 10 ++++++---- smstools/models/sineModel.py | 6 ++++-- smstools/models/sprModel.py | 6 ++++-- smstools/models/spsModel.py | 10 ++++++---- smstools/models/stft.py | 1 + smstools/models/stochasticModel.py | 5 +++-- smstools/models/utilFunctions.py | 4 ++-- smstools/models/utilFunctions_C/cutilFunctions.pyx | 3 ++- smstools/transformations/stftTransformations.py | 6 +++++- 14 files changed, 60 insertions(+), 28 deletions(-) create mode 100644 .github/workflows/isort.yaml diff --git a/.github/workflows/isort.yaml b/.github/workflows/isort.yaml new file mode 100644 index 00000000..ea44105d --- /dev/null +++ b/.github/workflows/isort.yaml @@ -0,0 +1,10 @@ +name: Run isort + +on: [push, pull_request] + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: isort/isort-action@v1 diff --git a/setup.py b/setup.py index 435e1e37..fb09fded 100644 --- a/setup.py +++ b/setup.py @@ -1,7 +1,8 @@ -from setuptools import Extension, setup -from Cython.Build import cythonize import sys + import numpy +from Cython.Build import cythonize +from setuptools import Extension, setup sourcefiles = [ "smstools/models/utilFunctions_C/utilFunctions.c", diff --git a/smstools/models/dftModel.py b/smstools/models/dftModel.py index 5b9cc6d5..9ef4a231 100644 --- a/smstools/models/dftModel.py +++ b/smstools/models/dftModel.py @@ -1,9 +1,11 @@ # functions that implement analysis and synthesis of sounds using the Discrete Fourier Transform # (for example usage check dftModel_function.py in the interface directory) -import numpy as np import math + +import numpy as np from scipy.fft import fft, ifft + from smstools.models import utilFunctions as UF tol = 1e-14 # threshold used to compute phase diff --git a/smstools/models/harmonicModel.py b/smstools/models/harmonicModel.py index 5c9116d8..a1bcd877 100644 --- a/smstools/models/harmonicModel.py +++ b/smstools/models/harmonicModel.py @@ -1,13 +1,15 @@ # functions that implement analysis and synthesis of sounds using the Harmonic Model # (for example usage check the interface directory) +import math + import numpy as np -from scipy.signal.windows import blackmanharris, triang from scipy.fft import ifft -import math +from scipy.signal.windows import blackmanharris, triang + from smstools.models import dftModel as DFT -from smstools.models import utilFunctions as UF from smstools.models import sineModel as SM +from smstools.models import utilFunctions as UF def f0Detection(x, fs, w, N, H, t, minf0, maxf0, f0et): diff --git a/smstools/models/hprModel.py b/smstools/models/hprModel.py index f18dc19b..17393608 100644 --- a/smstools/models/hprModel.py +++ b/smstools/models/hprModel.py @@ -1,14 +1,16 @@ # functions that implement analysis and synthesis of sounds using the Harmonic plus Residual Model # (for example usage check the interface directory) -import numpy as np import math -from scipy.signal.windows import blackmanharris, triang + +import numpy as np from scipy.fft import fft, ifft -from smstools.models import harmonicModel as HM +from scipy.signal.windows import blackmanharris, triang + from smstools.models import dftModel as DFT -from smstools.models import utilFunctions as UF +from smstools.models import harmonicModel as HM from smstools.models import sineModel as SM +from smstools.models import utilFunctions as UF def hprModelAnal(x, fs, w, N, H, t, minSineDur, nH, minf0, maxf0, f0et, harmDevSlope): diff --git a/smstools/models/hpsModel.py b/smstools/models/hpsModel.py index c3ef7934..99738098 100644 --- a/smstools/models/hpsModel.py +++ b/smstools/models/hpsModel.py @@ -1,14 +1,16 @@ # functions that implement analysis and synthesis of sounds using the Harmonic plus Stochastic Model # (for example usage check the examples interface) +import math + import numpy as np -from scipy.signal import resample -from scipy.signal.windows import blackmanharris, triang, hann from scipy.fft import fft, ifft -import math +from scipy.signal import resample +from scipy.signal.windows import blackmanharris, hann, triang + +from smstools.models import dftModel as DFT from smstools.models import harmonicModel as HM from smstools.models import sineModel as SM -from smstools.models import dftModel as DFT from smstools.models import stochasticModel as STM from smstools.models import utilFunctions as UF diff --git a/smstools/models/sineModel.py b/smstools/models/sineModel.py index ca29700f..1ad95411 100644 --- a/smstools/models/sineModel.py +++ b/smstools/models/sineModel.py @@ -1,10 +1,12 @@ # functions that implement analysis and synthesis of sounds using the Sinusoidal Model # (for example usage check the examples in interface) +import math + import numpy as np +from scipy.fft import fftshift, ifft from scipy.signal.windows import blackmanharris, triang -from scipy.fft import ifft, fftshift -import math + from smstools.models import dftModel as DFT from smstools.models import utilFunctions as UF diff --git a/smstools/models/sprModel.py b/smstools/models/sprModel.py index 38eb7572..fec54651 100644 --- a/smstools/models/sprModel.py +++ b/smstools/models/sprModel.py @@ -1,10 +1,12 @@ # functions that implement analysis and synthesis of sounds using the Sinusoidal plus Residual Model # (for example usage check the examples interface) +import math + import numpy as np -from scipy.signal.windows import blackmanharris, triang from scipy.fft import fft, ifft -import math +from scipy.signal.windows import blackmanharris, triang + from smstools.models import dftModel as DFT from smstools.models import sineModel as SM from smstools.models import utilFunctions as UF diff --git a/smstools/models/spsModel.py b/smstools/models/spsModel.py index 182ba223..d0f41183 100644 --- a/smstools/models/spsModel.py +++ b/smstools/models/spsModel.py @@ -1,15 +1,17 @@ # functions that implement analysis and synthesis of sounds using the Sinusoidal plus Stochastic Model # (for example usage check the interface directory) +import math + import numpy as np -from scipy.signal import resample -from scipy.signal.windows import blackmanharris, triang, hann from scipy.fft import fft, ifft -import math -from smstools.models import utilFunctions as UF +from scipy.signal import resample +from scipy.signal.windows import blackmanharris, hann, triang + from smstools.models import dftModel as DFT from smstools.models import sineModel as SM from smstools.models import stochasticModel as STM +from smstools.models import utilFunctions as UF def spsModelAnal( diff --git a/smstools/models/stft.py b/smstools/models/stft.py index 5de74bf6..409559ff 100644 --- a/smstools/models/stft.py +++ b/smstools/models/stft.py @@ -2,6 +2,7 @@ # (for example usage check stft_function.py in the interface directory) import numpy as np + from smstools.models import dftModel as DFT diff --git a/smstools/models/stochasticModel.py b/smstools/models/stochasticModel.py index 2972bd0e..d0540d8c 100644 --- a/smstools/models/stochasticModel.py +++ b/smstools/models/stochasticModel.py @@ -2,10 +2,11 @@ # (for example usage check stochasticModel_function.py in the interface directory) import numpy as np +from scipy.fft import fft, ifft +from scipy.interpolate import splev, splrep from scipy.signal import resample from scipy.signal.windows import hann -from scipy.interpolate import splrep, splev -from scipy.fft import fft, ifft + from smstools.models import utilFunctions as UF diff --git a/smstools/models/utilFunctions.py b/smstools/models/utilFunctions.py index 5693e128..c7e7aa7e 100644 --- a/smstools/models/utilFunctions.py +++ b/smstools/models/utilFunctions.py @@ -4,8 +4,8 @@ import sys import numpy as np -from scipy.fft import fft, ifft, fftshift -from scipy.io.wavfile import write, read +from scipy.fft import fft, fftshift, ifft +from scipy.io.wavfile import read, write from scipy.signal import resample from scipy.signal.windows import blackmanharris, triang diff --git a/smstools/models/utilFunctions_C/cutilFunctions.pyx b/smstools/models/utilFunctions_C/cutilFunctions.pyx index 85e3686e..06e3f5b8 100644 --- a/smstools/models/utilFunctions_C/cutilFunctions.pyx +++ b/smstools/models/utilFunctions_C/cutilFunctions.pyx @@ -1,9 +1,10 @@ #this is a cython wrapper on C functions to call them in python import numpy as np + cimport numpy as np -from libc.stdlib cimport * from cutilFunctions cimport * +from libc.stdlib cimport * np.import_array() diff --git a/smstools/transformations/stftTransformations.py b/smstools/transformations/stftTransformations.py index 8b649c3f..14a460ab 100644 --- a/smstools/transformations/stftTransformations.py +++ b/smstools/transformations/stftTransformations.py @@ -1,8 +1,12 @@ # functions that implement transformations using the stft +import math +import os +import sys + import numpy as np -import sys, os, math from scipy.signal import resample + from smstools.models import dftModel as DFT