def test_gnu_make(): os.makedirs(cpth, exist_ok=True) target = "triangle" pm = pymake.Pymake(verbose=True) pm.makefile = True pm.makeclean = True pm.cc = "gcc" if sys.platform.lower() == "win32": target += ".exe" # get current directory cwd = os.getcwd() # change to working directory so triangle download directory is # a subdirectory in the working directory os.chdir(cpth) # build triangle and makefile assert (pymake.build_apps( target, clean=False, pymake_object=pm) == 0), "could not build {}".format(target) if os.path.isfile(os.path.join(cpth, "makefile")): print("cleaning with GNU make") # clean prior to make print("clean {} with makefile".format(target)) success, buff = flopy.run_model( "make", None, cargs="clean", model_ws=cpth, report=True, normal_msg="rm -rf ./triangle", silent=False, ) # build triangle with makefile if success: print("build {} with makefile".format(target)) success, buff = flopy.run_model( "make", None, model_ws=cpth, report=True, normal_msg="cc -O2 -o triangle ./obj_temp/triangle.o", silent=False, ) # finalize Pymake object pm.finalize() # return to starting directory os.chdir(cwd) assert os.path.isfile(os.path.join( cpth, target)), "could not build {} with makefile".format(target) return
def download_mf6_examples(verbose=False): """Download mf6 examples and return location of folder""" target = "mf6" pm = pymake.Pymake(verbose=True) pm.target = target # download the modflow 6 release pm.download_target(target, download_path=temp_pth) assert pm.download, "could not download {} distribution".format(target) # get program dictionary prog_dict = pymake.usgs_program_data.get_target(target) # set path to example temp_download_dir = os.path.join(temp_pth, prog_dict.dirname) temp_dir = os.path.join(temp_download_dir, "examples") print("copying files to...{}".format(mf6_exdir)) shutil.copytree(temp_dir, mf6_exdir) print("removing...{} directory".format(temp_download_dir)) shutil.rmtree(temp_download_dir) return os.path.abspath(mf6_exdir)
def build_mf6(srcdir=None, appdir=None): pm = pymake.Pymake() pm.target = f"mf6{eext}" if srcdir is None: srcdir = os.path.join("..", "src") pm.srcdir = srcdir if appdir is None: appdir = os.path.join("..", "bin") pm.appdir = appdir pm.include_subdirs = True pm.inplace = True pm.makeclean = True # reset compiler based on environmental variable, if defined pm.fc = get_compiler_envvar(pm.fc) # add strict flags if gfortran is being used if pm.fc == "gfortran": pm.fflags = strict_flags # build the application pm.build() msg = "{} does not exist.".format(pm.target) assert pm.returncode == 0, msg
def build_mf6(): pm = pymake.Pymake() pm.target = "mf6" + eext pm.srcdir = os.path.join('..', 'src') pm.appdir = os.path.join('..', 'bin') pm.include_subdirs = True pm.inplace = True if pm.fc == "gfortran": pm.fflags = strict_flags # build the application pm.build() msg = '{} does not exist.'.format(pm.target) assert pm.returncode == 0, msg
def build_zbud6(): pm = pymake.Pymake() pm.target = "zbud6" + eext pm.srcdir = os.path.join('..', 'utils', 'zonebudget', 'src') pm.appdir = os.path.join('..', 'bin') pm.extrafiles = os.path.join('..', 'utils', 'zonebudget', 'pymake', 'extrafiles.txt') pm.inplace = True if pm.fc == "gfortran": pm.fflags = strict_flags # build the application pm.build() msg = '{} does not exist.'.format(pm.target) assert pm.returncode == 0, msg
def build_mf6_so(): pm = pymake.Pymake() pm.target = "libmf6" + soext pm.srcdir = os.path.join('..', 'srcbmi') pm.srcdir2 = os.path.join('..', 'src') pm.appdir = os.path.join('..', 'bin') pm.excludefiles = [os.path.join(pm.srcdir2, 'mf6.f90')] pm.include_subdirs = True pm.sharedobject = True pm.inplace = True if pm.fc == "gfortran": pm.fflags = strict_flags # build the application pm.build() msg = '{} does not exist.'.format(pm.target) assert pm.returncode == 0, msg
def build_mf6_makefile(): with cwd(os.path.join("..", "make")): pm = pymake.Pymake() pm.target = "mf6" pm.srcdir = os.path.join("..", "src") pm.appdir = os.path.join("..", "bin") pm.include_subdirs = True pm.inplace = True pm.dryrun = True pm.makefile = True pm.networkx = True # build the application pm.build() msg = f"could not create makefile for '{pm.target}'." assert pm.returncode == 0, msg return
def rebuild_mf6_release(): pm = pymake.Pymake(verbose=True) pm.target = "mf6" pm.appdir = ebindir download_pth = os.path.join("temp") target_dict = pymake.usgs_program_data.get_target(pm.target) pm.download_target(pm.target, download_path=download_pth) # Set MODFLOW 6 to compile develop version of the release srcpth = os.path.join(download_pth, target_dict["dirname"], target_dict["srcdir"]) fpth = os.path.join(srcpth, "Utilities", "version.f90") with open(fpth) as f: lines = f.read().splitlines() assert len(lines) > 0, "could not update {}".format(srcpth) f = open(fpth, "w") for line in lines: tag = "IDEVELOPMODE = 0" if tag in line: line = line.replace(tag, "IDEVELOPMODE = 1") f.write("{}\n".format(line)) f.close() # reset compiler based on environmental variable, if defined pm.fc = get_compiler_envvar(pm.fc) # add strict flags if gfortran is being used if pm.fc == "gfortran": pm.fflags = strict_flags # build the release version of MODFLOW 6 pm.build() msg = "{} does not exist.".format(pm.target) assert pm.returncode == 0, msg # finalize the build pm.finalize() return
def build_zbud6_makefile(): with cwd(os.path.join("..", "utils", "zonebudget", "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.inplace = True pm.makeclean = True pm.dryrun = True pm.makefile = True pm.networkx = True # build the application pm.build() msg = f"could not create makefile for '{pm.target}'." assert pm.returncode == 0, msg return
def build_zbud6(): pm = pymake.Pymake() pm.target = "zbud6" + eext pm.srcdir = os.path.join("..", "utils", "zonebudget", "src") pm.appdir = os.path.join("..", "bin") pm.extrafiles = os.path.join("..", "utils", "zonebudget", "pymake", "extrafiles.txt") pm.inplace = True pm.makeclean = True # reset compiler based on environmental variable, if defined pm.fc = get_compiler_envvar(pm.fc) # add strict flags if gfortran is being used if pm.fc == "gfortran": pm.fflags = strict_flags # build the application pm.build() msg = "{} does not exist.".format(pm.target) assert pm.returncode == 0, msg
def build_mf6_so(): pm = pymake.Pymake(verbose=True) pm.target = "libmf6" + soext pm.srcdir = os.path.join("..", "srcbmi") pm.srcdir2 = os.path.join("..", "src") pm.appdir = os.path.join("..", "bin") pm.excludefiles = [os.path.join(pm.srcdir2, "mf6.f90")] pm.include_subdirs = True pm.inplace = True pm.makeclean = True # reset compiler based on environmental variable, if defined pm.fc = get_compiler_envvar(pm.fc) # add strict flags if gfortran is being used if pm.fc == "gfortran": pm.fflags = strict_flags # build the application pm.build() msg = "{} does not exist.".format(pm.target) assert pm.returncode == 0, msg
"fhb.nam", "twri.nam", "ibs2k.nam", "swtex4.nam", "twrihfb.nam", "l1a2k.nam", "tc2hufv4.nam", "twrip.nam", "l1b2k.nam", "test1ss.nam", ] # add path to name_files for idx, namefile in enumerate(name_files): name_files[idx] = os.path.join(expth, namefile) pm = pymake.Pymake(verbose=True) pm.target = target pm.appdir = dstpth pm.fflags = "-O3" pm.cflags = "-O3" def run_mf2005(namefile, regression=True): """ Run the simulation. """ if namefile is not None: # Set root as the directory name where namefile is located testname = pymake.get_sim_name(namefile, rootpth=expth)[0]
#! /usr/bin/env python try: import pymake except: msg = 'Error. Pymake package is not available.\n' msg += 'Try installing using the following command:\n' msg += ' pip install https://github.com/modflowpy/pymake/zipball/master' print(msg) raise Exception() import os pmobj = pymake.Pymake() pmobj.target = "zbud6" pmobj.appdir = os.path.join("..", "..", "..", "bin") pmobj.srcdir = os.path.join("..", "src") pmobj.extrafiles = os.path.join('extrafiles.txt') pmobj.cc = None pmobj.subdirs = True pmobj.inplace = True pmobj.verbose = True pmobj.makeclean = True pmobj.build()
import pymake pmobj = pymake.Pymake(verbose=True) pmobj.target = "gsflow" pmobj.appdir = "../bin" pmobj.srcdir = "./" pmobj.include_subdirs = True pmobj.inplace = True pmobj.makeclean = True pmobj.build()