diff --git a/.github/workflows/black-fix.yml b/.github/workflows/black-fix.yml new file mode 100644 index 0000000..0c082ae --- /dev/null +++ b/.github/workflows/black-fix.yml @@ -0,0 +1,39 @@ +name: linting + +on: [push, pull_request] + +defaults: + run: + shell: bash + +jobs: + black: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + with: + ref: ${{ github.head_ref }} + + - name: Install black + run: | + sudo apt update -y + sudo apt -y install python3-pip python3-setuptools python3-wheel + pip3 install black isort + + - name: Version + run: | + python3 --version + $HOME/.local/bin/black --version + $HOME/.local/bin/isort --version + + - name: Run black + run: | + pwd + ls + $HOME/.local/bin/black zoidberg + $HOME/.local/bin/isort zoidberg + + - uses: stefanzweifel/git-auto-commit-action@v4 + with: + commit_message: "[skip ci] Apply black/isort changes" diff --git a/.github/workflows/black.yml b/.github/workflows/black.yml deleted file mode 100644 index 9682996..0000000 --- a/.github/workflows/black.yml +++ /dev/null @@ -1,21 +0,0 @@ -# This workflow will lint the repo with black - -name: Python package - -on: - [push, pull_request] - -jobs: - black: - - runs-on: ubuntu-latest - if: always() - - steps: - - uses: actions/checkout@v2 - - name: Set up Python - uses: actions/setup-python@v1 - - name: Check formatting with black - run: | - pip install black - black --check . diff --git a/zoidberg/__init__.py b/zoidberg/__init__.py index 196ecd2..03b9b64 100644 --- a/zoidberg/__init__.py +++ b/zoidberg/__init__.py @@ -1,9 +1,6 @@ import zoidberg -from . import grid -from . import field -from . import fieldtracer -from . import plot +from . import field, fieldtracer, grid, plot from .zoidberg import make_maps, write_maps __all__ = [ diff --git a/zoidberg/field.py b/zoidberg/field.py index fbd0085..660d4c4 100644 --- a/zoidberg/field.py +++ b/zoidberg/field.py @@ -317,22 +317,8 @@ def Rfunc(self, x, z, phi): try: - from sympy import ( - Symbol, - atan2, - cos, - sin, - log, - pi, - sqrt, - lambdify, - Piecewise, - Sum, - gamma, - And, - factorial, - diff, - ) + from sympy import (And, Piecewise, Sum, Symbol, atan2, cos, diff, + factorial, gamma, lambdify, log, pi, sin, sqrt) class StraightStellarator(MagneticField): """A "rotating ellipse" stellarator without curvature @@ -1124,7 +1110,7 @@ def read_vmec_file(self, vmec_file, ntheta=None, nzeta=None): def __init__(self, vmec_file, ntheta=None, nzeta=None, nr=32, nz=32): # Only needed here - from scipy.interpolate import griddata, RegularGridInterpolator + from scipy.interpolate import RegularGridInterpolator, griddata self.read_vmec_file(vmec_file, ntheta, nzeta) @@ -1433,8 +1419,8 @@ def __init__( While the description are at: http://svvmec1.ipp-hgw.mpg.de:8080/vmecrest/v1/Coil_currents_1_AA_T_0011.pdf """ - from scipy.interpolate import RegularGridInterpolator import numpy as np + from scipy.interpolate import RegularGridInterpolator ## create 1D arrays of cylindrical coordinates r = np.linspace(x_range[0], x_range[-1], nx) @@ -1497,13 +1483,14 @@ def field_values(r, phi, z, configuration=0, plot_poincare=False): Contact brendan.shanahan@ipp.mpg.de for questions """ - from osa import Client import os.path - import xarray as xr import pickle - import matplotlib.pyplot as plt from time import sleep + import matplotlib.pyplot as plt + import xarray as xr + from osa import Client + tracer = Client("http://esb.ipp-hgw.mpg.de:8280/services/FieldLineProxy?wsdl") nx = r.shape[0] @@ -1684,10 +1671,11 @@ def plasma_field(r, phi, z, wout_file="wout.nc"): Contact brendan.shanahan@ipp.mpg.de for questions """ - from osa import Client import os.path import pickle + from osa import Client + cl = Client("http://esb.ipp-hgw.mpg.de:8280/services/Extender?wsdl") vmecURL = "http://svvmec1.ipp-hgw.mpg.de:8080/vmecrest/v1/w7x_ref_1/wout.nc" @@ -1826,8 +1814,8 @@ def __init__( phi_range=[0, 2 * np.pi], vmec_id="w7x_ref_171", ): - from scipy.interpolate import RegularGridInterpolator import numpy as np + from scipy.interpolate import RegularGridInterpolator ## create 1D arrays of cylindrical coordinates r = np.linspace(x_range[0], x_range[-1], nx) diff --git a/zoidberg/grid.py b/zoidberg/grid.py index 33948c1..4d23837 100644 --- a/zoidberg/grid.py +++ b/zoidberg/grid.py @@ -1,5 +1,3 @@ -from __future__ import division - import numpy as np # Import classes representing poloidal grids diff --git a/zoidberg/plot.py b/zoidberg/plot.py index 58b0c24..f517d69 100644 --- a/zoidberg/plot.py +++ b/zoidberg/plot.py @@ -1,8 +1,8 @@ -from . import fieldtracer +import warnings import numpy as np -import warnings +from . import fieldtracer try: import matplotlib.animation as anim diff --git a/zoidberg/poloidal_grid.py b/zoidberg/poloidal_grid.py index a4b4b67..3e94ac3 100644 --- a/zoidberg/poloidal_grid.py +++ b/zoidberg/poloidal_grid.py @@ -18,13 +18,13 @@ """ +import warnings + import numpy as np -from numpy import pi, linspace, zeros +from numpy import linspace, pi, zeros from scipy.interpolate import RectBivariateSpline from scipy.spatial import cKDTree as KDTree -import warnings - try: import matplotlib.pyplot as plt diff --git a/zoidberg/rzline.py b/zoidberg/rzline.py index 665d326..3dbad2b 100644 --- a/zoidberg/rzline.py +++ b/zoidberg/rzline.py @@ -3,13 +3,12 @@ """ -import numpy as np +import warnings -from numpy import pi, linspace, sqrt, cos, sin, append, argmin -from scipy.interpolate import splrep, splev, interp1d +import numpy as np +from numpy import append, argmin, cos, linspace, pi, sin, sqrt from scipy.integrate import cumtrapz - -import warnings +from scipy.interpolate import interp1d, splev, splrep try: import matplotlib.pyplot as plt @@ -518,7 +517,6 @@ def line_from_points(rarray, zarray, show=False): ############################################################################# # Define the magnetic field - # Length in y after which the coils return to their starting (R,Z) locations yperiod = 10.0 diff --git a/zoidberg/test_field.py b/zoidberg/test_field.py index 1c9cef3..4a19493 100644 --- a/zoidberg/test_field.py +++ b/zoidberg/test_field.py @@ -1,5 +1,6 @@ import numpy as np -from .field import Slab, CurvedSlab + +from .field import CurvedSlab, Slab def test_slab(): diff --git a/zoidberg/test_fieldtracer.py b/zoidberg/test_fieldtracer.py index 619fac5..745fb58 100644 --- a/zoidberg/test_fieldtracer.py +++ b/zoidberg/test_fieldtracer.py @@ -1,7 +1,6 @@ import numpy as np -from . import fieldtracer -from . import field +from . import field, fieldtracer def test_slab(): diff --git a/zoidberg/test_grid.py b/zoidberg/test_grid.py index 68332ef..c5d94f5 100644 --- a/zoidberg/test_grid.py +++ b/zoidberg/test_grid.py @@ -1,6 +1,7 @@ -from .grid import rectangular_grid import numpy as np +from .grid import rectangular_grid + def test_getPoloidalGrid(): # Create a simple non-periodic grid diff --git a/zoidberg/test_poloidal_grid.py b/zoidberg/test_poloidal_grid.py index 39ffc4c..c01ffd3 100644 --- a/zoidberg/test_poloidal_grid.py +++ b/zoidberg/test_poloidal_grid.py @@ -1,7 +1,6 @@ import numpy as np -from . import rzline -from . import poloidal_grid +from . import poloidal_grid, rzline def test_out_of_domain(): diff --git a/zoidberg/test_rzline.py b/zoidberg/test_rzline.py index 687758f..c483110 100644 --- a/zoidberg/test_rzline.py +++ b/zoidberg/test_rzline.py @@ -1,7 +1,7 @@ -from . import rzline - import numpy as np +from . import rzline + def test_circular_boundaries(): inner = rzline.circle(R0=1.0, r=1.0, n=20) @@ -37,7 +37,6 @@ def test_distance(): def test_order_by_distance(): # Check the RZline.equallySpaced function inner = rzline.circle(R0=1.0, r=1.0, n=20) - outer = rzline.circle(R0=1.0, r=2.0, n=20) new_inner = inner.equallySpaced(n=10) diff --git a/zoidberg/test_zoidberg.py b/zoidberg/test_zoidberg.py index a4382e3..b818915 100644 --- a/zoidberg/test_zoidberg.py +++ b/zoidberg/test_zoidberg.py @@ -1,6 +1,8 @@ from itertools import chain, product + import numpy as np -from . import zoidberg, grid, field + +from . import field, grid, zoidberg def test_make_maps_slab(): diff --git a/zoidberg/zoidberg.py b/zoidberg/zoidberg.py index 18ee273..98a504f 100644 --- a/zoidberg/zoidberg.py +++ b/zoidberg/zoidberg.py @@ -1,9 +1,8 @@ -from __future__ import division +from collections import namedtuple +from itertools import chain import numpy as np from boututils import datafile as bdata -from collections import namedtuple -from itertools import chain from . import fieldtracer from .progress import update_progress @@ -483,8 +482,8 @@ def upscale(field, maps, upscale_factor=4, quiet=True): """ - from scipy.ndimage.interpolation import map_coordinates from scipy.interpolate import griddata + from scipy.ndimage.interpolation import map_coordinates xt_prime = maps["forward_xt_prime"] zt_prime = maps["forward_zt_prime"]