Skip to content

Commit

Permalink
eliminate tabs and trailing whitespace (#429)
Browse files Browse the repository at this point in the history
+ setup a github action
  • Loading branch information
zingale authored Mar 26, 2024
1 parent 00e688e commit 513d27e
Show file tree
Hide file tree
Showing 48 changed files with 395 additions and 300 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/create_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ on:
push:
# Sequence of patterns matched against refs/tags
tags:
- '[0-9][0-9].[0-9][0-9]'
- '[0-9][0-9].[0-9][0-9]'

name: Create Release

jobs:
Expand Down
22 changes: 22 additions & 0 deletions .github/workflows/style.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Style

on: [push, pull_request]

concurrency:
group: ${{ github.ref }}-${{ github.head_ref }}-style
cancel-in-progress: true

jobs:
tabs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Tabs
run: .github/workflows/style/check_tabs.sh

trailing_whitespaces:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Trailing Whitespaces
run: .github/workflows/style/check_trailing_whitespaces.sh
36 changes: 36 additions & 0 deletions .github/workflows/style/check_tabs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/usr/bin/env bash

set -eu -o pipefail

find . -type d \( -name .git \
-o -path ./paper \
-o -name build -o -name install \
-o -name tmp_build_dir -o -name tmp_install_dir \
\) -prune -o \
-type f \( \( -name "*.H" -o -name "*.h" -o -name "*.hh" -o -name "*.hpp" \
-o -name "*.c" -o -name "*.cc" -o -name "*.cpp" -o -name "*.cxx" \
-o -name "*.f" -o -name "*.F" -o -name "*.f90" -o -name "*.F90" \
-o -name "*.py" \
-o -name "*.md" -o -name "*.rst" \
-o -name "*.sh" \
-o -name "*.tex" \
-o -name "*.txt" \
-o -name "*.yml" \) \
-a \( ! -name "*.tab.h" -a ! -name "*.tab.nolint.H" \
-a ! -name "*.lex.h" -a ! -name "*.lex.nolint.H" \) \
\) \
-exec grep -Iq . {} \; \
-exec sed -i 's/\t/\ \ \ \ /g' {} +

gitdiff=`git diff`

if [ -z "$gitdiff" ]
then
exit 0
else
echo -e "\nTabs are not allowed. Changes suggested by"
echo -e " ${0}\n"
git --no-pager diff
echo ""
exit 1
fi
38 changes: 38 additions & 0 deletions .github/workflows/style/check_trailing_whitespaces.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/usr/bin/env bash

set -eu -o pipefail

find . -type d \( -name .git \
-o -path ./paper \
-o -name build -o -name install \
-o -name tmp_build_dir -o -name tmp_install_dir \
-o -path ./util/gcem \
\) -prune -o \
-type f \( \( -name "*.H" -o -name "*.h" -o -name "*.hh" -o -name "*.hpp" \
-o -name "*.c" -o -name "*.cc" -o -name "*.cpp" -o -name "*.cxx" \
-o -name "*.f" -o -name "*.F" -o -name "*.f90" -o -name "*.F90" \
-o -name "*.py" \
-o -name "*.rst" \
-o -name "*.sh" \
-o -name "*.tex" \
-o -name "*.txt" \
-o -name "*.yml" \) \
-a \( ! -name "*.tab.h" -a ! -name "*.tab.nolint.H" \
-a ! -name "*.lex.h" -a ! -name "*.lex.nolint.H" \
-a ! -path "./networks/*/reaclib_rates.H" \) \
\) \
-exec grep -Iq . {} \; \
-exec sed -i 's/[[:blank:]]\+$//g' {} +

gitdiff=`git diff`

if [ -z "$gitdiff" ]
then
exit 0
else
echo -e "\nTrailing whitespaces at the end of a line are not allowed. Changes suggested by"
echo -e " ${0}\n"
git --no-pager diff
echo ""
exit 1
fi
9 changes: 4 additions & 5 deletions Exec/science/code_comp/analysis/image_animator.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def image_animator(args):

# Sort if necessary
if args.sort is not None:

# Descending or ascending
desc = args.sort < 0
# Starting index
Expand All @@ -43,21 +43,21 @@ def image_animator(args):
else:
key = lambda filename: filename[start:start+nchars]
images.sort(key=key, reverse=desc)

if args.out.endswith(".mp4"):
args.out = args.out[:-4]
if not args.out:
sys.exit("Invalid output file!")

with tf.TemporaryDirectory() as dir:

# The files are numbered
# Padding with zeros preserves sort order
ndigits = len(str(len(images)))
baselink = "__fftemp_{:0%dd}.png" % ndigits

for i, image in enumerate(map(os.path.abspath, images)):

# Create a symlink for each file
linkname = baselink.format(i)
linkname = os.path.join(dir, linkname)
Expand All @@ -75,4 +75,3 @@ def image_animator(args):
args = parse_args()

image_animator(args)

32 changes: 16 additions & 16 deletions Exec/science/code_comp/analysis/plot_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,14 @@ def plot_generator(args):
def get_width(ds, xlim=None, ylim=None, zlim=None):
""" Get the width of the plot. """

if xlim is None:
if xlim is None:
xlim = ds.domain_left_edge[0], ds.domain_right_edge[0]
else:
else:
xlim = xlim[0] * cm, xlim[1] * cm

if ylim is None:
if ylim is None:
ylim = ds.domain_left_edge[1], ds.domain_right_edge[1]
else:
else:
ylim = ylim[0] * cm, ylim[1] * cm

xwidth = (xlim[1] - xlim[0]).in_cgs()
Expand All @@ -116,9 +116,9 @@ def get_width(ds, xlim=None, ylim=None, zlim=None):
if ds.domain_dimensions[2] == 1:
zwidth = 0.0
else:
if zlim is None:
if zlim is None:
zlim = ds.domain_left_edge[2], ds.domain_right_edge[2]
else:
else:
zlim = zlim[0] * cm, zlim[1] * cm

zwidth = (zlim[1] - zlim[0]).in_cgs()
Expand All @@ -128,14 +128,14 @@ def get_width(ds, xlim=None, ylim=None, zlim=None):
def get_center(ds, xlim=None, ylim=None, zlim=None):
""" Get the coordinates of the center of the plot. """

if xlim is None:
if xlim is None:
xlim = ds.domain_left_edge[0], ds.domain_right_edge[0]
else:
else:
xlim = xlim[0] * cm, xlim[1] * cm

if ylim is None:
if ylim is None:
ylim = ds.domain_left_edge[1], ds.domain_right_edge[1]
else:
else:
ylim = ylim[0] * cm, ylim[1] * cm

xctr = 0.5 * (xlim[0] + xlim[1])
Expand All @@ -144,9 +144,9 @@ def get_center(ds, xlim=None, ylim=None, zlim=None):
if ds.domain_dimensions[2] == 1:
zctr = 0.0
else:
if zlim is None:
if zlim is None:
zlim = ds.domain_left_edge[2], ds.domain_right_edge[2]
else:
else:
zlim = zlim[0] * cm, zlim[1] * cm

zctr = 0.5 * (zlim[0] + zlim[1])
Expand All @@ -157,14 +157,14 @@ def get_center(ds, xlim=None, ylim=None, zlim=None):

# Loop and generate
for ds in ts:

settings = {}
settings['center'] = get_center(ds, args.xlim, args.ylim, args.zlim)
settings['width'] = get_width(ds, args.xlim, args.ylim, args.zlim)
settings['normal'] = args.normal

plot = func(ds, fields=field, **settings)
if args.cmap:
if args.cmap:
plot.set_cmap(field=field, cmap=args.cmap)

if args.linthresh:
Expand All @@ -180,9 +180,9 @@ def get_center(ds, xlim=None, ylim=None, zlim=None):
plot.set_zlim(field, *args.bounds)

if args.time:

time_format = f't = {{time:.{args.time}f}}{{units}}'

plot.annotate_timestamp(corner='upper_left', time_format=time_format,
time_unit='s', draw_inset_box=True, inset_box_args={'alpha': 0.0})

Expand Down
14 changes: 7 additions & 7 deletions Exec/science/ecsn/analysis/vol-ecsn-enuc.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def doit(plotfile):

field = ('boxlib', 'Hnuc')
ds._get_field_info(field).take_log = True

sc = Scene()


Expand Down Expand Up @@ -55,10 +55,10 @@ def doit(plotfile):

sc.get_source(0).transfer_function = tf

cam = sc.add_camera(ds, lens_type="perspective")
cam = sc.add_camera(ds, lens_type="perspective")
cam.resolution = (1080, 1080)
cam.position = 1.0*ds.domain_right_edge

# look toward the center -- we are dealing with an octant
center = ds.domain_left_edge
normal = (center - cam.position)
Expand All @@ -75,11 +75,11 @@ def doit(plotfile):

sc.render()
sc.save("{}_Hnuc".format(plotfile), sigma_clip=4.0)
sc.save_annotated("{}_Hnuc_annotated.png".format(plotfile),
text_annotate=[[(0.05, 0.05),
sc.save_annotated("{}_Hnuc_annotated.png".format(plotfile),
text_annotate=[[(0.05, 0.05),
"t = {}".format(ds.current_time.d),
dict(horizontalalignment="left")],
[(0.5,0.95),
[(0.5,0.95),
"MAESTROeX simulation of ECSN convection",
dict(color="y", fontsize="24",
horizontalalignment="center")]])
Expand All @@ -96,4 +96,4 @@ def doit(plotfile):
doit(plotfile)



14 changes: 7 additions & 7 deletions Exec/science/ecsn/analysis/vol-ecsn-radvel.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def doit(plotfile):

field = ('boxlib', 'radial_velocity')
ds._get_field_info(field).take_log = False

sc = Scene()


Expand All @@ -50,10 +50,10 @@ def doit(plotfile):

sc.get_source(0).transfer_function = tf

cam = sc.add_camera(ds, lens_type="perspective")
cam = sc.add_camera(ds, lens_type="perspective")
cam.resolution = (1080, 1080)
cam.position = 1.0*ds.domain_right_edge

# look toward the center -- we are dealing with an octant
center = ds.domain_left_edge
normal = (center - cam.position)
Expand All @@ -70,11 +70,11 @@ def doit(plotfile):

sc.render()
sc.save("{}_radvel".format(plotfile), sigma_clip=4.0)
# sc.save_annotated("{}_radvel_annotated.png".format(plotfile),
# text_annotate=[[(0.05, 0.05),
# sc.save_annotated("{}_radvel_annotated.png".format(plotfile),
# text_annotate=[[(0.05, 0.05),
# "t = {}".format(ds.current_time.d),
# dict(horizontalalignment="left")],
# [(0.5,0.95),
# [(0.5,0.95),
# "Maestro simulation of He convection on a white dwarf",
# dict(color="y", fontsize="24",
# horizontalalignment="center")]])
Expand All @@ -91,4 +91,4 @@ def doit(plotfile):
doit(plotfile)



4 changes: 2 additions & 2 deletions Exec/science/urca/MaestroInitData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ void Maestro::InitLevelDataSphr(const int lev, const Real time, MultiFab& scal,

Put1dArrayOnCart(lev, temp_vec, temp_mf, 0, 0, bcs_f, 0);
MultiFab::Copy(scal, temp_mf, 0, Temp, 1, 0);

// initialize density
for (auto l = 0; l <= base_geom.max_radial_level; ++l) {
for (auto r = 0; r < base_geom.nr(l); ++r) {
Expand Down Expand Up @@ -166,7 +166,7 @@ void Maestro::InitLevelDataSphr(const int lev, const Real time, MultiFab& scal,
scal_arr(i, j, k, Temp) = eos_state.T;
});


const auto prob_lo = geom[lev].ProbLoArray();
const auto prob_hi = geom[lev].ProbHiArray();
const auto dx = geom[lev].CellSizeArray();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

class PhysicalConstants:
N_AVO = 6.02214129e23

class DatasetHelpers:
@staticmethod
def get_field(ds, field_name):
Expand Down Expand Up @@ -79,7 +79,7 @@ def setup(self, ds):
except yt.utilities.exceptions.YTFieldNotFound:
print('WARNING: enucdot_dqweak_urca23 could not be added because it relies on a field not in the dataset.')
pass

try:
ds.add_field(('boxlib','enucloss_sneut'), sampling_type='cell', units='g',
function=UrcaShellFields._enucloss_sneut)
Expand Down Expand Up @@ -128,7 +128,7 @@ def setup(self, ds):
except yt.utilities.exceptions.YTFieldNotFound:
print('WARNING: xc12_complement could not be added because it relies on a field not in the dataset.')
pass

@staticmethod
def _urca23_shell_unscaled(field, data):
return data['boxlib','ecap23']*data['boxlib','beta23']*data['boxlib','X(na23)']*data['boxlib','X(ne23)']
Expand Down
Loading

0 comments on commit 513d27e

Please sign in to comment.