Skip to content

Commit

Permalink
refactor: support filtering components in mf6ivar and dist scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
wpbonelli committed Jan 5, 2024
1 parent 9b3cc69 commit 91fbc70
Show file tree
Hide file tree
Showing 13 changed files with 1,128 additions and 1,236 deletions.
42 changes: 37 additions & 5 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,14 @@ on:
description: 'Version number to use for release.'
required: true
type: string
models:
description: 'Models to include in the release build'
required: false
type: string
exchanges:
description: 'Exchanges to include in the release build'
required: false
type: string
outputs:
version:
description: 'Version number used for release'
Expand Down Expand Up @@ -130,7 +138,7 @@ jobs:
if: runner.os != 'Windows'
working-directory: modflow6
run: |
meson setup builddir -Ddebug=false --prefix=$(pwd) --libdir=bin
meson setup builddir -Ddebug=false --prefix=$(pwd) --libdir=bin -Dmodels=${{ inputs.models }} -Dexchanges=${{ inputs.exchanges }}
meson install -C builddir
meson test --verbose --no-rebuild -C builddir
Expand All @@ -139,7 +147,7 @@ jobs:
working-directory: modflow6
shell: pwsh
run: |
meson setup builddir -Ddebug=false --prefix=$(pwd) --libdir=bin
meson setup builddir -Ddebug=false --prefix=$(pwd) --libdir=bin -Dmodels=${{ inputs.models }} -Dexchanges=${{ inputs.exchanges }}
meson install -C builddir
meson test --verbose --no-rebuild -C builddir
Expand Down Expand Up @@ -346,8 +354,32 @@ jobs:

- name: Build example models
if: inputs.full == true
working-directory: modflow6-examples/etc
run: python ci_build_files.py
working-directory: modflow6-examples/scripts
shell: python
run: |
from pathlib import Path
exclude = ["ex-gwf-capture.py"]
models = "${{ inputs.models }}"".split(',')
scripts = [
fname
for fname in Path.cwd().glob("*")
if fname.suffix == ".py"
and fname.stem not in exclude
and any(fname.stem.startswith(f"ex-{m}") for m in models)
]
if patterns:
scripts = [s for s in scripts if any(p in s for p in patterns)]
for script in scripts:
argv = [
sys.executable,
script,
"--no_run",
"--no_plot",
"--destination",
examples_path,
]
print(f"running {argv} in {scripts_folder}")
run_command(argv, scripts_folder)
- name: Create full docs folder structure
if: inputs.full == true
Expand Down Expand Up @@ -389,7 +421,7 @@ jobs:
GITHUB_TOKEN: ${{ github.token }}
run: |
mkdir -p "${{ needs.build.outputs.distname }}/doc"
cmd="python modflow6/distribution/build_docs.py -b bin -o doc"
cmd="python modflow6/distribution/build_docs.py -b bin -o doc --models ${{ inputs.models }} --exchanges ${{ inputs.exchanges }}"
if [[ "${{ inputs.full }}" == "true" ]]; then
cmd="$cmd --full"
fi
Expand Down
57 changes: 1 addition & 56 deletions distribution/build_dist.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from pathlib import Path
from pprint import pprint
from shutil import copytree
from typing import List, Optional

import pytest
from modflow_devtools.build import meson_build
Expand All @@ -22,7 +23,6 @@

# default paths
_project_root_path = get_project_root_path()
_examples_repo_path = _project_root_path.parent / "modflow6-examples"
_build_path = _project_root_path / "builddir"

# OS-specific extensions
Expand Down Expand Up @@ -95,38 +95,6 @@ def test_copy_sources(tmp_path):
assert (tmp_path / "msvs" / "mf6.sln").is_file()


def build_examples(examples_repo_path: PathLike, overwrite: bool = False):
examples_repo_path = Path(examples_repo_path).expanduser().absolute()

# create examples, but don't run them
examples_path = examples_repo_path / "examples"
examples_path.mkdir(parents=True, exist_ok=True)
if not overwrite and any(get_model_paths(examples_path)):
print(f"Examples already built")
else:
print(f"Building examples")
scripts_folder = examples_repo_path / "scripts"
exclude_list = ["ex-gwf-capture.py"]
scripts = [
fname
for fname in scripts_folder.glob("*")
if fname.suffix == ".py"
and fname.stem.startswith("ex-")
and fname.stem not in exclude_list
]
for script in scripts:
argv = [
sys.executable,
script,
"--no_run",
"--no_plot",
"--destination",
examples_path,
]
print(f"running {argv} in {scripts_folder}")
run_command(argv, scripts_folder)


def setup_examples(
bin_path: PathLike, examples_path: PathLike, overwrite: bool = False
):
Expand Down Expand Up @@ -197,7 +165,6 @@ def build_programs_meson(
):
build_path = Path(build_path).expanduser().absolute()
bin_path = Path(bin_path).expanduser().absolute()

exe_paths = [
bin_path / f"mf6{_eext}",
bin_path / f"zbud6{_eext}",
Expand Down Expand Up @@ -285,15 +252,13 @@ def test_build_makefiles(tmp_path):
def build_distribution(
build_path: PathLike,
output_path: PathLike,
examples_repo_path: PathLike,
full: bool = False,
overwrite: bool = False,
):
print(f"Building {'full' if full else 'minimal'} distribution")

build_path = Path(build_path).expanduser().absolute()
output_path = Path(output_path).expanduser().absolute()
examples_repo_path = Path(examples_repo_path).expanduser().absolute()

# binaries
build_programs_meson(
Expand Down Expand Up @@ -322,8 +287,6 @@ def build_distribution(
build_documentation(
bin_path=output_path / "bin",
output_path=output_path / "doc",
examples_repo_path=examples_repo_path,
# benchmarks_path=_benchmarks_path / "run-time-comparison.md",
full=full,
overwrite=overwrite,
)
Expand All @@ -337,7 +300,6 @@ def test_build_distribution(tmp_path, full):
build_distribution(
build_path=tmp_path / "builddir",
output_path=output_path,
examples_repo_path=_examples_repo_path,
full=full,
overwrite=True,
)
Expand Down Expand Up @@ -395,13 +357,6 @@ def test_build_distribution(tmp_path, full):
default=str(_project_root_path / "distribution"),
help="Path to create distribution artifacts",
)
parser.add_argument(
"-e",
"--examples-repo-path",
required=False,
default=str(_examples_repo_path),
help="Path to directory containing modflow6 example models",
)
parser.add_argument(
"--full",
required=False,
Expand All @@ -420,20 +375,10 @@ def test_build_distribution(tmp_path, full):
args = parser.parse_args()
build_path = Path(args.build_path)
out_path = Path(args.output_path)
examples_repo_path = (
Path(args.examples_repo_path)
if args.examples_repo_path
else _examples_repo_path
)
assert (
examples_repo_path.is_dir()
), f"Examples repo not found at path: {examples_repo_path}"
out_path.mkdir(parents=True, exist_ok=True)

build_distribution(
build_path=build_path,
output_path=out_path,
examples_repo_path=examples_repo_path,
full=args.full,
overwrite=args.force,
)
16 changes: 13 additions & 3 deletions distribution/build_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@
# OS-specific extensions
_system = platform.system()
_eext = ".exe" if _system == "Windows" else ""
_soext = ".dll" if _system == "Windows" else ".so" if _system == "Linux" else ".dylib"

# publications included in full dist docs
_publication_urls = [
Expand Down Expand Up @@ -213,7 +212,9 @@ def build_deprecations_tex():
assert (_docs_path / "ReleaseNotes" / f"{deprecations_path.stem}.tex").is_file()


def build_mf6io_tex_from_dfn(overwrite: bool = False):
def build_mf6io_tex_from_dfn(
overwrite: bool = False,
models: Optional[List[str]] = None):
if overwrite:
clean_tex_files()

Expand Down Expand Up @@ -255,7 +256,10 @@ def files_match(tex_path, dfn_path, ignored):
f.unlink()

# run python script
out, err, ret = run_cmd(sys.executable, "mf6ivar.py")
args = [sys.executable, "mf6ivar.py"]
for model in models:
args += ["--model", model]
out, err, ret = run_cmd(*args)
assert not ret, out + err

# check that dfn and tex files match
Expand Down Expand Up @@ -595,6 +599,12 @@ def test_build_documentation(tmp_path):
default="MODFLOW-USGS",
help="Repository owner (substitute your own for a fork)",
)
parser.add_argument(
"--models",
required=False,
default=""
)
parser.add_argument()
args = parser.parse_args()
output_path = Path(args.output_path).expanduser().absolute()
output_path.mkdir(parents=True, exist_ok=True)
Expand Down
Loading

0 comments on commit 91fbc70

Please sign in to comment.