From 01553e9977ce84b8fc1b41c96ca48536b25978bb Mon Sep 17 00:00:00 2001 From: Kyle Mandli Date: Sun, 2 Jun 2024 16:02:29 -0400 Subject: [PATCH 1/3] Add basic CI script --- .github/workflows/testing.yml | 55 +++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 .github/workflows/testing.yml diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml new file mode 100644 index 00000000..f0d5a565 --- /dev/null +++ b/.github/workflows/testing.yml @@ -0,0 +1,55 @@ +name: Test AMRClaw + +on: + push: + branches: [ "master" ] + pull_request: + branches: [ "master" ] + +permissions: + contents: read + +env: + CLAW: ${{ github.workspace }} + +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: Set up Python 3.10 + uses: actions/setup-python@v5 + with: + python-version: "3.10" + - name: Install dependencies + run: | + sudo apt-get update + sudo apt-get install gfortran + python -m pip install --upgrade pip + pip install flake8 meson-python ninja pytest numpy + # if [ -f requirements.txt ]; then pip install -r requirements.txt; fi + + - name: Checkout Clawpack + uses: actions/checkout@v4.1.5 + with: + repository: clawpack/clawpack + submodules: true + - name: Checkout AMRClaw branch + uses: actions/checkout@v4.1.5 + with: + path: amrclaw + + - name: Install clawpack + run: | + pip install --no-build-isolation --editable . + + - name: Lint with flake8 + run: | + cd ${CLAW}/amrclaw + # stop the build if there are Python syntax errors or undefined names + flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics + # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide + flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics + - name: Test with pytest + run: | + cd ${CLAW}/amrclaw + pytest From 5d100dae294e741b53732ef063a970e820b3e0b0 Mon Sep 17 00:00:00 2001 From: Kyle Mandli Date: Sun, 2 Jun 2024 16:03:27 -0400 Subject: [PATCH 2/3] Add *.data to gitignore --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index a06ab4f3..e8c08d49 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +.DS_Store *.pyc *.o *.mod @@ -8,6 +9,7 @@ xclaw xamr xgeoclaw *.html +*.data _output/ _plots/ *~ From 6d6dac1086d51a5d2c851d9a71721b3d556b1620 Mon Sep 17 00:00:00 2001 From: Kyle Mandli Date: Sun, 2 Jun 2024 16:11:31 -0400 Subject: [PATCH 3/3] Update some python code to remove errors Also excludes the dev directory from linting --- .github/workflows/testing.yml | 2 +- examples/acoustics_2d_adjoint/run_adjoint_flagging.py | 10 +++++----- src/python/amrclaw/data.py | 6 +++--- tests/advection_1d_example1/setplot.py | 2 +- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml index f0d5a565..78949e17 100644 --- a/.github/workflows/testing.yml +++ b/.github/workflows/testing.yml @@ -46,7 +46,7 @@ jobs: run: | cd ${CLAW}/amrclaw # stop the build if there are Python syntax errors or undefined names - flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics + flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics --exclude dev # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics - name: Test with pytest diff --git a/examples/acoustics_2d_adjoint/run_adjoint_flagging.py b/examples/acoustics_2d_adjoint/run_adjoint_flagging.py index c4c57856..fbdc0776 100644 --- a/examples/acoustics_2d_adjoint/run_adjoint_flagging.py +++ b/examples/acoustics_2d_adjoint/run_adjoint_flagging.py @@ -4,17 +4,17 @@ import os -currentdir = os.getcwd() -adjointdir = currentdir + '/adjoint' +current_dir = os.getcwd() +adjoint_dir = os.path.join(current_dir, "adjoint") # Running the adjoint problem -os.chdir(adjointdir) +os.chdir(adjoint_dir) os.system('make new') os.system('make .plots') # Running the forward problem -os.chdir(currentdir) +os.chdir(current_dir) os.system('make new') os.system('make .plots') -print 'Finished running example with adjoint refinement' \ No newline at end of file +print('Finished running example with adjoint refinement') \ No newline at end of file diff --git a/src/python/amrclaw/data.py b/src/python/amrclaw/data.py index 42276e11..89343832 100755 --- a/src/python/amrclaw/data.py +++ b/src/python/amrclaw/data.py @@ -228,7 +228,7 @@ def __init__(self, num_dim, region=None): self.convert_old_region(region) - def convert_old_region(region): + def convert_old_region(self, region): """ Take a list region = [minlevel, maxlevel, t1, t2, x1, x2, y1, y2] in the old style and convert to a new flagregion. @@ -266,10 +266,10 @@ def __init__(self,flagregions=None,num_dim=2): super(FlagRegionData,self).__init__() - if flagregions is None or not isinstance(regions,list): + if flagregions is None or not isinstance(flagregions,list): self.add_attribute('flagregions',[]) else: - self.add_attribute('flagregions',regions) + self.add_attribute('flagregions',flagregions) self.add_attribute('num_dim',num_dim) diff --git a/tests/advection_1d_example1/setplot.py b/tests/advection_1d_example1/setplot.py index 86c6f4b4..aa2701cb 100644 --- a/tests/advection_1d_example1/setplot.py +++ b/tests/advection_1d_example1/setplot.py @@ -11,7 +11,7 @@ from numpy import linspace probdata = ClawData() probdata.read('setprob.data', force=True) -print "Parameters: u = %g, beta = %g" % (probdata.u, probdata.beta) +print("Parameters: u = %g, beta = %g" % (probdata.u, probdata.beta)) def qtrue(x,t): """