From ab5f390b173ddd19bb06111b6fe9fac35eed0c17 Mon Sep 17 00:00:00 2001 From: Malik Date: Sat, 19 Sep 2026 16:30:55 -0600 Subject: [PATCH 1/9] use __all__ to silence pyflakes --- bird/__init__.py | 4 ++++ bird/postprocess/post_quantities/__init__.py | 9 +++++++++ bird/utilities/ofio/__init__.py | 11 +++++++++++ 3 files changed, 24 insertions(+) diff --git a/bird/__init__.py b/bird/__init__.py index 34a58352..427d64fb 100644 --- a/bird/__init__.py +++ b/bird/__init__.py @@ -4,6 +4,10 @@ from bird.version import __version__ +# Marks __version__ as an intentional re-export (read by setuptools as +# bird.__version__); does not restrict attribute access to the module. +__all__ = ["__version__"] + BIRD_DIR = os.path.dirname(os.path.realpath(__file__)) BIRD_CASE_DIR = os.path.join(BIRD_DIR, "../tutorial_cases") BIRD_CONST_DIR = os.path.join(BIRD_DIR, "constants") diff --git a/bird/postprocess/post_quantities/__init__.py b/bird/postprocess/post_quantities/__init__.py index 7e8be921..e3ba0105 100644 --- a/bird/postprocess/post_quantities/__init__.py +++ b/bird/postprocess/post_quantities/__init__.py @@ -61,3 +61,12 @@ "sherwood", "weber", ] + +# Private cell-selection helpers re-exported for the test suite (imported by tests/). +__all__ += [ + "_field_filter", + "_get_ind_gas", + "_get_ind_liq", + "_get_ind_slice", + "_weighted_average", +] diff --git a/bird/utilities/ofio/__init__.py b/bird/utilities/ofio/__init__.py index 66618409..c5132d9f 100644 --- a/bird/utilities/ofio/__init__.py +++ b/bird/utilities/ofio/__init__.py @@ -50,3 +50,14 @@ "species_name_to_mw", "write_openfoam_dict", ] + +# Helpers +__all__ += [ + "_find_header_size", + "_get_mesh_time", + "_get_volume_time", + "_read_mesh", + "_readOF", + "_readOFScal", + "_readOFVec", +] From 011fdd426cd9bd342bc22bc1bc60f768225c7c23 Mon Sep 17 00:00:00 2001 From: Malik Date: Sat, 19 Sep 2026 16:31:22 -0600 Subject: [PATCH 2/9] accomodate vim syntax coloring --- tests/io/test_read_foam_fields.py | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/tests/io/test_read_foam_fields.py b/tests/io/test_read_foam_fields.py index 70bc3ccf..ef00bd62 100644 --- a/tests/io/test_read_foam_fields.py +++ b/tests/io/test_read_foam_fields.py @@ -23,8 +23,8 @@ def test_read_nonunif_scal(): """ case_folder = os.path.join( Path(__file__).parent, - "..", - "..", + " .. ".strip(), + " .. ".strip(), "bird", "postprocess", "data_conditional_mean", @@ -53,8 +53,8 @@ def test_read_unif_scal(): """ case_folder = os.path.join( Path(__file__).parent, - "..", - "..", + " .. ".strip(), + " .. ".strip(), "bird", "postprocess", "data_conditional_mean", @@ -83,8 +83,8 @@ def test_read_nonunif_vec(): """ case_folder = os.path.join( Path(__file__).parent, - "..", - "..", + " .. ".strip(), + " .. ".strip(), "bird", "postprocess", "data_conditional_mean", @@ -131,8 +131,8 @@ def test_find_header_size(): """ case_folder = os.path.join( Path(__file__).parent, - "..", - "..", + " .. ".strip(), + " .. ".strip(), "bird", "postprocess", "data_conditional_mean", @@ -164,8 +164,8 @@ def test_read_unif_vec(): """ case_folder = os.path.join( Path(__file__).parent, - "..", - "..", + " .. ".strip(), + " .. ".strip(), "bird", "postprocess", "data_conditional_mean", @@ -184,8 +184,8 @@ def test_read_bubble_diameter(): """ case_folder = os.path.join( Path(__file__).parent, - "..", - "..", + " .. ".strip(), + " .. ".strip(), "bird", "postprocess", "data_conditional_mean", @@ -228,8 +228,8 @@ def test_read_mu_liquid(): """ case_folder = os.path.join( Path(__file__).parent, - "..", - "..", + " .. ".strip(), + " .. ".strip(), "bird", "postprocess", "data_conditional_mean", From b32b38756140f98e85fa4a4805fbb0ae8a9d497f Mon Sep 17 00:00:00 2001 From: Malik Date: Sat, 19 Sep 2026 16:34:20 -0600 Subject: [PATCH 3/9] remove rogue f strings --- bird/postprocess/kla_utils.py | 2 +- bird/preprocess/dynamic_mixer/io_fvModels.py | 14 +++++++------- bird/preprocess/json_gen/generate_designs.py | 18 +++++++++--------- bird/utilities/ofio/thermo.py | 2 +- 4 files changed, 18 insertions(+), 18 deletions(-) diff --git a/bird/postprocess/kla_utils.py b/bird/postprocess/kla_utils.py index eca199ac..76d688c4 100644 --- a/bird/postprocess/kla_utils.py +++ b/bird/postprocess/kla_utils.py @@ -367,6 +367,6 @@ def print_res_dict(res_dict: dict) -> None: if bs: logger.info(f"\tkla = {kla*3600:.4g} +/- {kla_err*3600:.4g} [h-1]") logger.info(f"\tcstar = {cs:.4g} +/- {cs_err:.4g} [mol/m3]") - logger.info(f"Without data bootstrap") + logger.info("Without data bootstrap") logger.info(f"\tkla = {kla_nb*3600:.4g} +/- {kla_err_nb*3600:.4g} [h-1]") logger.info(f"\tcstar = {cs_nb:.4g} +/- {cs_err_nb:.4g} [mol/m3]") diff --git a/bird/preprocess/dynamic_mixer/io_fvModels.py b/bird/preprocess/dynamic_mixer/io_fvModels.py index b78fb49c..4a7a1ebc 100644 --- a/bird/preprocess/dynamic_mixer/io_fvModels.py +++ b/bird/preprocess/dynamic_mixer/io_fvModels.py @@ -42,14 +42,14 @@ def write_preamble(output_folder): f.write("\t\tconst volVectorField& UL =\n") f.write('\t\t\tmesh().lookupObject("U.liquid");\n') f.write("\t\tdouble pi=3.141592654;\n") - f.write(f"\t\tdouble source_pt_x;\n") - f.write(f"\t\tdouble source_pt_y;\n") - f.write(f"\t\tdouble source_pt_z;\n") - f.write(f"\t\tdouble disk_rad;\n") + f.write("\t\tdouble source_pt_x;\n") + f.write("\t\tdouble source_pt_y;\n") + f.write("\t\tdouble source_pt_z;\n") + f.write("\t\tdouble disk_rad;\n") f.write("\t\tdouble disk_area;\n") - f.write(f"\t\tdouble power;\n") - f.write(f"\t\tdouble smear_factor;\n") - f.write(f"\t\tdouble startTime;\n") + f.write("\t\tdouble power;\n") + f.write("\t\tdouble smear_factor;\n") + f.write("\t\tdouble startTime;\n") def write_mixer(mixer, output_folder): diff --git a/bird/preprocess/json_gen/generate_designs.py b/bird/preprocess/json_gen/generate_designs.py index f05b1040..3c35219e 100644 --- a/bird/preprocess/json_gen/generate_designs.py +++ b/bird/preprocess/json_gen/generate_designs.py @@ -152,8 +152,8 @@ def write_script_start(filename, n): for i in range(n): sim_folder = id2simfolder(i) f.write(f"cd {sim_folder}\n") - f.write(f"sbatch script\n") - f.write(f"cd ..\n") + f.write("sbatch script\n") + f.write("cd ..\n") def write_script_post(filename, n): @@ -161,20 +161,20 @@ def write_script_post(filename, n): for i in range(n): sim_folder = id2simfolder(i) f.write(f"cd {sim_folder}\n") - f.write(f"sbatch script_post\n") - f.write(f"cd ..\n") + f.write("sbatch script_post\n") + f.write("cd ..\n") def write_prep(filename, n): with open(filename, "w+") as f: f.write("prep () {\n") - f.write(f"\tcd $1\n") - f.write(f"\treconstructPar -newTimes\n") - f.write(f"\tcd ..\n") + f.write("\tcd $1\n") + f.write("\treconstructPar -newTimes\n") + f.write("\tcd ..\n") f.write("}\n") - f.write(f"\n") + f.write("\n") f.write( - f"source /projects/gas2fuels/ofoam_cray_mpich/OpenFOAM-dev/etc/bashrc\n" + "source /projects/gas2fuels/ofoam_cray_mpich/OpenFOAM-dev/etc/bashrc\n" ) for i in range(n): sim_folder = id2simfolder(i) diff --git a/bird/utilities/ofio/thermo.py b/bird/utilities/ofio/thermo.py index 4676b91a..1cf38bb5 100644 --- a/bird/utilities/ofio/thermo.py +++ b/bird/utilities/ofio/thermo.py @@ -163,7 +163,7 @@ def read_mu_liquid( mu_liq = globalVars["muMixLiq"] if mu_liq is None: logger.error( - f"Liquid viscosity is not constant, yet could not find thermo:mu.liquid" + "Liquid viscosity is not constant, yet could not find thermo:mu.liquid" ) raise FileNotFoundError(err) else: From 773bb6901bc21a03f18b9b9258d09b6c2d7fc76f Mon Sep 17 00:00:00 2001 From: Malik Date: Sat, 19 Sep 2026 16:44:46 -0600 Subject: [PATCH 4/9] remove unused variables --- bird/postprocess/conditional_mean.py | 2 -- bird/postprocess/early_pred.py | 4 ++-- bird/postprocess/kla_utils.py | 3 +-- bird/preprocess/stl_patch/stl_shapes.py | 1 - bird/utilities/ofio/foam_field_io.py | 1 - bird/utilities/ofio/global_vars.py | 4 ++-- 6 files changed, 5 insertions(+), 10 deletions(-) diff --git a/bird/postprocess/conditional_mean.py b/bird/postprocess/conditional_mean.py index 6ba04b65..01e493e5 100644 --- a/bird/postprocess/conditional_mean.py +++ b/bird/postprocess/conditional_mean.py @@ -20,7 +20,6 @@ def compute_cond_mean( ): time_float_sorted, time_str_sorted = get_case_times(case_folder) cell_centers, _ = read_cell_centers(case_folder) - nCells = len(cell_centers) assert len(diff_val_list) == len(diff_name_list) window_ave = min(window_ave, len(time_str_sorted)) @@ -40,7 +39,6 @@ def compute_cond_mean( ) for filename, name in zip(field_file, field_name_list): - val_dict = {} field_tmp, _ = read_field( case_folder, time_folder, field_name=field_name ) diff --git a/bird/postprocess/early_pred.py b/bird/postprocess/early_pred.py index 3ae7f84c..c96006f4 100644 --- a/bird/postprocess/early_pred.py +++ b/bird/postprocess/early_pred.py @@ -24,7 +24,7 @@ def plotAllEarly(data_dict, color_files=None, chop=False, extrap=False): - fig = plt.figure() + plt.figure() for idat, datf in enumerate(data_dict): if color_files is not None: color = color_files[idat] @@ -56,7 +56,7 @@ def plotAllEarly(data_dict, color_files=None, chop=False, extrap=False): def plotAllEarly_uq(data_dict, color_files=None): - fig = plt.figure() + plt.figure() for idat, datf in enumerate(data_dict): color = color_files[idat] text = data_dict[datf]["textrap"] diff --git a/bird/postprocess/kla_utils.py b/bird/postprocess/kla_utils.py index 76d688c4..97753de0 100644 --- a/bird/postprocess/kla_utils.py +++ b/bird/postprocess/kla_utils.py @@ -302,7 +302,6 @@ def post_cal( """ np_hmc_samples = hmc_samples_2_np_samples(hmc_samples) labels_np = ["cstar", "kla", "sigma"] - nsamples = np_hmc_samples.shape[0] labels = list(hmc_samples.keys()) nparams = len(labels) @@ -322,7 +321,7 @@ def post_cal( p10_real = pred_dict["p10_pred"] p90_real = pred_dict["p90_pred"] - fig = plt.figure() + plt.figure() plt.plot( time_obs, mean_real, color="k", linewidth=3, label="mean predictions" ) diff --git a/bird/preprocess/stl_patch/stl_shapes.py b/bird/preprocess/stl_patch/stl_shapes.py index c85b41a3..0197d9d7 100644 --- a/bird/preprocess/stl_patch/stl_shapes.py +++ b/bird/preprocess/stl_patch/stl_shapes.py @@ -65,7 +65,6 @@ def make_circle(radius, center, normal_dir, npts=3): def make_spider(centerRad, nArms, widthArms, lengthArms, center, normal_dir): - globalArea = 0 if nArms < 2: error_msg = f"nArms ({nArms}) must be >= 2" logger.error(error_msg) diff --git a/bird/utilities/ofio/foam_field_io.py b/bird/utilities/ofio/foam_field_io.py index 67e84f81..c900233f 100644 --- a/bird/utilities/ofio/foam_field_io.py +++ b/bird/utilities/ofio/foam_field_io.py @@ -142,7 +142,6 @@ def _read_meta_data(filename: str, mode: str | None = None) -> dict: sline = line.split() for ientry, entry in enumerate(sline): if ";" in entry: - ind_end = ientry break line_cropped = " ".join(sline[2 : ientry + 1]) unif_value = _ofvec2arr(line_cropped.strip(";")) diff --git a/bird/utilities/ofio/global_vars.py b/bird/utilities/ofio/global_vars.py index eb3fdfc4..3bb5e99c 100644 --- a/bird/utilities/ofio/global_vars.py +++ b/bird/utilities/ofio/global_vars.py @@ -94,7 +94,7 @@ def repl(match): # result = int(result) cross_referenced_globalVars_dict[key] = result - except Exception as e: + except Exception: logger.warning( f"Could not evaluate globalVars expression for {key}: {expr}" ) @@ -124,7 +124,7 @@ def repl_direct(match): # if result.is_integer(): # result = int(result) cross_referenced_globalVars_dict[key] = result - except Exception as e: + except Exception: logger.warning( f"Could not evaluate globalVars expression for {key}: {expr}" ) From c8042186e49f60bb6c0fd50f3d6d8871016163f1 Mon Sep 17 00:00:00 2001 From: Malik Date: Sat, 19 Sep 2026 16:56:42 -0600 Subject: [PATCH 5/9] conditional mean field was not updated --- bird/postprocess/conditional_mean.py | 3 +-- tests/postprocess/test_cond_mean.py | 6 +++--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/bird/postprocess/conditional_mean.py b/bird/postprocess/conditional_mean.py index 01e493e5..5b17da17 100644 --- a/bird/postprocess/conditional_mean.py +++ b/bird/postprocess/conditional_mean.py @@ -37,10 +37,9 @@ def compute_cond_mean( field_file.append( os.path.join(case_folder, time_folder, field_name) ) - for filename, name in zip(field_file, field_name_list): field_tmp, _ = read_field( - case_folder, time_folder, field_name=field_name + case_folder, time_folder, field_name=name ) vert_axis, field_cond_tmp = conditional_average( cell_centers[:, vert_ind], field_tmp, nbins=n_bins diff --git a/tests/postprocess/test_cond_mean.py b/tests/postprocess/test_cond_mean.py index bc3218d9..9d166ef5 100644 --- a/tests/postprocess/test_cond_mean.py +++ b/tests/postprocess/test_cond_mean.py @@ -14,8 +14,8 @@ def test_compute_cond(): case_folder = os.path.join( Path(__file__).parent, - "..", - "..", + " .. ".strip(), + " .. ".strip(), "bird", "postprocess", "data_conditional_mean", @@ -31,7 +31,7 @@ def test_compute_cond(): "d.gas", ] fields_cond = compute_cond_mean(case_folder, 1, fields_list, 2, n_bins=32) - + # Output to temporary directory and delete when done with tempfile.TemporaryDirectory() as tmpdirname: save_cond(os.path.join(tmpdirname, "cond.pkl"), fields_cond) From c815ec53d4148ab0be54a3f02a48da72db39cb4f Mon Sep 17 00:00:00 2001 From: Malik Date: Sat, 19 Sep 2026 17:05:45 -0600 Subject: [PATCH 6/9] remove l r grading altogether --- bird/meshing/block_cyl_mesh.py | 6 ------ 1 file changed, 6 deletions(-) diff --git a/bird/meshing/block_cyl_mesh.py b/bird/meshing/block_cyl_mesh.py index 0bb12f3a..a30ed165 100644 --- a/bird/meshing/block_cyl_mesh.py +++ b/bird/meshing/block_cyl_mesh.py @@ -87,8 +87,6 @@ def assemble_mesh(input_file, geom_dict): raise ValueError(f"unknown input file ({input_file}) extension") R = geom_dict["R"] L = geom_dict["L"] - N1 = len(R) - N2 = len(L) - 1 CW = [] mCW = [] C1 = [] @@ -321,8 +319,6 @@ def writeBlockMeshDict(out_folder, geom_dict, mesh_dict): NS = mesh_dict["NS"] NVert = mesh_dict["NVert"] gradR = mesh_dict["gradR"] - gradR_l = mesh_dict["gradR_l"] - gradR_r = mesh_dict["gradR_r"] gradVert = mesh_dict["gradVert"] CW = mesh_dict["CW"] mCW = mesh_dict["mCW"] @@ -420,8 +416,6 @@ def writeBlockMeshDict(out_folder, geom_dict, mesh_dict): # gradingR = 1 # if il==N2-1: # gradingVert = outletGrading - gradingR_l = gradR_l[ir] - gradingR_r = gradR_r[ir] gradingVert = gradVert[il] gradingR = gradR[ir] # Am I a wall From f4581c762c5eab963b7c561b12f0820099742acd Mon Sep 17 00:00:00 2001 From: Malik Date: Sat, 19 Sep 2026 17:06:11 -0600 Subject: [PATCH 7/9] remove more unused vars --- bird/meshing/block_rect_mesh.py | 1 - bird/meshing/stirred_tank_mesh.py | 4 ---- 2 files changed, 5 deletions(-) diff --git a/bird/meshing/block_rect_mesh.py b/bird/meshing/block_rect_mesh.py index c6665a40..8876c2ae 100644 --- a/bird/meshing/block_rect_mesh.py +++ b/bird/meshing/block_rect_mesh.py @@ -93,7 +93,6 @@ def make_fluid_blocks_from_corner(corners): assert isinstance(corners, list) fluid_blocks = [] for multi_block in corners: - n_end_block = len(multi_block) for iend, end_block in enumerate(multi_block): # Add blocks that connect end points if iend == 0: diff --git a/bird/meshing/stirred_tank_mesh.py b/bird/meshing/stirred_tank_mesh.py index 9b755dbd..49e85cf5 100644 --- a/bird/meshing/stirred_tank_mesh.py +++ b/bird/meshing/stirred_tank_mesh.py @@ -122,8 +122,6 @@ def get_globalindex_of(splti, ci, zi, react): centeroffset = react.centeroffset polyoffset = react.polyoffset nsplits = react.nsplits - hub_circ = react.hub_circ - tank_circ = react.tank_circ # also works for ci=-1 global_id = ( @@ -173,8 +171,6 @@ def write_edges(outfile, react): for zi in range(nsections): outfile.write("\n//section " + str(zi) + "\n") - offset = 1 + nsplits # one for center and nsplits for polygon - outfile.write("\n//circles\n") for ci in range(ncirc): outfile.write("\n//circle " + str(ci) + "\n") From b18d89fef3ea7c8f49ae58c990fd658b293735ea Mon Sep 17 00:00:00 2001 From: Malik Date: Sat, 19 Sep 2026 17:13:00 -0600 Subject: [PATCH 8/9] more unused vars --- bird/meshing/block_cyl_mesh.py | 5 ----- bird/meshing/block_rect_mesh.py | 2 -- bird/postprocess/early_pred.py | 1 - 3 files changed, 8 deletions(-) diff --git a/bird/meshing/block_cyl_mesh.py b/bird/meshing/block_cyl_mesh.py index a30ed165..079c7285 100644 --- a/bird/meshing/block_cyl_mesh.py +++ b/bird/meshing/block_cyl_mesh.py @@ -311,9 +311,7 @@ def writeBlockMeshDict(out_folder, geom_dict, mesh_dict): BoundaryNames = geom_dict["names"] BoundaryType = geom_dict["types"] BoundaryRmin = geom_dict["rmin"] - BoundaryRmax = geom_dict["rmax"] BoundaryLmin = geom_dict["lmin"] - BoundaryLmax = geom_dict["lmax"] NR = mesh_dict["NR"] NS = mesh_dict["NS"] @@ -522,7 +520,6 @@ def writeBlockMeshDict(out_folder, geom_dict, mesh_dict): boundType = BoundaryType[i][ibound] if boundType == "lateral": rminInd = BoundaryRmin[i][ibound] - rmaxInd = BoundaryRmax[i][ibound] lInd = BoundaryLmin[i][ibound] i1 = rminInd * (4 * (N2 + 1)) + 4 * lInd # bottom i2 = i1 - 4 # top @@ -534,7 +531,6 @@ def writeBlockMeshDict(out_folder, geom_dict, mesh_dict): elif boundType == "top": lminInd = BoundaryLmin[i][ibound] - lmaxInd = BoundaryLmax[i][ibound] rInd = BoundaryRmin[i][ibound] if rInd > 0: i1 = 4 * (N2 + 1) * (rInd - 1) + 4 * lminInd # right @@ -550,7 +546,6 @@ def writeBlockMeshDict(out_folder, geom_dict, mesh_dict): elif boundType == "bottom": lminInd = BoundaryLmin[i][ibound] - lmaxInd = BoundaryLmax[i][ibound] rInd = BoundaryRmin[i][ibound] i1 = 4 * (N2 + 1) * (rInd - 1) + 4 * lminInd # right i2 = i1 + 4 * (N2 + 1) # left diff --git a/bird/meshing/block_rect_mesh.py b/bird/meshing/block_rect_mesh.py index 8876c2ae..9985117a 100644 --- a/bird/meshing/block_rect_mesh.py +++ b/bird/meshing/block_rect_mesh.py @@ -44,7 +44,6 @@ def write_vertices(outfile, lengths, nboxes): def write_blocks(outfile, blockids, lengths, nboxes, points_per_len): nx = nboxes[0] ny = nboxes[1] - nz = nboxes[2] idarray = np.zeros(8, dtype=int) mesharray = np.zeros(3, dtype=int) @@ -221,7 +220,6 @@ def from_block_rect_to_seg(input_geom_dict, rescale=True): ) vec_conn = segments[iseg]["end"] - segments[iseg]["start"] segments[iseg]["conn"] = vec_conn - norm_vec_conn = np.linalg.norm(vec_conn) segments[iseg]["normal_dir"] = int(np.nonzero(vec_conn)[0][0]) if segments[iseg]["normal_dir"] == 0: segments[iseg]["max_rad"] = (blocksize_y + blocksize_z) / 4 diff --git a/bird/postprocess/early_pred.py b/bird/postprocess/early_pred.py index c96006f4..ac4c4f57 100644 --- a/bird/postprocess/early_pred.py +++ b/bird/postprocess/early_pred.py @@ -63,7 +63,6 @@ def plotAllEarly_uq(data_dict, color_files=None): t = data_dict[datf]["t"] y = data_dict[datf]["y"] * 100 med_real = data_dict[datf]["med_real"] * 100 - mean_real = data_dict[datf]["mean_real"] * 100 std16_real = data_dict[datf]["std16_real"] * 100 std84_real = data_dict[datf]["std84_real"] * 100 From 59b3c5b8a3c1c44b2b1aad216325533a48a336e2 Mon Sep 17 00:00:00 2001 From: Malik Date: Sat, 19 Sep 2026 17:23:02 -0600 Subject: [PATCH 9/9] escape annoying pyflakes messages --- noxfile.py | 47 ++++++++++++++++++++++++++--- tests/postprocess/test_cond_mean.py | 2 +- 2 files changed, 44 insertions(+), 5 deletions(-) diff --git a/noxfile.py b/noxfile.py index 23b88490..c9221a95 100644 --- a/noxfile.py +++ b/noxfile.py @@ -48,7 +48,7 @@ def run_cleanup(session: nox.Session) -> None: @nox.session(name="linter", python=False) def run_lint(session: nox.Session) -> None: """ - Run black and isort with the github config file + Run black and isort, then pyflakes on the bird library """ @@ -59,9 +59,6 @@ def run_lint(session: nox.Session) -> None: "black", "--line-length", "79", - # Target the OLDEST python supported in pyproject.toml, not the newest. - # This flag tells black which syntax it may emit, so targeting py314 - # let it rewrite `except (A, B):` into py3.14-only `except A, B:` "--target-version", "py311", "--exclude", @@ -97,6 +94,48 @@ def run_lint(session: nox.Session) -> None: session.run(*black_command) session.run(*isort_command) + run_pyflakes(session) + + +@nox.session(name="pyflakes", python=False) +def run_pyflakes(session: nox.Session) -> None: + """ + Run pyflakes on the bird library only + """ + + session.run("pip", "install", "--upgrade", "--quiet", "pyflakes") + + output = session.run( + "pyflakes", + "bird", + external=True, + silent=True, + success_codes=[0, 1], + ) + + ignored_messages = ( + "unable to detect undefined names", + "may be undefined, or defined from star imports", + ) + # Script-only subtrees under bird/ + excluded_paths = ( + "bird/preprocess/data_case_gen/", + "bird/preprocess/inhomogeneousBC/", + "bird/postprocess/SA_optimization/", + "bird/postprocess/computeQoI/", + ) + + problems = [ + line + for line in (output or "").splitlines() + if line.strip() + and not any(msg in line for msg in ignored_messages) + and not any(path in line for path in excluded_paths) + ] + + if problems: + session.error("pyflakes found issues:\n" + "\n".join(problems)) + @nox.session(name="spell", python=False) @nox.session(name="codespell", python=False) diff --git a/tests/postprocess/test_cond_mean.py b/tests/postprocess/test_cond_mean.py index 9d166ef5..c29fd36c 100644 --- a/tests/postprocess/test_cond_mean.py +++ b/tests/postprocess/test_cond_mean.py @@ -31,7 +31,7 @@ def test_compute_cond(): "d.gas", ] fields_cond = compute_cond_mean(case_folder, 1, fields_list, 2, n_bins=32) - + # Output to temporary directory and delete when done with tempfile.TemporaryDirectory() as tmpdirname: save_cond(os.path.join(tmpdirname, "cond.pkl"), fields_cond)