diff --git a/.github/workflows/ci-check-warnings-gfortran.yml b/.github/workflows/ci-check-warnings-gfortran.yml index 0b8dc258f87..2637da2bf9b 100644 --- a/.github/workflows/ci-check-warnings-gfortran.yml +++ b/.github/workflows/ci-check-warnings-gfortran.yml @@ -75,9 +75,3 @@ jobs: working-directory: distribution run: | pytest -v -s build_nightly.py - - - name: Move the build zip file - run: | - ls -l ./distribution/* - mv ./distribution/temp_zip/linux.zip ./linux.zip - ls -l ./ diff --git a/.github/workflows/ci-tests-gfortran-latest.yml b/.github/workflows/ci-tests-gfortran-latest.yml index ae952f86670..0cf070542cb 100644 --- a/.github/workflows/ci-tests-gfortran-latest.yml +++ b/.github/workflows/ci-tests-gfortran-latest.yml @@ -46,7 +46,7 @@ jobs: - name: Test make for MODFLOW 6 programs working-directory: ./distribution run: | - pytest -v -n=auto build_makefiles.py + pytest -v build_makefiles.py - name: Get regression test files run: | diff --git a/distribution/build_makefiles.py b/distribution/build_makefiles.py index 113729661af..045eaa23092 100644 --- a/distribution/build_makefiles.py +++ b/distribution/build_makefiles.py @@ -1,8 +1,11 @@ +from datetime import datetime import os import sys from contextlib import contextmanager +from pathlib import Path import pymake +import pytest if sys.platform.lower() == "win32": ext = ".exe" @@ -16,28 +19,31 @@ fc = sys.argv[idx + 1] # if compiler not set by command line argument -# use environmental variable or set to default compiler (gfortran) +# use environment variable or set to default compiler (gfortran) if fc is None: if "FC" in os.environ: fc = os.getenv("FC") else: fc = "gfortran" +# assumes this file is in /distribution +root_path = Path(__file__).parent.parent + @contextmanager def cwd(path): - oldpwd = os.getcwd() + prev = os.getcwd() os.chdir(path) try: yield finally: - os.chdir(oldpwd) + os.chdir(prev) def run_makefile(target): - assert os.path.isfile( + assert Path( "makefile" - ), f"makefile does not exist in {os.getcwd()}" + ).is_file(), f"makefile does not exist in {os.getcwd()}" base_target = os.path.basename(target) base_message = ( @@ -60,19 +66,13 @@ def run_makefile(target): f"{base_target} does not exist." + base_message ) - # clean after successful make - print(f"clean {base_target} with makefile") - os.system("make clean") - - return - def build_mf6_makefile(): - with cwd(os.path.join("..", "make")): + with cwd(root_path / "make"): pm = pymake.Pymake() pm.target = "mf6" - pm.srcdir = os.path.join("..", "src") - pm.appdir = os.path.join("..", "bin") + pm.srcdir = str(root_path / "src") + pm.appdir = str(root_path / "bin") pm.include_subdirs = True pm.inplace = True pm.dryrun = True @@ -85,16 +85,15 @@ def build_mf6_makefile(): msg = f"could not create makefile for '{pm.target}'." assert pm.returncode == 0, msg - return - def build_zbud6_makefile(): - with cwd(os.path.join("..", "utils", "zonebudget", "make")): + util_path = root_path / "utils" / "zonebudget" + with cwd(util_path / "make"): pm = pymake.Pymake() pm.target = "zbud6" - pm.srcdir = os.path.join("..", "src") - pm.appdir = os.path.join("..", "..", "..", "bin") - pm.extrafiles = os.path.join("..", "pymake", "extrafiles.txt") + pm.srcdir = str(util_path / "src") + pm.appdir = str(root_path / "bin") + pm.extrafiles = str(util_path / "pymake" / "extrafiles.txt") pm.inplace = True pm.makeclean = True pm.dryrun = True @@ -107,14 +106,13 @@ def build_zbud6_makefile(): msg = f"could not create makefile for '{pm.target}'." assert pm.returncode == 0, msg - return - def build_mf5to6_makefile(): - with cwd(os.path.join("..", "utils", "mf5to6", "make")): - srcdir = os.path.join("..", "src") - target = os.path.join("..", "..", "..", "bin", "mf5to6") - extrafiles = os.path.join("..", "pymake", "extrafiles.txt") + util_path = root_path / "utils" / "mf5to6" + with cwd(util_path / "make"): + srcdir = str(util_path / "src") + target = str(root_path / "bin" / "mf5to6") + extrafiles = str(util_path / "pymake" / "extrafiles.txt") # build modflow 5 to 6 converter returncode = pymake.main( @@ -129,34 +127,96 @@ def build_mf5to6_makefile(): fflags="-fall-intrinsics", ) - msg = f"could not create makefile for '{os.path.basename(target)}'." + msg = f"could not create makefile for '{target}'." assert returncode == 0, msg - return + +def test_build_mf6_makefile(): + makefile_paths = [root_path / "make" / "makefile"] + makefile_mtimes = [p.stat().st_mtime for p in makefile_paths] + + build_mf6_makefile() + + # check files were modified + for p, t in zip(makefile_paths, makefile_mtimes): + assert p.stat().st_mtime > t + os.system(f"git restore {p}") + + +def test_build_zbud6_makefile(): + util_path = root_path / "utils" / "zonebudget" + makefile_paths = [util_path / "make" / "makefile"] + makefile_mtimes = [p.stat().st_mtime for p in makefile_paths] + + build_zbud6_makefile() + + # check files were modified + for p, t in zip(makefile_paths, makefile_mtimes): + assert p.stat().st_mtime > t + os.system(f"git restore {p}") + + +def test_build_mf5to6_makefile(): + util_path = root_path / "utils" / "mf5to6" + makefile_paths = [util_path / "make" / "makefile"] + makefile_mtimes = [p.stat().st_mtime for p in makefile_paths] + + build_mf5to6_makefile() + + # check files were modified + for p, t in zip(makefile_paths, makefile_mtimes): + assert p.stat().st_mtime > t + os.system(f"git restore {p}") def test_build_mf6_wmake(): - target = os.path.join("..", "bin", f"mf6{ext}") - with cwd(os.path.join("..", "make")): + target = root_path / "bin" / f"mf6{ext}" + mtime = target.stat().st_mtime if target.is_file() else datetime.today().timestamp() + + with cwd(root_path / "make"): run_makefile(target) + # check executable was modified + assert target.stat().st_mtime > mtime + + # clean after successful make + print(f"clean {target} with makefile") + os.system("make clean") + def test_build_zbud6_wmake(): - target = os.path.join("..", "..", "..", "bin", f"zbud6{ext}") - with cwd(os.path.join("..", "utils", "zonebudget", "make")): + target = root_path / "bin" / f"zbud6{ext}" + util_path = root_path / "utils" / "zonebudget" + mtime = target.stat().st_mtime if target.is_file() else datetime.today().timestamp() + + with cwd(util_path / "make"): run_makefile(target) + # check executable was modified + assert target.stat().st_mtime > mtime + + # clean after successful make + print(f"clean {target} with makefile") + os.system("make clean") + def test_build_mf5to6_wmake(): - target = os.path.join("..", "..", "..", "bin", f"mf5to6{ext}") - with cwd(os.path.join("..", "utils", "mf5to6", "make")): + target = root_path / "bin" / f"mf5to6{ext}" + util_path = root_path / "utils" / "mf5to6" + mtime = target.stat().st_mtime if target.is_file() else datetime.today().timestamp() + + with cwd(util_path / "make"): run_makefile(target) + # check executable was modified + assert target.stat().st_mtime > mtime + + # clean after successful make + print(f"clean {target} with makefile") + os.system("make clean") + if __name__ == "__main__": build_mf6_makefile() build_zbud6_makefile() build_mf5to6_makefile() - # test_build_mf6_wmake() - # test_build_zbud6_wmake() - # test_build_mf5to6_wmake() diff --git a/distribution/build_nightly.py b/distribution/build_nightly.py index a59749dba60..c2bb4b55149 100644 --- a/distribution/build_nightly.py +++ b/distribution/build_nightly.py @@ -1,15 +1,19 @@ +from contextlib import contextmanager import os -import pathlib +from os import PathLike, chdir, X_OK +from pathlib import Path import platform -import shutil +from shutil import which +import subprocess import sys +from tempfile import TemporaryDirectory import flopy import pymake +import pytest -# add path to build script in autotest directory and reuse mf6 build scripts -sys.path.append(os.path.join("..", "autotest")) -from build_exes import meson_build +from make_release import update_version +from mkdist import update_mf6io_tex_files # make sure exe extension is used on windows eext = "" @@ -18,9 +22,17 @@ eext = ".exe" soext = ".dll" -bin_path = os.path.abspath(os.path.join("..", "bin")) -example_path = os.path.abspath(os.path.join("temp")) -zip_path = os.path.abspath(os.path.join("temp_zip")) +root_path = Path(__file__).parent.parent + + +@contextmanager +def cwd(path): + prev = os.getcwd() + os.chdir(path) + try: + yield + finally: + os.chdir(prev) def get_zipname(): @@ -35,78 +47,68 @@ def get_zipname(): return zipname -def relpath_fallback(pth): - try: - # throws ValueError on Windows if pth is on a different drive - return os.path.relpath(pth) - except ValueError: - return os.path.abspath(pth) - - -def create_dir(pth): - # remove pth directory if it exists - if os.path.exists(pth): - print(f"removing... {os.path.abspath(pth)}") - shutil.rmtree(pth) - - # create pth directory - print(f"creating... {os.path.abspath(pth)}") - os.makedirs(pth) - - msg = f"could not create... {os.path.abspath(pth)}" - assert os.path.exists(pth), msg - - -def test_update_version(): - from make_release import update_version - - update_version() - - -def test_create_dirs(): - for pth in ( - bin_path, - zip_path, - ): - create_dir(pth) - - -def test_nightly_build(): - meson_build() - - # test if there are any executable files to zip - binpth_files = [ - os.path.join(bin_path, f) - for f in os.listdir(bin_path) - if os.path.isfile(os.path.join(bin_path, f)) - and shutil.which(os.path.join(bin_path, f), mode=os.X_OK) - and pathlib.Path(os.path.join(bin_path, f)).suffix - not in (".a", ".lib", ".pdb") - ] - if len(binpth_files) < 1: - raise FileNotFoundError( - f"No executable files present in {os.path.abspath(bin_path)}.\n" - + f"Available files:\n [{', '.join(os.listdir(bin_path))}]" +def create_nightly_build(proj_path: PathLike, + build_path: PathLike, + bin_path: PathLike, + zip_file_path: PathLike): + build_path = Path(build_path).expanduser().absolute() + bin_path = Path(bin_path).expanduser().absolute() + zip_file_path = Path(zip_file_path).expanduser().absolute() + + with cwd(Path(proj_path)): + wipe = build_path.is_dir() and any([p for p in build_path.glob('*') if not p.name.startswith(".")]) + + # build release source files with Meson + cmd = ( + f"meson setup {build_path} " + + f"--bindir={bin_path} " + + f"--libdir={bin_path} " + + f"--prefix={('%CD%' if platform.system() == 'Windows' else '$(pwd)')}" + + (" --wipe" if wipe else "") ) - else: - print(f"Files to zip:\n [{', '.join(binpth_files)}]") + print(f"Running meson setup command: {cmd}") + subprocess.run(cmd, shell=True, check=True) + + cmd = f"meson install -C {build_path}" + print(f"Running meson install command: {cmd}") + subprocess.run(cmd, shell=True, check=True) + + # test if there are any executable files to zip + binaries = [ + str(bin_path / f) + for f in bin_path.glob('*') + if (bin_path / f).is_file() + and which(bin_path / f, mode=X_OK) + and (bin_path / f).suffix not in (".a", ".lib", ".pdb") + ] + if len(binaries) < 1: + raise FileNotFoundError( + f"No executable files present in {bin_path.absolute()}.\n" + + f"Available files:\n [{', '.join([str(p) for p in bin_path.glob('*')])}]" + ) + else: + print(f"Files to zip:\n [{', '.join(binaries)}]") + + zip_file_path = (Path(zip_file_path) / (get_zipname() + ".zip")).absolute() + print(f"Zipping files to '{zip_file_path}'") + + success = pymake.zip_all(str(zip_file_path), file_pths=binaries) + assert success, f"Could not create '{zip_file_path}'" + + +def update_mf6io(bin_path: PathLike, temp_path: PathLike): + bin_path = Path(bin_path) + temp_path = Path(temp_path) - zip_pth = os.path.abspath(os.path.join(zip_path, get_zipname() + ".zip")) - print(f"Zipping files to '{zip_pth}'") - success = pymake.zip_all(zip_pth, file_pths=binpth_files) - assert success, f"Could not create '{zip_pth}'" - - -def test_update_mf6io(): - from mkdist import update_mf6io_tex_files - - # build simple model name = "mymodel" - ws = os.path.join(example_path, name) + ws = str(temp_path / name) + exe_name = "mf6" if sys.platform.lower() == "win32": exe_name += ".exe" - exe_name = os.path.join(bin_path, exe_name) + exe_name = str(bin_path / exe_name) + + # build simple model sim = flopy.mf6.MFSimulation(sim_name=name, sim_ws=ws, exe_name=exe_name) tdis = flopy.mf6.ModflowTdis(sim) ims = flopy.mf6.ModflowIms(sim) @@ -124,8 +126,51 @@ def test_update_mf6io(): update_mf6io_tex_files(None, exe_name, expth=ws) +def test_create_nightly_build(tmpdir): + build_path = root_path / "builddir" + bin_path = root_path / "bin" + dist_path = tmpdir / "dist" + + # build_path.mkdir(exist_ok=True) + bin_path.mkdir(exist_ok=True) + dist_path.mkdir() + + create_nightly_build(root_path, build_path, bin_path, dist_path) + assert Path(dist_path / f"{get_zipname()}.zip").is_file() + + +@pytest.mark.order(after="test_create_nightly_build") +def test_update_mf6io(tmpdir): + # LaTeX files to be updated + tex_paths = [ + root_path / "doc" / "mf6io" / "mf6noname.tex", + root_path / "doc" / "mf6io" / "mf6output.tex", + root_path / "doc" / "mf6io" / "mf6switches.tex", + ] + tex_mtimes = [p.stat().st_mtime for p in tex_paths] + + bin_path = root_path / "bin" + bin_path.mkdir(exist_ok=True) + update_mf6io(bin_path, tmpdir) + + # check files were modified + for p, t in zip(tex_paths, tex_mtimes): + assert p.stat().st_mtime > t + os.system(f"git restore {p}") + + if __name__ == "__main__": - test_update_version() - test_create_dirs() - test_nightly_build() - test_update_mf6io() + with TemporaryDirectory as temp: + build_path = Path(root_path / "builddir") + bin_path = Path(root_path / "bin") + temp_path = Path(temp.name) + dist_path = root_path / "distribution" / "temp_zip" + + print(f"Building nightly MODFLOW 6 release") + bin_path.mkdir(exist_ok=True) + temp_path.mkdir(exist_ok=True) + dist_path.mkdir(exist_ok=True, parents=True) + + update_version() + create_nightly_build(root_path, build_path, bin_path, dist_path) + update_mf6io(bin_path, temp_path) diff --git a/distribution/make_release.py b/distribution/make_release.py index 51865f5b0f3..fad00971898 100644 --- a/distribution/make_release.py +++ b/distribution/make_release.py @@ -53,11 +53,10 @@ import subprocess import sys from collections import OrderedDict +from pathlib import Path -# update files and paths so that there are the same number of -# path and file entries in the paths and files list. Enter '.' -# as the path if the file is in the root repository directory -paths = ["../", "../doc", "../", "../", "../", "../src/Utilities"] +project_root = Path(__file__).parent.parent +paths = [project_root, project_root / "doc", project_root, project_root, project_root, project_root / "src" / "Utilities"] files = [ "version.txt", "version.tex", @@ -158,7 +157,7 @@ def get_is_approved(): if is_approved is None: # get current branch branch = get_branch() - if "release" in branch.lower() or "master" in branch.lower(): + if branch is None or "release" in branch.lower() or "master" in branch.lower(): is_approved = True else: is_approved = False @@ -249,7 +248,7 @@ def update_version(): vmicro = int(t[2]) try: - fpth = os.path.join(paths[0], files[0]) + fpth = str(paths[0] / files[0]) lines = [line.rstrip("\n") for line in open(fpth, "r")] if vmajor is None: for line in lines: @@ -283,8 +282,8 @@ def update_version(): # update version.py in doc directory shutil.copyfile( os.path.abspath(fpth), - os.path.join( - "..", "doc", os.path.basename(fpth.replace(".txt", ".py")) + str( + project_root / "doc" / os.path.basename(fpth.replace(".txt", ".py")) ), ) @@ -293,7 +292,7 @@ def update_version(): version_type = get_version_type(get_branch()).strip() if len(version_type) > 0: version += f"---{version_type}" - pth = os.path.join(paths[1], files[1]) + pth = str(paths[1] / files[1]) f = open(pth, "w") line = "\\newcommand{\\modflowversion}{mf" + f"{version}" + "}" f.write(f"{line}\n") @@ -381,7 +380,7 @@ def update_mf6_version(vmajor, vminor, vmicro): is_approved, disclaimerfmt = get_disclaimerfmt() # read version.f90 into memory - fpth = os.path.join(paths[5], files[5]) + fpth = str(paths[5] / files[5]) with open(fpth, "r") as file: lines = [line.rstrip() for line in file] @@ -429,7 +428,7 @@ def update_readme_markdown(vmajor, vminor, vmicro): sb = " release candidate" # read README.md into memory - fpth = os.path.join(paths[2], files[2]) + fpth = str(paths[2] / files[2]) with open(fpth, "r") as file: lines = [line.rstrip() for line in file] @@ -439,7 +438,7 @@ def update_readme_markdown(vmajor, vminor, vmicro): for line in lines: if "## Version " in line: line = f"### Version {version}" - if "develop" in branch: + if branch is not None and "develop" in branch: line += sb # This has been commented out as we've generalized this reference. # elif "https://doi.org/10.5066/F76Q1VQV" in line: @@ -464,7 +463,7 @@ def update_readme_markdown(vmajor, vminor, vmicro): f.close() # write disclaimer markdown file - fpth = os.path.join(paths[3], files[3]) + fpth = str(paths[3] / files[3]) f = open(fpth, "w") f.write(disclaimer) f.close() @@ -474,7 +473,7 @@ def update_readme_markdown(vmajor, vminor, vmicro): def update_codejson(vmajor, vminor, vmicro): # define json filename - json_fname = os.path.join(paths[4], files[4]) + json_fname = str(paths[4] / files[4]) # get branch branch = get_branch() diff --git a/distribution/mkdist.py b/distribution/mkdist.py index a6d25399f0d..2cbbd238537 100644 --- a/distribution/mkdist.py +++ b/distribution/mkdist.py @@ -24,6 +24,7 @@ import os +from pathlib import Path import shutil import subprocess import sys @@ -33,6 +34,8 @@ import pymake from pymake import download_and_unzip +project_root = Path(__file__).parent.parent + @contextmanager def cwd(path): @@ -81,7 +84,6 @@ def zipdir(dirname, zipname): zipf.write(fname, arcname=fname) zipf.close() print("\n") - return def setup(name, destpath, version, subdirs): @@ -128,7 +130,6 @@ def copytree(src, dst, symlinks=False, ignore=None): else: print(f" copying {s} ===> {d}") shutil.copy2(s, d) - return def convert_line_endings(folder, windows=True): @@ -153,7 +154,6 @@ def convert_line_endings(folder, windows=True): p = subprocess.Popen(cmd, cwd=folder, shell=True) print(p.communicate()) print("\n") - return def change_version_module(fname, version): @@ -185,7 +185,6 @@ def change_version_module(fname, version): with open(fname, "w") as f: for line in newlines: f.write(line.strip() + "\n") - return def make_zonebudget(srcpath, destpath, win_target_os, exepath): @@ -213,7 +212,7 @@ def make_zonebudget(srcpath, destpath, win_target_os, exepath): print("Creating zonebudget makefile") with cwd(os.path.join(srcpath, "pymake")): pymake.main( - os.path.join("..", "src"), + str(project_root / "src"), "zbud6", "gfortran", "gcc", @@ -283,8 +282,6 @@ def make_zonebudget(srcpath, destpath, win_target_os, exepath): if not os.path.isfile(target): raise Exception(f"Did not build target: {target}") - return - def make_mf5to6(srcpath, destpath, win_target_os, exepath): """ @@ -311,7 +308,7 @@ def make_mf5to6(srcpath, destpath, win_target_os, exepath): print("Creating mf5to6 makefile") with cwd(os.path.join(srcpath, "pymake")): pymake.main( - os.path.join("..", "src"), + str(project_root / "src"), name, "gfortran", "gcc", @@ -377,8 +374,6 @@ def make_mf5to6(srcpath, destpath, win_target_os, exepath): if not os.path.isfile(target): raise Exception(f"Did not build target: {target}") - return - def delete_files(files, pth, allow_failure=False): for file in files: @@ -418,42 +413,40 @@ def clean_latex_files(): print("Cleaning latex files") exts = ["pdf", "aux", "bbl", "idx", "lof", "out", "toc"] - pth = os.path.join("..", "doc", "mf6io") + pth = str(project_root / "doc" / "mf6io") files = [f"mf6io.{e}" for e in exts] delete_files(files, pth, allow_failure=True) assert not os.path.isfile(pth + ".pdf") - pth = os.path.join("..", "doc", "ReleaseNotes") + pth = str(project_root / "doc" / "ReleaseNotes") files = [f"ReleaseNotes.{e}" for e in exts] delete_files(files, pth, allow_failure=True) assert not os.path.isfile(pth + ".pdf") - pth = os.path.join("..", "doc", "zonebudget") + pth = str(project_root / "doc" / "zonebudget") files = [f"zonebudget.{e}" for e in exts] delete_files(files, pth, allow_failure=True) assert not os.path.isfile(pth + ".pdf") - pth = os.path.join("..", "doc", "ConverterGuide") + pth = str(project_root / "doc" / "ConverterGuide") files = [f"converter_mf5to6.{e}" for e in exts] delete_files(files, pth, allow_failure=True) assert not os.path.isfile(pth + ".pdf") - pth = os.path.join("..", "..", "modflow6-docs.git", "mf6suptechinfo") + pth = str(project_root.parent / "modflow6-docs.git" / "mf6suptechinfo") files = [f"mf6suptechinfo.{e}" for e in exts] delete_files(files, pth, allow_failure=True) assert not os.path.isfile(pth + ".pdf") - pth = os.path.join("..", "..", "modflow6-examples.git", "doc") + pth = str(project_root.parent / "modflow6-examples.git" / "doc") files = [f"mf6examples.{e}" for e in exts] delete_files(files, pth, allow_failure=True) assert not os.path.isfile(pth + ".pdf") - return - def rebuild_tex_from_dfn(): - npth = os.path.join("..", "doc", "mf6io", "mf6ivar") + npth = str(project_root / "doc" / "mf6io" / "mf6ivar") pth = "./" with cwd(npth): @@ -502,12 +495,9 @@ def rebuild_tex_from_dfn(): ) assert icnt == 0, msg - return - def update_mf6io_tex_files(distfolder, mf6pth, expth=None): - - texpth = "../doc/mf6io" + texpth = str(project_root / "doc" / "mf6io") fname1 = os.path.join(texpth, "mf6output.tex") fname2 = os.path.join(texpth, "mf6noname.tex") fname3 = os.path.join(texpth, "mf6switches.tex") @@ -571,14 +561,12 @@ def update_mf6io_tex_files(distfolder, mf6pth, expth=None): if os.path.isdir("./temp"): shutil.rmtree("./temp") - return - def build_latex_docs(): print("Building latex files") - pth1 = os.path.join("..", "doc") - pth2 = os.path.join("..", "..", "modflow6-docs.git") - pth3 = os.path.join("..", "..", "modflow6-examples.git") + pth1 = str(project_root / "doc") + pth2 = str(project_root.parent / "modflow6-docs.git") + pth3 = str(project_root.parent / "modflow6-examples.git") doclist = [ (pth1, "mf6io", "mf6io.tex"), (pth1, "ReleaseNotes", "ReleaseNotes.tex"), @@ -630,12 +618,9 @@ def build_latex_docs(): fname = os.path.splitext(t)[0] + ".pdf" assert os.path.isfile(fname), "Could not find " + fname - return - def update_latex_releaseinfo(examples_folder): - - pth = os.path.join("..", "doc", "ReleaseNotes") + pth = str(project_root / "doc" / "ReleaseNotes") files = ["folder_struct.tex"] delete_files(files, pth, allow_failure=True) @@ -654,8 +639,6 @@ def update_latex_releaseinfo(examples_folder): "File does not exist: " + f ) - return - def setup_examples(examples_repo, exdestpath, mf6path): @@ -724,8 +707,6 @@ def setup_examples(examples_repo, exdestpath, mf6path): f.write(s + "\n") f.write("pause" + "\n") - return - if __name__ == "__main__": @@ -737,7 +718,7 @@ def setup_examples(examples_repo, exdestpath, mf6path): name = "MODFLOW 6" exename = "mf6" destpath = "." - versiontexname = os.path.join("..", "doc", "version.tex") + versiontexname = str(project_root / "doc" / "version.tex") version, versiondate = get_distribution_info(versiontexname) distfolder = os.path.join(destpath, version) subdirs = [ @@ -754,11 +735,11 @@ def setup_examples(examples_repo, exdestpath, mf6path): # Copy the Visual Studio solution and project files flist = [ - os.path.join("..", "msvs", "mf6.sln"), - os.path.join("..", "msvs", "mf6.vfproj"), - os.path.join("..", "msvs", "mf6core.vfproj"), - os.path.join("..", "msvs", "mf6bmi.sln"), - os.path.join("..", "msvs", "mf6bmi.vfproj"), + str(project_root / "msvs" / "mf6.sln"), + str(project_root / "msvs" / "mf6.vfproj"), + str(project_root / "msvs" / "mf6core.vfproj"), + str(project_root / "msvs" / "mf6bmi.sln"), + str(project_root / "msvs" / "mf6bmi.vfproj"), ] print("Copying msvs files") for d in flist: @@ -768,21 +749,21 @@ def setup_examples(examples_repo, exdestpath, mf6path): # copy source folder copytree( - os.path.join("..", "src"), + str(project_root / "src"), fd["src"], ignore=shutil.ignore_patterns(".DS_Store"), ) # copy srcbmi folder copytree( - os.path.join("..", "srcbmi"), + str(project_root / "srcbmi"), fd["srcbmi"], ignore=shutil.ignore_patterns(".DS_Store"), ) # Remove existing makefile and makedefaults print("Creating makefile") - makedir = os.path.join("..", "make") + makedir = str(project_root / "make") for fname in ["makefile", "makedefaults"]: fpath = os.path.join(makedir, fname) if os.path.isfile(fpath): @@ -791,7 +772,7 @@ def setup_examples(examples_repo, exdestpath, mf6path): # Create makefile in the make folder with cwd(makedir): pymake.main( - os.path.join("..", "src"), + str(project_root / "src"), "mf6", "gfortran", "gcc", @@ -825,7 +806,7 @@ def setup_examples(examples_repo, exdestpath, mf6path): # setup zone budget make_zonebudget( - os.path.join("..", "utils", "zonebudget"), + str(project_root / "utils" / "zonebudget"), fd["utils"], win_target_os, fd["bin"], @@ -833,7 +814,7 @@ def setup_examples(examples_repo, exdestpath, mf6path): # setup mf5to6 make_mf5to6( - os.path.join("..", "utils", "mf5to6"), + str(project_root / "utils" / "mf5to6"), fd["utils"], win_target_os, fd["bin"], @@ -841,7 +822,7 @@ def setup_examples(examples_repo, exdestpath, mf6path): # setup the examples exdstpath = fd["examples"] - examples_repo = os.path.join("..", "..", "modflow6-examples.git") + examples_repo = str(project_root.parent / "modflow6-examples.git") setup_examples(examples_repo, exdstpath, target) # run the comparison tests so the run time comparison table can be @@ -860,7 +841,7 @@ def setup_examples(examples_repo, exdestpath, mf6path): build_latex_docs() # docs - docsrc = os.path.join("..", "doc") + docsrc = str(project_root / "doc") doclist = [ [ os.path.join(docsrc, "ReleaseNotes", "ReleaseNotes.pdf"), @@ -872,22 +853,18 @@ def setup_examples(examples_repo, exdestpath, mf6path): "mf5to6.pdf", ], [ - os.path.join("..", "doc", "zonebudget", "zonebudget.pdf"), + str(project_root / "doc" / "zonebudget" / "zonebudget.pdf"), "zonebudget.pdf", ], [ - os.path.join( - "..", - "..", - "modflow6-docs.git", - "mf6suptechinfo", - "mf6suptechinfo.pdf", + str( + project_root.parent / "modflow6-docs.git" / "mf6suptechinfo" / "mf6suptechinfo.pdf", ), "mf6suptechinfo.pdf", ], [ - os.path.join( - "..", "..", "modflow6-examples.git", "doc", "mf6examples.pdf" + str( + project_root.parent / "modflow6-examples.git" / "doc" / "mf6examples.pdf" ), "mf6examples.pdf", ], diff --git a/environment.yml b/environment.yml index 4b6d4da6a01..a9af05170b0 100644 --- a/environment.yml +++ b/environment.yml @@ -18,5 +18,6 @@ dependencies: - git+https://github.com/Deltares/xmipy.git - git+https://github.com/MODFLOW-USGS/modflowapi.git - pytest + - pytest-order - pytest-xdist - requests