Skip to content

Commit 48ec3b2

Browse files
authored
feat(generate_classes.py): allow excluding components (#2447)
1 parent 2ba4010 commit 48ec3b2

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

flopy/mf6/utils/generate_classes.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
flopypth = os.path.join(thisfilepath, "..", "..")
1212
flopypth = os.path.abspath(flopypth)
1313
protected_dfns = ["flopy.dfn"]
14-
1514
default_owner = "MODFLOW-USGS"
1615
default_repo = "modflow6"
1716

@@ -88,14 +87,17 @@ def backup_existing_dfns(flopy_dfn_path):
8887
), f"dfn backup files not found: {backup_folder}"
8988

9089

91-
def replace_dfn_files(new_dfn_pth, flopy_dfn_path):
90+
def replace_dfn_files(new_dfn_pth, flopy_dfn_path, exclude):
9291
# remove the old files, unless the file is protected
9392
filenames = os.listdir(flopy_dfn_path)
9493
delete_files(filenames, flopy_dfn_path, exclude=protected_dfns)
9594

9695
# copy the new ones into the folder
9796
filenames = os.listdir(new_dfn_pth)
9897
for filename in filenames:
98+
if exclude and any(pattern in filename for pattern in exclude):
99+
print(f" excluding..{filename}")
100+
continue
99101
filename_w_path = os.path.join(new_dfn_pth, filename)
100102
print(f" copying..{filename}")
101103
shutil.copy(filename_w_path, flopy_dfn_path)
@@ -118,6 +120,7 @@ def generate_classes(
118120
ref="master",
119121
dfnpath=None,
120122
backup=True,
123+
exclude=None
121124
):
122125
"""
123126
Generate the MODFLOW 6 flopy classes using definition files from the
@@ -147,7 +150,8 @@ def generate_classes(
147150
backup : bool, default True
148151
Keep a backup of the definition files in dfn_backup with a date and
149152
timestamp from when the definition files were replaced.
150-
153+
exclude : list of str, optional, default None
154+
Patterns for excluding DFN files and corresponding components.
151155
"""
152156

153157
# print header
@@ -187,7 +191,7 @@ def generate_classes(
187191
print(" Using pre-existing definition files")
188192
else:
189193
print(" Replacing existing definition files")
190-
replace_dfn_files(new_dfn_pth, flopy_dfn_path)
194+
replace_dfn_files(new_dfn_pth, flopy_dfn_path, exclude)
191195
if dfnpath is None:
192196
shutil.rmtree(new_dfn_pth)
193197

@@ -230,6 +234,11 @@ def cli_main():
230234
help="Path to a definition file folder that will be used to generate "
231235
"the MODFLOW 6 classes.",
232236
)
237+
parser.add_argument(
238+
"--exclude",
239+
help="Exclude DFNs matching a pattern.",
240+
action="append"
241+
)
233242
parser.add_argument(
234243
"--no-backup",
235244
action="store_true",

0 commit comments

Comments
 (0)