pymake.pymake module

Pymake() class to make a binary executable for a FORTRAN, C, or C++ program, such as MODFLOW 6.

An example of how to build MODFLOW-2005 from source files in the official release downloaded from the USGS using Intel compilers is:

import pymake

# create an instance of the Pymake object
pm = pymake.Pymake(verbose=True)

# reset select pymake settings
pm.target = "mf2005"
pm.appdir = "../bin"
pm.fc = "ifort"
pm.cc = "icc"
pm.fflags = "-O3 -fbacktrace"
pm.cflags = "-O3"

# download the target
pm.download_target(pm.target, download_path="temp")

# build the target
pm.build()

# clean up downloaded files
pm.finalize()

All other settings not specified in the script would be based on command line arguments or default values. The same Pymake() object could be used to compile MODFLOW 6 by appending the following code to the previous code block:

# reset the target
pm.target = "mf6"

# download the target
pm.download_target(pm.target, download_path="temp")

# build the target
pm.build()

# clean up downloaded files
pm.finalize()

The Intel compilers and fortran flags defined previously would be used when MODFLOW 6 was built.

class Pymake(name='pymake', verbose=None)[source]

Bases: object

Pymake class for interacting with pymake functionality. This is essentially a wrapper for all of the pymake functions needed to download and build a target.

argv_reset_settings(args)[source]

Reset settings using command line arguments

Parameters

args (Namespace object) – reset self.variables using command line arguments

build(target=None, srcdir=None, modify_exe_name=False)[source]

Build the target

Parameters
  • target (str) – target name. If target is None self.target is used. (default is None)

  • srcdir (str) – path to directory with source files. (default is None)

  • modify_exe_name (bool) – boolean that determines if the target name can be modified to include precision (dbl) and debugging (d) indicators.

compress_targets()[source]

Compress targets in build_targets list.

download_setup(target, url=None, download_path='.', verify=True, timeout=30)[source]

Setup download

Parameters
  • target (str) – target name

  • url (str) – url of asset

  • download_path (str) – path where the asset will be saved

  • verify (bool) – boolean defining ssl verification

  • timeout (int) – download timeout in seconds (default is 30)

download_target(target, url=None, download_path='.', verify=True, timeout=30)[source]

Setup and download url

Parameters
  • target (str) – target name

  • url (str) – url of asset

  • download_path (str) – path where the asset will be saved

  • verify (bool) – boolean defining ssl verification

  • timeout (int) – download timeout in seconds (default is 30)

Returns

success – boolean flag indicating download success

Return type

bool

download_url()[source]

Download files from the url

Returns

success – boolean flag indicating download success

Return type

bool

finalize()[source]

Finalize Pymake class

reset(target)[source]

Reset PyMake object variables for a target

Parameters

target (str) – target name

set_build_target_bool(target=None)[source]

Evaluate if the executable exists and if so and the command line argument –keep is specified then the executable is not built.

Parameters

target (str) – target name. If target is None self.target will be used. (default is None)

Returns

build – boolean indicating if the executable should be built

Return type

bool

update_build_targets()[source]

Add target to build_targets list if it is not in the list

update_target(target, modify_target=False)[source]

Update target name with executable extension on Windows and based on pymake settings.

Parameters
  • target (str) – target name

  • modify_target (bool) – boolean indicating if the target name can be modified based on pymake double and debug settings (default is False)

Returns

target – updated target name

Return type

str