Skip to content

Commit

Permalink
Merge pull request #106 from boutproject/fix-format-ci
Browse files Browse the repository at this point in the history
Fix formatting CI
  • Loading branch information
ZedThree authored Jul 30, 2024
2 parents f9ed3d1 + d4c009c commit 7992f64
Show file tree
Hide file tree
Showing 21 changed files with 84 additions and 136 deletions.
40 changes: 0 additions & 40 deletions .github/workflows/black-fix.yml

This file was deleted.

9 changes: 4 additions & 5 deletions .github/workflows/formatting.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
name: Formatting (black & isort)
on:
push:
branches: master
paths:
- '**.py'

Expand All @@ -27,12 +26,12 @@ jobs:
python --version
black --version
isort --version
- name: Run black
run: |
black boututils
- name: Run isort
run: |
isort boututils
isort src
- name: Run black
run: |
black src
- uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: "[skip ci] Apply black/isort changes"
14 changes: 7 additions & 7 deletions src/boutdata/__init__.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
""" Routines for exchanging data to/from BOUT++ """

from boutdata.collect import collect, attributes
from boutdata.collect import attributes, collect
from boututils.boutarray import BoutArray
from boututils.boutwarnings import alwayswarn
from boututils.run_wrapper import (
build_and_log,
determineNumberOfCPUs,
launch,
launch_safe,
shell,
shell_safe,
determineNumberOfCPUs,
build_and_log,
)


__all__ = [
"attributes",
"collect",
Expand All @@ -31,18 +30,19 @@
__name__ = "boutdata"

try:
from importlib.metadata import version, PackageNotFoundError
from importlib.metadata import PackageNotFoundError, version
except ModuleNotFoundError:
from importlib_metadata import version, PackageNotFoundError
from importlib_metadata import PackageNotFoundError, version
try:
# This gives the version if the boutdata package was installed
__version__ = version(__name__)
except PackageNotFoundError:
# This branch handles the case when boutdata is used from the git repo
try:
from setuptools_scm import get_version
from pathlib import Path

from setuptools_scm import get_version

path = Path(__file__).resolve()
__version__ = get_version(root="..", relative_to=path)
except (ModuleNotFoundError, LookupError):
Expand Down
4 changes: 2 additions & 2 deletions src/boutdata/collect.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import glob
import os
import sys
import glob

import numpy as np

from boututils.datafile import DataFile
from boututils.boutarray import BoutArray
from boututils.datafile import DataFile


def findVar(varname, varlist):
Expand Down
67 changes: 26 additions & 41 deletions src/boutdata/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,61 +4,44 @@
"""

from collections import OrderedDict
import copy
import glob
import io
import numpy
import os
import re
from collections import OrderedDict, UserDict
from multiprocessing import Pipe, Process, RawArray

from multiprocessing import Process, Pipe, RawArray
import numpy

# These are imported to be used by 'eval' in
# BoutOptions.evaluate_scalar() and BoutOptionsFile.evaluate().
# Change the names to match those used by C++/BOUT++
from numpy import abs as abs # noqa: F401
from numpy import arccos as acos # noqa: F401
from numpy import arccosh as acosh # noqa: F401
from numpy import arcsin as asin # noqa: F401
from numpy import arcsinh as asinh # noqa: F401
from numpy import arctan as atan # noqa: F401
from numpy import arctan2 as atan2 # noqa: F401
from numpy import arctanh as atanh # noqa: F401
from numpy import ceil, cos, cosh, exp, floor, log, log10, pi # noqa: F401
from numpy import power as pow # noqa: F401
from numpy import round, sin, sinh, sqrt, tan, tanh # noqa: F401

from boutdata.collect import (
collect,
create_cache,
findVar,
_check_fieldperp_attributes,
_collect_from_one_proc,
_get_grid_info,
collect,
create_cache,
findVar,
)
from boututils.boutarray import BoutArray
from boututils.boutwarnings import alwayswarn
from boututils.datafile import DataFile
from boututils.run_wrapper import determineNumberOfCPUs

# These are imported to be used by 'eval' in
# BoutOptions.evaluate_scalar() and BoutOptionsFile.evaluate().
# Change the names to match those used by C++/BOUT++
from numpy import ( # noqa: F401
pi,
sin,
cos,
tan,
arccos as acos,
arcsin as asin,
arctan as atan,
arctan2 as atan2,
sinh,
cosh,
tanh,
arcsinh as asinh,
arccosh as acosh,
arctanh as atanh,
exp,
log,
log10,
power as pow,
sqrt,
ceil,
floor,
round,
abs,
)


from collections import UserDict


class CaseInsensitiveDict(UserDict):
def __missing__(self, key):
Expand Down Expand Up @@ -1345,11 +1328,12 @@ def redistribute(self, npes, nxpe=None, mxg=2, myg=2, include_restarts=True):
redistribute the restart files also (default: True)
"""
from os import mkdir, path, rename

from boutdata.processor_rearrange import (
get_processor_layout,
create_processor_layout,
get_processor_layout,
)
from os import rename, path, mkdir

# use get_processor_layout to get nx, ny
old_processor_layout = get_processor_layout(
Expand Down Expand Up @@ -1490,9 +1474,10 @@ def redistribute(self, npes, nxpe=None, mxg=2, myg=2, include_restarts=True):

if include_restarts:
print("processing restarts")
from boutdata import restart
from glob import glob

from boutdata import restart

restart_prefix = "BOUT.restart"
restarts_list = glob(path.join(self._path, restart_prefix + "*"))

Expand Down
4 changes: 2 additions & 2 deletions src/boutdata/griddata.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
"""

from numpy import ndarray, zeros, concatenate, linspace, amin, amax
import numpy as np
import matplotlib.pyplot as plt
import numpy as np
from numpy import amax, amin, concatenate, linspace, ndarray, zeros

from boututils.datafile import DataFile

Expand Down
2 changes: 1 addition & 1 deletion src/boutdata/input.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"""

from numpy.fft import rfft
from numpy import ndarray
from numpy.fft import rfft


def transform3D(arr):
Expand Down
7 changes: 3 additions & 4 deletions src/boutdata/mayavi2.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import numpy as np
from numpy import cos, sin, pi

from enthought.tvtk.api import tvtk
from enthought.mayavi.scripts import mayavi2
from enthought.tvtk.api import tvtk
from numpy import cos, pi, sin


def aligned_points(grid, nz=1, period=1.0, maxshift=0.4):
Expand Down Expand Up @@ -74,8 +73,8 @@ def create_grid(grid, data, period=1):

@mayavi2.standalone
def view3d(sgrid):
from enthought.mayavi.modules.api import GridPlane, Outline
from enthought.mayavi.sources.vtk_data_source import VTKDataSource
from enthought.mayavi.modules.api import Outline, GridPlane

mayavi2.new_scene()
src = VTKDataSource(data=sgrid)
Expand Down
3 changes: 1 addition & 2 deletions src/boutdata/mms.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@
"""

from sympy import symbols, cos, sin, diff, sqrt, pi, simplify, trigsimp, integrate, Wild

from numpy import arange, zeros
from sympy import Wild, cos, diff, integrate, pi, simplify, sin, sqrt, symbols, trigsimp

# Constants
qe = 1.602e-19
Expand Down
3 changes: 2 additions & 1 deletion src/boutdata/pol_slice.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from boututils.datafile import DataFile
import numpy as np
from scipy.ndimage import map_coordinates

from boututils.datafile import DataFile


def pol_slice(var3d, gridfile, n=1, zangle=0.0, nyInterp=None):
"""Takes a 3D variable, and returns a 2D slice at fixed toroidal angle
Expand Down
2 changes: 1 addition & 1 deletion src/boutdata/processor_rearrange.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
"""

from math import sqrt
from collections import namedtuple
from math import sqrt

processor_layout_ = namedtuple(
"BOUT_processor_layout",
Expand Down
19 changes: 9 additions & 10 deletions src/boutdata/restart.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,22 @@
"""

import os
import glob

from boutdata.collect import collect, create_cache
from boututils.datafile import DataFile
from boututils.boutarray import BoutArray
from boutdata.processor_rearrange import get_processor_layout, create_processor_layout

import multiprocessing
from natsort import natsorted
import os

import numpy as np
from numpy import mean, zeros, arange
from natsort import natsorted
from numpy import arange, mean, zeros
from numpy.random import normal

from scipy.interpolate import interp1d

from boutdata import shiftz
from boutdata.collect import collect, create_cache
from boutdata.processor_rearrange import create_processor_layout, get_processor_layout
from boututils.boutarray import BoutArray
from boututils.datafile import DataFile

from . import griddata

try:
Expand Down
3 changes: 1 addition & 2 deletions src/boutdata/shiftz.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from numpy import ndarray, pi, cos, sin
from numpy import fft
from numpy import cos, fft, ndarray, pi, sin


def shiftz(var, zangle, zperiod=1.0):
Expand Down
16 changes: 9 additions & 7 deletions src/boutdata/squashoutput.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,15 +110,17 @@ def squashoutput(
is used.
"""
# use local imports to allow fast import for tab-completion
from boutdata.data import BoutOutputs
from boututils.datafile import DataFile
from boututils.boutarray import BoutArray
import numpy
import os
import gc
import tempfile
import shutil
import glob
import os
import shutil
import tempfile

import numpy

from boutdata.data import BoutOutputs
from boututils.boutarray import BoutArray
from boututils.datafile import DataFile

try:
# If we are using the netCDF4 module (the usual case) set caching to zero, since
Expand Down
3 changes: 2 additions & 1 deletion src/boutdata/tests/make_test_data.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from copy import copy
from netCDF4 import Dataset

import numpy as np
from netCDF4 import Dataset

field3d_t_list = ["field3d_t_1", "field3d_t_2"]
field3d_list = ["field3d_1", "field3d_2"]
Expand Down
5 changes: 3 additions & 2 deletions src/boutdata/tests/test_boutoptions.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from boutdata.data import BoutOptions
import textwrap

import pytest
import textwrap

from boutdata.data import BoutOptions


def test_getSection_nonexistent():
Expand Down
Loading

0 comments on commit 7992f64

Please sign in to comment.