From 502ed89688816d2fda34d6dd81aabd7ddd03988d Mon Sep 17 00:00:00 2001 From: Stef Smeets Date: Mon, 26 Aug 2024 10:27:57 +0200 Subject: [PATCH 1/2] Fix linting issues --- src/proteus/utils/logs.py | 2 -- start_proteus.py | 12 +++++++----- tools/GridPROTEUS.py | 12 ++++++------ tools/GridSummarise.py | 14 +++++++------- tools/RunOfflineChemistry.py | 6 ++++-- 5 files changed, 24 insertions(+), 22 deletions(-) diff --git a/src/proteus/utils/logs.py b/src/proteus/utils/logs.py index ebb9ab57..69937d7e 100644 --- a/src/proteus/utils/logs.py +++ b/src/proteus/utils/logs.py @@ -126,5 +126,3 @@ def GetLogfilePath(output_dir:str, j:int): raise Exception("Cannot create logfile - too many in output folder already") return os.path.join(output_dir, "proteus_%02d.log"%j) - - diff --git a/start_proteus.py b/start_proteus.py index 0bf9a467..7bac63f9 100755 --- a/start_proteus.py +++ b/start_proteus.py @@ -21,6 +21,7 @@ import proteus.utils.constants from proteus.atmos_clim import RunAtmosphere from proteus.atmos_clim.agni import DeallocAtmos +from proteus.atmos_clim.wrapper_atmosphere import atm from proteus.utils.constants import ( AU, L_sun, @@ -240,7 +241,8 @@ def main(): # Set volatile mass targets f solvevol_target = {} for e in element_list: - if e == 'O': continue + if e == 'O': + continue solvevol_target[e] = hf_row[e+"_kg_total"] # Download all basic data. @@ -488,11 +490,11 @@ def main(): log.info("Bulk escape rate: %.2e kg yr-1 = %.2e kg s-1" % (hf_row["esc_rate_total"] * secs_per_year, hf_row["esc_rate_total"])) # update elemental mass targets for e in element_list: - if e=='O': continue + if e=='O': + continue # store change, for statistics esc_m = esc_result[e+"_kg_total"] - esc_dm = esc_m - solvevol_target[e] # update total elemental inventory solvevol_target[e] = esc_m @@ -502,7 +504,6 @@ def main(): ############### / ESCAPE - ############### OUTGASSING PrintHalfSeparator() solvevol_inp = copy.deepcopy(OPTIONS) @@ -610,7 +611,8 @@ def main(): arr_p = np.array(hf_all["Phi_global"]) # Time samples - t1 = arr_t[lb1]; t2 = arr_t[lb2] + t1 = arr_t[lb1] + t2 = arr_t[lb2] # Flux samples flx_m = max(abs(arr_f[lb1]),abs(arr_f[lb2])) diff --git a/tools/GridPROTEUS.py b/tools/GridPROTEUS.py index fcf04400..937fc1da 100644 --- a/tools/GridPROTEUS.py +++ b/tools/GridPROTEUS.py @@ -18,7 +18,7 @@ import numpy as np PROTEUS_DIR=os.getenv('PROTEUS_DIR') -if PROTEUS_DIR == None: +if PROTEUS_DIR is None: raise Exception("Environment is not activated or is setup incorrectly") @@ -323,12 +323,12 @@ def run(self,num_threads:int,test_run:bool=False): hdl.write("# gp_index = %d \n" % i) # Write lines - for l in base_config: - if ('=' not in l): + for line in base_config: + if ('=' not in line): continue - l = l.split('#')[0] - key = l.split('=')[0].strip() + line = line.split('#')[0] + key = line.split('=')[0].strip() # Give priority to pgrid parameters if key in gp.keys(): @@ -336,7 +336,7 @@ def run(self,num_threads:int,test_run:bool=False): # Otherwise, use default value else: - hdl.write(str(l) + "\n") + hdl.write(str(line) + "\n") # Ensure data is written to disk hdl.flush() diff --git a/tools/GridSummarise.py b/tools/GridSummarise.py index 051c903d..5af8d9b7 100755 --- a/tools/GridSummarise.py +++ b/tools/GridSummarise.py @@ -15,7 +15,7 @@ def summarise(pgrid_dir:str, opts:list): if (not os.path.exists(pgrid_dir)) or (not os.path.isdir(pgrid_dir)): raise Exception("Invalid path '%s'" % pgrid_dir) - + # Find folders pgrid_dir = os.path.abspath(pgrid_dir) @@ -35,13 +35,13 @@ def summarise(pgrid_dir:str, opts:list): lines = hdl.readlines() status[i] = int(lines[0]) cmmnts[i] = str(lines[1]) - + # Statistics print("Statistics:") for i in range(-1,100): count = np.count_nonzero(status == i) if count == 0: - continue + continue if i == -1: comment = "Uncategorised" else: @@ -99,7 +99,7 @@ def summarise(pgrid_dir:str, opts:list): print("Invalid status category '%s'" % o) def print_help(): - + print("Command usage: GridSummarise.py [fold] (opt1) (opt2) (opt3) ...") print(" [fold] = path to Pgrid output folder, required") print(" [optN] = status categories to print, optional") @@ -116,12 +116,12 @@ def print_help(): if (len(sys.argv) == 2) and (sys.argv[1].strip().lower() == "help"): print_help() exit(0) - - # Grid folder + + # Grid folder fold = sys.argv[1] # Extra requested status categories - opts = [] + opts = [] if len(sys.argv) > 2: for o in sys.argv[2:]: opts.append(str(o)) diff --git a/tools/RunOfflineChemistry.py b/tools/RunOfflineChemistry.py index 79c3f27a..002f6b4c 100755 --- a/tools/RunOfflineChemistry.py +++ b/tools/RunOfflineChemistry.py @@ -13,6 +13,7 @@ import pathlib import shutil import subprocess +import sys import time from datetime import datetime @@ -24,8 +25,9 @@ from proteus.plot.cpl_offchem_species import plot_offchem_species from proteus.plot.cpl_offchem_time import plot_offchem_time from proteus.plot.cpl_offchem_year import plot_offchem_year -from proteus.utils.constants import AU_cm, R_sun_cm +from proteus.utils.constants import AU_cm, R_sun_cm, element_list from proteus.utils.coupler import ReadInitFile, SetDirectories +from proteus.utils.helper import find_nearest, mol_to_ele from proteus.utils.plot_offchem import offchem_read_year @@ -154,7 +156,7 @@ def run_once(logger:logging.Logger, year:int, screen_name:str, first_run:bool, d p_bot = np.max(pl) p_top = np.min(pl) - v_mx = dict() # Mixing ratios + v_mx = {} # Mixing ratios for i,g in enumerate(gases): val = float(x_gas[g][-1]) v_mx[g] = val From 982ac1b336e11360753c254678ce23362222790c Mon Sep 17 00:00:00 2001 From: Stef Smeets Date: Mon, 26 Aug 2024 13:28:57 +0200 Subject: [PATCH 2/2] Switch to better maintained pre-commit action --- .github/workflows/code-style.yaml | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/.github/workflows/code-style.yaml b/.github/workflows/code-style.yaml index 8efe9241..40e8f0af 100644 --- a/.github/workflows/code-style.yaml +++ b/.github/workflows/code-style.yaml @@ -20,6 +20,14 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - - uses: chartboost/ruff-action@v1 + + - name: Get changed files + id: changed-files + uses: tj-actions/changed-files@v45 + + - name: Run Pre-Commit + env: + ALL_CHANGED_FILES: ${{ steps.changed-files.outputs.all_changed_files }} + uses: pre-commit/action@v3.0.1 with: - changed-files: 'true' + extra_args: --files $ALL_CHANGED_FILES