diff --git a/flopy/mf6/utils/generate_classes.py b/flopy/mf6/utils/generate_classes.py index 0041a928b..7feeed163 100644 --- a/flopy/mf6/utils/generate_classes.py +++ b/flopy/mf6/utils/generate_classes.py @@ -11,7 +11,6 @@ flopypth = os.path.join(thisfilepath, "..", "..") flopypth = os.path.abspath(flopypth) protected_dfns = ["flopy.dfn"] - default_owner = "MODFLOW-USGS" default_repo = "modflow6" @@ -88,7 +87,7 @@ def backup_existing_dfns(flopy_dfn_path): ), f"dfn backup files not found: {backup_folder}" -def replace_dfn_files(new_dfn_pth, flopy_dfn_path): +def replace_dfn_files(new_dfn_pth, flopy_dfn_path, exclude): # remove the old files, unless the file is protected filenames = os.listdir(flopy_dfn_path) delete_files(filenames, flopy_dfn_path, exclude=protected_dfns) @@ -96,6 +95,9 @@ def replace_dfn_files(new_dfn_pth, flopy_dfn_path): # copy the new ones into the folder filenames = os.listdir(new_dfn_pth) for filename in filenames: + if exclude and any(pattern in filename for pattern in exclude): + print(f" excluding..{filename}") + continue filename_w_path = os.path.join(new_dfn_pth, filename) print(f" copying..{filename}") shutil.copy(filename_w_path, flopy_dfn_path) @@ -118,6 +120,7 @@ def generate_classes( ref="master", dfnpath=None, backup=True, + exclude=None ): """ Generate the MODFLOW 6 flopy classes using definition files from the @@ -147,7 +150,8 @@ def generate_classes( backup : bool, default True Keep a backup of the definition files in dfn_backup with a date and timestamp from when the definition files were replaced. - + exclude : list of str, optional, default None + Patterns for excluding DFN files and corresponding components. """ # print header @@ -187,7 +191,7 @@ def generate_classes( print(" Using pre-existing definition files") else: print(" Replacing existing definition files") - replace_dfn_files(new_dfn_pth, flopy_dfn_path) + replace_dfn_files(new_dfn_pth, flopy_dfn_path, exclude) if dfnpath is None: shutil.rmtree(new_dfn_pth) @@ -230,6 +234,11 @@ def cli_main(): help="Path to a definition file folder that will be used to generate " "the MODFLOW 6 classes.", ) + parser.add_argument( + "--exclude", + help="Exclude DFNs matching a pattern.", + action="append" + ) parser.add_argument( "--no-backup", action="store_true",