Beispiel #1
0
def run_make(targets):
    import pymake
    options = ['-s']
    try:
        pymake.main(options + targets)
    except (pymake.PymakeTypeError, pymake.PymakeKeyError):
        print("Caught exception while parsing makefile.")
Beispiel #2
0
def make_mt3d():

    # get current directory
    dstpth = os.path.join('temp')
    if not os.path.exists(dstpth):
        os.makedirs(dstpth)
    os.chdir(dstpth)

    # Download the MT3D distribution
    url = "http://hydro.geo.ua.edu/mt3d/mt3dms_530.exe"
    download_and_unzip(url)

    # Set srcdir and remove unneeded files
    srcdir = os.path.join('src', 'true-binary')
    dlist = ['automake.fig', 'mt3dms5b.exe']
    for d in dlist:
        dname = os.path.join(srcdir, d)
        if os.path.isfile(dname):
            print('Removing ', dname)
            os.remove(dname)

    # Replace the getcl command with getarg
    f1 = open(os.path.join(srcdir, 'mt3dms5.for'), 'r')
    f2 = open(os.path.join(srcdir, 'mt3dms5.for.tmp'), 'w')
    for line in f1:
        f2.write(line.replace('CALL GETCL(FLNAME)', 'CALL GETARG(1,FLNAME)'))
    f1.close()
    f2.close()
    os.remove(os.path.join(srcdir, 'mt3dms5.for'))
    shutil.move(os.path.join(srcdir, 'mt3dms5.for.tmp'),
                os.path.join(srcdir, 'mt3dms5.for'))

    # Replace filespec with standard fortran
    l = '''
          CHARACTER*20 ACCESS,FORM,ACTION(2)
          DATA ACCESS/'STREAM'/
          DATA FORM/'UNFORMATTED'/
          DATA (ACTION(I),I=1,2)/'READ','READWRITE'/
    '''
    fn = os.path.join(srcdir, 'filespec.inc')
    f = open(fn, 'w')
    f.write(l)
    f.close()

    target = 'mt3dms'
    pymake.main(srcdir, target, 'gfortran', 'gcc', makeclean=True,
                expedite=False, dryrun=False, double=False, debug=False)

    # Clean up unneeded folders
    dlist = ['bin', 'doc', 'examples', 'src', 'utility']
    for d in dlist:
        dname = d
        if os.path.isdir(dname):
            print('Removing ', dname)
            shutil.rmtree(dname)

    # Clean up unneeded files
    for f in ['ReadMe_MT3DMS.pdf', 'upgrade.pdf']:
        print('Removing {}'.format(f))
        os.remove(f)
Beispiel #3
0
def build_mf5to6():
    # define default compilers
    fc = "gfortran"
    cc = None

    # determine if fortran compiler specified on the command line
    for idx, arg in enumerate(sys.argv):
        if arg == '-fc':
            fc = sys.argv[idx + 1]
            break

    # set source and target paths
    srcdir = os.path.join('..', 'utils', 'mf5to6', 'src')
    target = os.path.join('..', 'bin', 'mf5to6')
    target += eext
    extrafiles = os.path.join('..', 'utils', 'mf5to6', 'pymake',
                              'extrafiles.txt')

    # build modflow 5 to 6 converter
    pymake.main(srcdir,
                target,
                fc=fc,
                cc=cc,
                include_subdirs=True,
                extrafiles=extrafiles,
                inplace=True)

    msg = '{} does not exist.'.format(relpath_fallback(target))
    assert os.path.isfile(target), msg
Beispiel #4
0
def make_mflgr():
    # get current directory
    dstpth = os.path.join('temp')
    if not os.path.exists(dstpth):
        os.makedirs(dstpth)
    os.chdir(dstpth)

    # Download the MODFLOW-LGR distribution
    url = "https://water.usgs.gov/ogw/modflow-lgr/modflow-lgr-v2.0.0/mflgrv2_0_00.zip"
    download_and_unzip(url)

    dirname = 'mflgr.2_0'
    srcdir = os.path.join(dirname, 'src')
    target = 'mflgrdbl'

    print('Present working directory: ', os.getcwd())
    pymake.main(srcdir,
                target,
                'gfortran',
                'gcc',
                makeclean=True,
                expedite=False,
                dryrun=False,
                double=True,
                debug=False)

    assert os.path.isfile(target), 'Target does not exist.'
Beispiel #5
0
def test_build_mf5to6():
    # determine if app should be build
    for idx, arg in enumerate(sys.argv):
        if arg.lower() == '--nomf5to6':
            txt = 'Command line cancel of MODFLOW 5 to 6 converter build'
            print(txt)
            return

    # set source and target paths
    srcdir = os.path.join('..', 'utils', 'mf5to6', 'src')
    target = os.path.join('..', 'bin', 'mf5to6')
    target += eext
    extrafiles = os.path.join('..', 'utils', 'mf5to6', 'pymake',
                              'extrafiles.txt')
    fc, cc = pymake.set_compiler('mf6')

    # build modflow 5 to 6 converter
    pymake.main(srcdir,
                target,
                fc=fc,
                cc=cc,
                include_subdirs=True,
                extrafiles=extrafiles)

    msg = '{} does not exist.'.format(relpath_fallback(target))
    assert os.path.isfile(target), msg
Beispiel #6
0
def make_mf2005():
    # get current directory
    dstpth = os.path.join('temp')
    if not os.path.exists(dstpth):
        os.makedirs(dstpth)
    os.chdir(dstpth)

    # Download the MODFLOW-2005 distribution
    url = "https://water.usgs.gov/ogw/modflow/MODFLOW-2005_v1.12.00/MF2005.1_12u.zip"
    download_and_unzip(url)

    # Set dir name
    dirname = 'MF2005.1_12u'
    srcdir = os.path.join(dirname, 'src')

    # make single precision version
    target = 'mf2005'
    pymake.main(srcdir, target, 'gfortran', 'gcc', makeclean=True,
                expedite=False, dryrun=False, double=False, debug=False)

    assert os.path.isfile(target), 'Target does not exist.'

    # make double precision version
    target = 'mf2005dbl'
    pymake.main(srcdir, target, 'gfortran', 'gcc', makeclean=True,
                expedite=False, dryrun=False, double=True, debug=False)

    assert os.path.isfile(target), 'Target does not exist.'

    # Clean up downloaded directory
    if os.path.isdir(dirname):
        shutil.rmtree(dirname)
Beispiel #7
0
def make_mfnwt():

    # Note, this script does not work yet due to some non-standard Fortran
    # in one or more of the source files.

    # get current directory
    dstpth = os.path.join('temp')
    if not os.path.exists(dstpth):
        os.makedirs(dstpth)
    os.chdir(dstpth)

    # Remove the existing directory if it exists
    dirname = 'MODFLOW-NWT_1.0.9'
    if os.path.isdir(dirname):
        shutil.rmtree(dirname)

    # Download the MODFLOW-NWT distribution
    url = "http://water.usgs.gov/ogw/modflow-nwt/MODFLOW-NWT-v1.0.9/MODFLOW-NWT_1.0.9.zip"
    download_and_unzip(url)

    # Remove the parallel and serial folders from the source directory
    srcdir = os.path.join('MODFLOW-NWT_1.0.9', 'src')
    target = 'mfnwt'

    pymake.main(srcdir, target, 'gfortran', 'gcc', makeclean=True,
                expedite=False, dryrun=False, double=False, debug=False)

    assert os.path.isfile(target), 'Target does not exist.'

    # Clean up
    dirname = 'MODFLOW-NWT_1.0.9'
    if os.path.isdir(dirname):
        shutil.rmtree(dirname)
Beispiel #8
0
def test_build_modflow6():
    # determine if app should be build
    for idx, arg in enumerate(sys.argv):
        if arg.lower() == '--nomf6':
            txt = 'Command line cancel of MODFLOW 6 build'
            print(txt)
            return

    # set source and target paths
    srcdir = os.path.join('..', 'src')
    target = os.path.join('..', 'bin', 'mf6')
    target += eext
    fc, cc = pymake.set_compiler('mf6')

    fflags = None
    if fc == 'gfortran':
        # some flags to check for errors in the code
        # add -Werror for compilation to terminate if errors are found
        fflags = ('-Wtabs -Wline-truncation -Wunused-label '
                  '-Wunused-variable -pedantic -std=f2008')

    pymake.main(srcdir,
                target,
                fc=fc,
                cc=cc,
                include_subdirs=True,
                fflags=fflags)

    msg = '{} does not exist.'.format(relpath_fallback(target))
    assert os.path.isfile(target), msg
Beispiel #9
0
def compile_code():
    # Remove the existing mfusg directory if it exists
    if os.path.isdir(mp6pth):
        shutil.rmtree(mp6pth)

    # Download the MODPATH 6 distribution
    url = "http://water.usgs.gov/ogw/modpath/modpath.6_0_01.zip"
    pymake.download_and_unzip(url, pth=dstpth)

    fname1 = os.path.join(srcpth, 'MP6Flowdata.for')
    f = open(fname1, 'r')

    fname2 = os.path.join(srcpth, 'MP6Flowdata_mod.for')
    f2 = open(fname2, 'w')
    for line in f:
        line = line.replace('CD.QX2', 'CD%QX2')
        f2.write(line)
    f.close()
    f2.close()
    os.remove(fname1)

    # compile MODPATH 6
    pymake.main(srcpth, target, 'gfortran', 'gcc', makeclean=True,
                expedite=False, dryrun=False, double=False, debug=False)
    assert os.path.isfile(target), 'Target does not exist.'
Beispiel #10
0
def build_mf6_dll(mode, onlytouched):

    fc = 'gfortran'
    cc = 'gcc'

    srcdir = os.path.join('..', 'srcbmi')
    comdir = os.path.join('..', 'src')
    excludefiles = [os.path.join(comdir, 'mf6.f90')]

    if mode == "-release":
        target = os.path.join('..', 'bin', 'libmf6.dll')
        fflags = ('-Wtabs -Wline-truncation -Wunused-label '
                  '-Wunused-variable -pedantic -std=f2008')
    else:
        target = os.path.join('..', 'bin', 'libmf6d.dll')
        fflags = ('-Wtabs -Wline-truncation -Wunused-label '
                  '-Wunused-variable -pedantic -std=f2008 '
                  '-O0 -g')

    pymake.main(srcdir,
                target,
                fc=fc,
                cc=cc,
                include_subdirs=True,
                fflags=fflags,
                srcdir2=comdir,
                excludefiles=excludefiles,
                sharedobject=True,
                makeclean=not onlytouched,
                expedite=onlytouched,
                inplace=True)
Beispiel #11
0
def make_mf6():
    # get current directory
    dstpth = os.path.join('temp')
    if not os.path.exists(dstpth):
        os.makedirs(dstpth)
    os.chdir(dstpth)

    # Remove the existing mf6.0.2 directory if it exists
    dirname = 'mf6.0.2'
    if os.path.isdir(dirname):
        shutil.rmtree(dirname)

    url = 'https://water.usgs.gov/ogw/modflow/{0}.zip'.format(dirname)
    download_and_unzip(url)

    # Set src and target
    srcdir = os.path.join(dirname, 'src')
    target = 'mf6'

    pymake.main(srcdir, target, 'gfortran', 'gcc', makeclean=True,
                expedite=False, dryrun=False, double=False, debug=False,
                include_subdirs=True)

    assert os.path.isfile(target), 'Target does not exist.'

    # Remove the existing mf6.0.1 directory if it exists
    if os.path.isdir(dirname):
        shutil.rmtree(dirname)
Beispiel #12
0
def build_mf6(mode, onlytouched):

    fc = 'gfortran'
    cc = 'gcc'

    srcdir = os.path.join('..', 'src')
    if mode == "-release":
        # release mode options:
        target = '../bin/mf6.exe'
        fflags = ('-Wtabs -Wline-truncation -Wunused-label '
                  '-Wunused-variable -pedantic -std=f2008')
    else:
        # debug:
        target = '../bin/mf6d.exe'
        fflags = ('-Wtabs -Wline-truncation -Wunused-label '
                  '-Wunused-variable -pedantic -std=f2008 '
                  ' -O0 -g')

    pymake.main(srcdir,
                target,
                fc=fc,
                cc=cc,
                include_subdirs=True,
                fflags=fflags,
                makeclean=not onlytouched,
                expedite=onlytouched,
                inplace=True)
Beispiel #13
0
def compile_code():
    # Remove the existing mfusg directory if it exists
    if os.path.isdir(mfusgpth):
        shutil.rmtree(mfusgpth)

    # Download the MODFLOW-USG distribution
    url = 'https://water.usgs.gov/ogw/mfusg/mfusg.1_4.zip'
    pymake.download_and_unzip(url, pth=dstpth)

    # Remove extraneous source directories
    dlist = ['zonebudusg', 'serial']
    for d in dlist:
        dname = os.path.join(srcpth, d)
        if os.path.isdir(dname):
            print('Removing ', dname)
            shutil.rmtree(os.path.join(srcpth, d))

    # compile MODFLOW-USG
    pymake.main(srcpth,
                target,
                'gfortran',
                'gcc',
                makeclean=True,
                expedite=False,
                dryrun=False,
                double=False,
                debug=False)
    assert os.path.isfile(target), 'Target does not exist.'
Beispiel #14
0
def make_mfnwt():

    # get current directory
    dstpth = os.path.join('temp')
    if not os.path.exists(dstpth):
        os.makedirs(dstpth)
    os.chdir(dstpth)

    # Remove the existing directory if it exists
    dirname = 'MODFLOW-NWT_1.1.4'
    if os.path.isdir(dirname):
        shutil.rmtree(dirname)

    # Download the MODFLOW-NWT distribution
    url = "https://water.usgs.gov/ogw/modflow-nwt/{0}.zip".format(dirname)
    download_and_unzip(url)

    # Remove the parallel and serial folders from the source directory
    srcdir = os.path.join(dirname, 'src')
    target = 'mfnwt'

    pymake.main(srcdir, target, 'gfortran', 'gcc', makeclean=True,
                expedite=False, dryrun=False, double=False, debug=False)

    assert os.path.isfile(target), 'Target does not exist.'

    # Clean up
    if os.path.isdir(dirname):
        shutil.rmtree(dirname)
Beispiel #15
0
def test_compile_prev():
    # Compile reference version of the program from the source.

    # Remove the existing distribution directory if it exists
    dir_previous = config.dir_previous
    if os.path.isdir(dir_previous):
        print('Removing folder ' + dir_previous)
        shutil.rmtree(dir_previous)

    # Setup variables
    url = config.url_previous
    srcdir = config.srcdir_previous
    target = config.target_previous

    # Download the MODFLOW-2005 distribution
    pymake.download_and_unzip(url, pth=config.testdir)

    # compile
    pymake.main(srcdir,
                target,
                'gfortran',
                'gcc',
                makeclean=True,
                expedite=False,
                dryrun=False,
                double=False,
                debug=False,
                include_subdirs=False)

    assert os.path.isfile(target), 'Target {} does not exist.'.format(target)

    return
Beispiel #16
0
def test_help_version():
    """Test help and version"""
    for i in ('-h', '--help', '-v', '--version'):
        try:
            main([i])
        except SystemExit:
            pass
Beispiel #17
0
def test_build_triangle(keep=True):
    if pymake is None:
        return
    starget = 'TRIANGLE'
    exe_name = 'triangle'
    dirname = 'triangle'
    url = "http://www.netlib.org/voronoi/{}.zip".format(dirname)

    print('Determining if {} needs to be built'.format(starget))
    if platform.system().lower() == 'windows':
        exe_name += '.exe'

    exe_exists = flopy.which(exe_name)
    if exe_exists is not None and keep:
        print('No need to build {}'.format(starget) +
              ' since it exists in the current path')
        return

    # get current directory
    cpth = os.getcwd()

    # create temporary path
    dstpth = os.path.join('tempbin', 'triangle')
    print('create...{}'.format(dstpth))
    if not os.path.exists(dstpth):
        os.makedirs(dstpth)
    os.chdir(dstpth)

    pymake.download_and_unzip(url)

    srcdir = 'src'
    os.mkdir(srcdir)
    shutil.move('triangle.c', 'src/triangle.c')
    shutil.move('triangle.h', 'src/triangle.h')

    fct, cct = set_compiler(starget)
    pymake.main(srcdir, 'triangle', fct, cct)

    # move the file
    src = os.path.join('.', exe_name)
    dst = os.path.join(bindir, exe_name)
    try:
        shutil.move(src, dst)
    except:
        print('could not move {}'.format(exe_name))

    # change back to original path
    os.chdir(cpth)

    # Clean up downloaded directory
    print('delete...{}'.format(dstpth))
    if os.path.isdir(dstpth):
        shutil.rmtree(dstpth)

    # make sure the gridgen was built
    msg = '{} does not exist.'.format(os.path.relpath(dst))
    assert os.path.isfile(dst), msg

    return
Beispiel #18
0
def compile_code():
    # Remove the existing modpath6 directory if it exists
    if os.path.isdir(mp6pth):
        shutil.rmtree(mp6pth)

    # Download the MODPATH 6 distribution
    url = "https://water.usgs.gov/ogw/modpath/archive/modpath_v6.0.01/modpath.6_0_01.zip"
    pymake.download_and_unzip(url, pth=dstpth)

    # start of edit a few files so it can compile with gfortran
    # file 1
    fname1 = os.path.join(srcpth, 'MP6Flowdata.for')
    f = open(fname1, 'r')

    bigline = 'CB%BALANCE = ABS(100.0*CB%QRESIDUAL/CB%QAVE)'
    newline = '      IF (ABS(CB%QAVE) > 0.) THEN\n' + \
              '        CB%BALANCE = ABS(100.0*CB%QRESIDUAL/CB%QAVE)\n' + \
              '      ELSE\n' + \
              '        CB%BALANCE = 0.\n' + \
              '      END IF\n'

    fname2 = os.path.join(srcpth, 'MP6Flowdata_mod.for')
    f2 = open(fname2, 'w')
    for line in f:
        line = line.replace('CD.QX2', 'CD%QX2')
        if bigline in line:
            line = newline
        f2.write(line)
    f.close()
    f2.close()
    os.remove(fname1)

    # file 2
    fname1 = os.path.join(srcpth, 'MP6MPBAS1.for')
    f = open(fname1, 'r')

    fname2 = os.path.join(srcpth, 'MP6MPBAS1_mod.for')
    f2 = open(fname2, 'w')
    for line in f:
        line = line.replace('MPBASDAT(IGRID)%NCPPL=NCPPL',
                            'MPBASDAT(IGRID)%NCPPL=>NCPPL')
        f2.write(line)
    f.close()
    f2.close()
    os.remove(fname1)
    # end of edit a few files so it can compile with gfortran

    # compile MODPATH 6
    pymake.main(srcpth,
                target,
                'gfortran',
                'gcc',
                makeclean=True,
                expedite=False,
                dryrun=False,
                double=False,
                debug=False)
    assert os.path.isfile(target), 'Target does not exist.'
Beispiel #19
0
def test_invalid_alias():
    """Test invalid alias"""
    try:
        main(['-f', fname, 'foo'])
    except PymakeKeyError as e:
        if 'foo' not in str(e):
            raise
    else:
        raise PymakeKeyError('foo')
Beispiel #20
0
def test_ignore_errors():
    """Test --ignore-errors"""
    try:
        main(['-s', '-f', fname, 'err'])
    except OSError:
        pass  # test passed if file not found
    else:
        raise PymakeTypeError('err')

    main(['-s', '-i', '-f', fname, 'err'])
Beispiel #21
0
def build_target(starget, exe_name, url, dirname, srcname='src',
                 replace_function=None, verify=True, keep=True,
                 dble=dbleprec, include_subdirs=False):
    print('Determining if {} needs to be built'.format(starget))
    if platform.system().lower() == 'windows':
        exe_name += '.exe'

    exe_exists = flopy.which(exe_name)
    if exe_exists is not None and keep:
        print('No need to build {}'.format(starget) +
              ' since it exists in the current path')
        return

    fct, cct = set_compiler(starget)

    # set up target
    target = os.path.abspath(os.path.join(bindir, exe_name))

    # get current directory
    cpth = os.getcwd()

    # create temporary path
    dstpth = os.path.join('tempbin')
    print('create...{}'.format(dstpth))
    if not os.path.exists(dstpth):
        os.makedirs(dstpth)
    os.chdir(dstpth)

    # Download the distribution
    pymake.download_and_unzip(url, verify=verify)

    # Set srcdir name
    srcdir = os.path.join(dirname, srcname)

    if replace_function is not None:
        replace_function(srcdir)

    # compile code
    print('compiling...{}'.format(os.path.relpath(target)))
    pymake.main(srcdir, target, fct, cct, makeclean=True,
                expedite=False, dryrun=False, double=dble, debug=False,
                include_subdirs=include_subdirs)

    # change back to original path
    os.chdir(cpth)

    # Clean up downloaded directory
    print('delete...{}'.format(dstpth))
    if os.path.isdir(dstpth):
        shutil.rmtree(dstpth)

    msg = '{} does not exist.'.format(os.path.relpath(target))
    assert os.path.isfile(target), msg

    return
Beispiel #22
0
def test_build_modflow():
    starget = 'MODFLOW-2005'

    fct, cct = set_compiler()

    # set up target
    target = os.path.abspath(os.path.join(ebindir, 'mf2005dbl'))
    target += eext

    rebuild = rebuild_exe(target, starget)
    if not rebuild:
        return

    # get current directory
    cpth = os.getcwd()

    # create temporary path
    dstpth = os.path.join('tempbin')
    print('create...{}'.format(dstpth))
    if not os.path.exists(dstpth):
        os.makedirs(dstpth)
    os.chdir(dstpth)

    # Set dir name
    dirname = mf2005dir
    srcdir = os.path.join(dirname, 'src')

    # Download the MODFLOW-2005 distribution
    url = mf2005url
    pymake.download_and_unzip(url)

    # compile code
    print('compiling...{}'.format(os.path.relpath(target)))
    pymake.main(srcdir,
                target,
                fct,
                cct,
                makeclean=True,
                expedite=False,
                dryrun=False,
                double=True,
                debug=False)

    msg = '{} does not exist.'.format(os.path.relpath(target))
    assert os.path.isfile(target), msg

    # change back to original path
    os.chdir(cpth)

    # Clean up downloaded directory
    print('delete...{}'.format(dstpth))
    if os.path.isdir(dstpth):
        shutil.rmtree(dstpth)

    return
Beispiel #23
0
def make_swtv4():

    # To compile SEAWAT on mac or linux:
    # 1. The starting source folder should not have the parallel and serial folders
    # 3. The program needs to be compiled in double precision.

    # get current directory
    dstpth = os.path.join('temp')
    if not os.path.exists(dstpth):
        os.makedirs(dstpth)
    os.chdir(dstpth)

    # Remove the existing directory if it exists
    dirname = 'swt_v4_00_05'
    if os.path.isdir(dirname):
        shutil.rmtree(dirname)

    # Download the SEAWAT distribution
    url = "http://water.usgs.gov/ogw/seawat/swt_v4_00_05.zip"
    download_and_unzip(url)

    # Remove the parallel and serial folders from the source directory
    srcdir = os.path.join(dirname, 'source')
    dlist = ['parallel', 'serial']
    for d in dlist:
        dname = os.path.join(srcdir, d)
        if os.path.isdir(dname):
            print('Removing ', dname)
            shutil.rmtree(os.path.join(srcdir, d))

    # Replace filespec with standard fortran
    l = '''
          CHARACTER*20 ACCESS,FORM,ACTION(2)
          DATA ACCESS/'STREAM'/
          DATA FORM/'UNFORMATTED'/
          DATA (ACTION(I),I=1,2)/'READ','READWRITE'/
    '''
    fn = os.path.join(srcdir, 'filespec.inc')
    f = open(fn, 'w')
    f.write(l)
    f.close()

    target = 'swtv4'
    pymake.main(srcdir, target, 'gfortran', 'gcc', makeclean=True,
                expedite=False, dryrun=False, double=True, debug=False)

    assert os.path.isfile(target), 'Target does not exist.'

    # Remove the existing directory if it exists
    dirname = 'swt_v4_00_05'
    if os.path.isdir(dirname):
        shutil.rmtree(dirname)

    return
Beispiel #24
0
def make_swtv4():

    # To compile SEAWAT on mac or linux:
    # 1. The starting source folder should not have the parallel and serial folders
    # 3. The program needs to be compiled in double precision.

    # get current directory
    dstpth = os.path.join('temp')
    if not os.path.exists(dstpth):
        os.makedirs(dstpth)
    os.chdir(dstpth)

    # Remove the existing directory if it exists
    dirname = 'swt_v4_00_05'
    if os.path.isdir(dirname):
        shutil.rmtree(dirname)

    # Download the SEAWAT distribution
    url = "http://water.usgs.gov/ogw/seawat/swt_v4_00_05.zip"
    download_and_unzip(url)

    # Remove the parallel and serial folders from the source directory
    srcdir = os.path.join(dirname, 'source')
    dlist = ['parallel', 'serial']
    for d in dlist:
        dname = os.path.join(srcdir, d)
        if os.path.isdir(dname):
            print('Removing ', dname)
            shutil.rmtree(os.path.join(srcdir, d))

    # Replace filespec with standard fortran
    l = '''
          CHARACTER*20 ACCESS,FORM,ACTION(2)
          DATA ACCESS/'STREAM'/
          DATA FORM/'UNFORMATTED'/
          DATA (ACTION(I),I=1,2)/'READ','READWRITE'/
    '''
    fn = os.path.join(srcdir, 'FILESPEC.INC')
    f = open(fn, 'w')
    f.write(l)
    f.close()

    target = 'swtv4'
    pymake.main(srcdir, target, 'gfortran', 'gcc', makeclean=True,
                expedite=False, dryrun=False, double=True, debug=False)

    assert os.path.isfile(target), 'Target does not exist.'

    # Remove the existing directory if it exists
    dirname = 'swt_v4_00_05'
    if os.path.isdir(dirname):
        shutil.rmtree(dirname)

    return
Beispiel #25
0
def test_compile_dev():
    # Compile development version of the program from source.

    # Compile
    target = config.target
    pymake.main(config.srcdir, target, config.fc, 'gcc', makeclean=True,
                expedite=False, dryrun=False, double=False, debug=False,
                include_subdirs=False, arch=config.target_arch)

    # Ensure target has been built
    assert os.path.isfile(target) is True, 'Target {} does not exist.'.format(target)

    return
Beispiel #26
0
def compile_code():
    # Remove the existing mfusg directory if it exists
    if os.path.isdir(mflgrpth):
        shutil.rmtree(mflgrpth)

    # Download the MODFLOW-LGR distribution
    url = "http://water.usgs.gov/ogw/modflow-lgr/modflow-lgr-v2.0.0/mflgrv2_0_00.zip"
    pymake.download_and_unzip(url, pth=dstpth)

    # compile MODFLOW-LGR
    pymake.main(srcpth, target, 'gfortran', 'gcc', makeclean=True,
                expedite=False, dryrun=False, double=False, debug=False)
    assert os.path.isfile(target), 'Target does not exist.'
    return
Beispiel #27
0
def compile_code():
    # Remove the existing swt_v4_00_05 directory if it exists
    if os.path.isdir(swtpth):
        shutil.rmtree(swtpth)

    # Download the SEAWAT distribution
    url = 'https://water.usgs.gov/ogw/seawat/swt_v4_00_05.zip'
    pymake.download_and_unzip(url, pth=dstpth)

    # Remove the parallel and serial folders from the source directory
    dlist = ['parallel', 'serial']
    for d in dlist:
        dname = os.path.join(srcpth, d)
        if os.path.isdir(dname):
            print('Removing ', dname)
            shutil.rmtree(os.path.join(srcpth, d))

    # Replace filespec with standard fortran
    l = "      CHARACTER*20 ACCESS,FORM,ACTION(2)\n" +\
        "      DATA ACCESS/'STREAM'/\n" +\
        "      DATA FORM/'UNFORMATTED'/\n" +\
        "      DATA (ACTION(I),I=1,2)/'READ','READWRITE'/\n"

    fn = os.path.join(srcpth, 'filespec.inc')
    f = open(fn, 'w')
    f.write(l)
    f.close()

    # rename all source files to lower case so compilation doesn't
    # bomb on case-sensitive systems
    srcfiles = os.listdir(srcpth)
    for filename in srcfiles:
        src = os.path.join(srcpth, filename)
        dst = os.path.join(srcpth, filename.lower())
        os.rename(src, dst)

    # compile seawat
    pymake.main(srcpth,
                target,
                'gfortran',
                'gcc',
                makeclean=True,
                expedite=False,
                dryrun=False,
                double=True,
                debug=False,
                include_subdirs=False)

    assert os.path.isfile(target) is True, 'Target does not exist.'
    return
Beispiel #28
0
def compile_code():
    # Remove the existing mf6 directory if it exists
    if os.path.isdir(mf6pth):
        shutil.rmtree(mf6pth)

    # Download the MODFLOW 6 distribution
    url = 'https://water.usgs.gov/ogw/modflow/mf6.0.2.zip'
    pymake.download_and_unzip(url, pth=dstpth)

    # compile MODFLOW 6
    pymake.main(srcpth, target, 'gfortran', 'gcc', makeclean=True,
                expedite=False, dryrun=False, double=False, debug=False,
                include_subdirs=True)
    assert os.path.isfile(target), 'Target does not exist.'
Beispiel #29
0
def main():
    """
    Execute pymake in the current working directory with sys.argv

    An explicit alternative:

    import subprocess
    subprocess.Popen("pymake",
                     stdout=subprocess.PIPE,
                     stderr=subprocess.STDOUT).communicate()[0].decode('utf-8')

    Or just install py-make and run pymake in this directory.
    """
    pymake.main()
Beispiel #30
0
def compile_code():
    # Remove the existing mfusg directory if it exists
    if os.path.isdir(mflgrpth):
        shutil.rmtree(mflgrpth)

    # Download the MODFLOW-LGR distribution
    url = "https://water.usgs.gov/ogw/modflow-lgr/modflow-lgr-v2.0.0/mflgrv2_0_00.zip"
    pymake.download_and_unzip(url, pth=dstpth)

    # compile MODFLOW-LGR
    pymake.main(srcpth, target, 'gfortran', 'gcc', makeclean=True,
                expedite=False, dryrun=False, double=False, debug=False)
    assert os.path.isfile(target), 'Target does not exist.'
    return
Beispiel #31
0
def test_compile_ref():
    # Compile reference version of the program from the source.

    # Remove the existing distribution directory if it exists
    dir_release = config.dir_release
    if os.path.isdir(dir_release):
        print('Removing folder ' + dir_release)
        shutil.rmtree(dir_release)

    # Setup variables
    srcdir = config.srcdir_release
    target = config.target_release

    # Copy MT3DMS into our test folder
    shutil.copytree(config.loc_release, dir_release)

    # Replace the getcl command with getarg
    print(config.srcdir_release)
    f1 = open(os.path.join(config.srcdir_release, 'mt3dms5.for'), 'r')
    f2 = open(os.path.join(config.srcdir_release, 'mt3dms5.for.tmp'), 'w')
    for line in f1:
        f2.write(line.replace('CALL GETCL(FLNAME)', 'CALL GETARG(1,FLNAME)'))
    f1.close()
    f2.close()
    os.remove(os.path.join(config.srcdir_release, 'mt3dms5.for'))
    shutil.move(os.path.join(config.srcdir_release, 'mt3dms5.for.tmp'),
                os.path.join(config.srcdir_release, 'mt3dms5.for'))

    # compile
    pymake.main(srcdir,
                target,
                config.fc,
                'gcc',
                makeclean=True,
                expedite=False,
                dryrun=False,
                double=False,
                debug=False,
                include_subdirs=False,
                arch=config.target_arch)

    assert os.path.isfile(target), 'Target {} does not exist.'.format(target)

    return
Beispiel #32
0
def make_mfusg():

    # get current directory
    dstpth = os.path.join('temp')
    if not os.path.exists(dstpth):
        os.makedirs(dstpth)
    os.chdir(dstpth)

    # Remove the existing mfusg.1_2 directory if it exists
    dirname = 'mfusg.1_2'
    if os.path.isdir(dirname):
        shutil.rmtree(dirname)

    url = 'http://water.usgs.gov/ogw/mfusg/mfusg.1_2_00.zip'
    download_and_unzip(url)

    # Set src and target
    srcdir = os.path.join('mfusg.1_2', 'src')
    target = 'mfusg'

    # Remove extraneous source directories
    dlist = ['zonebudusg', 'serial']
    for d in dlist:
        dname = os.path.join(srcdir, d)
        if os.path.isdir(dname):
            print('Removing ', dname)
            shutil.rmtree(os.path.join(srcdir, d))

    pymake.main(srcdir,
                target,
                'gfortran',
                'gcc',
                makeclean=True,
                expedite=False,
                dryrun=False,
                double=False,
                debug=False)

    assert os.path.isfile(target), 'Target does not exist.'

    # Remove the existing mfusg.1_2 directory if it exists
    dirname = 'mfusg.1_2'
    if os.path.isdir(dirname):
        shutil.rmtree(dirname)
Beispiel #33
0
def make_mf2005():

    # get current directory
    dstpth = os.path.join('temp')
    if not os.path.exists(dstpth):
        os.makedirs(dstpth)
    os.chdir(dstpth)

    # Download the MODFLOW-2005 distribution
    url = "http://water.usgs.gov/ogw/modflow/MODFLOW-2005_v1.11.00/mf2005v1_11_00_unix.zip"
    download_and_unzip(url)

    # Rename Unix to a more reasonable name
    dirname = 'MF2005.1_11u'
    if os.path.isdir(dirname):
        shutil.rmtree(dirname)
    os.rename('Unix', 'MF2005.1_11u')

    # Remove two src folders
    srcdir = os.path.join(dirname, 'src')
    dlist = ['hydprograms', 'mnw1to2']
    for d in dlist:
        dname = os.path.join(srcdir, d)
        if os.path.isdir(dname):
            print('Removing ', dname)
            shutil.rmtree(os.path.join(srcdir, d))

    target = 'mf2005dbl'
    pymake.main(srcdir,
                target,
                'gfortran',
                'gcc',
                makeclean=True,
                expedite=False,
                dryrun=False,
                double=True,
                debug=False)

    assert os.path.isfile(target), 'Target does not exist.'

    dirname = 'MF2005.1_11u'
    if os.path.isdir(dirname):
        shutil.rmtree(dirname)
Beispiel #34
0
def compile_code():
    # Remove the existing swt_v4_00_05 directory if it exists
    if os.path.isdir(swtpth):
        shutil.rmtree(swtpth)

    # Download the SEAWAT distribution
    url = 'http://water.usgs.gov/ogw/seawat/swt_v4_00_05.zip'
    pymake.download_and_unzip(url, pth=dstpth)

    # Remove the parallel and serial folders from the source directory
    dlist = ['parallel', 'serial']
    for d in dlist:
        dname = os.path.join(srcpth, d)
        if os.path.isdir(dname):
            print('Removing ', dname)
            shutil.rmtree(os.path.join(srcpth, d))

    # Replace filespec with standard fortran
    l = "      CHARACTER*20 ACCESS,FORM,ACTION(2)\n" +\
        "      DATA ACCESS/'STREAM'/\n" +\
        "      DATA FORM/'UNFORMATTED'/\n" +\
        "      DATA (ACTION(I),I=1,2)/'READ','READWRITE'/\n"

    fn = os.path.join(srcpth, 'filespec.inc')
    f = open(fn, 'w')
    f.write(l)
    f.close()

    # rename all source files to lower case so compilation doesn't
    # bomb on case-sensitive systems
    srcfiles = os.listdir(srcpth)
    for filename in srcfiles:
        src = os.path.join(srcpth, filename)
        dst = os.path.join(srcpth, filename.lower())
        os.rename(src, dst)

    # compile seawat
    pymake.main(srcpth, target, 'gfortran', 'gcc', makeclean=True,
                expedite=False, dryrun=False, double=True, debug=False,
                include_subdirs=False)

    assert os.path.isfile(target) is True, 'Target does not exist.'
    return
Beispiel #35
0
def make_modpath6():

    # get current directory
    dstpth = os.path.join('temp')
    if not os.path.exists(dstpth):
        os.makedirs(dstpth)
    os.chdir(dstpth)

    # Download the MODFLOW-2005 distribution
    url = "http://water.usgs.gov/ogw/modpath/modpath.6_0_01.zip"
    download_and_unzip(url)
    dirname = 'modpath.6_0'
    dwpath = os.path.join(dstpth, dirname)
    if os.path.isdir(dwpath):
        shutil.rmtree(dwpath)

    # Name src folders
    srcdir = os.path.join(dirname, 'src')

    fname1 = os.path.join(srcdir, 'MP6Flowdata.for')
    f = open(fname1, 'r')

    fname2 = os.path.join(srcdir, 'MP6Flowdata_mod.for')
    f2 = open(fname2, 'w')
    for line in f:
        line = line.replace('CD.QX2', 'CD%QX2')
        f2.write(line)
    f.close()
    f2.close()
    os.remove(fname1)

    target = 'mp6'
    pymake.main(srcdir,
                target,
                'gfortran',
                'gcc',
                makeclean=True,
                expedite=False,
                dryrun=False,
                double=True,
                debug=False)

    assert os.path.isfile(target), 'Target does not exist.'
Beispiel #36
0
def test_main():
    """Test execution"""
    res = _sh(sys.executable,
              '-c',
              ('\
              import pymake; pymake.main(["-f", "%s"])' % fname).strip(),
              stderr=subprocess.STDOUT)

    # actual test:
    try:
        assert ("hello world" in res)
    except AssertionError:
        if sys.version_info[:2] > (2, 6):
            raise

    # semi-fake test which gets coverage:
    _SYS = sys.argv
    sys.argv = ['', '-f', fname]
    main()
    sys.argv = _SYS
Beispiel #37
0
def compile_code():
    # Remove the existing mfusg directory if it exists
    if os.path.isdir(mfusgpth):
        shutil.rmtree(mfusgpth)

    # Download the MODFLOW-USG distribution
    url = 'http://water.usgs.gov/ogw/mfusg/mfusg.1_3.zip'
    pymake.download_and_unzip(url, pth=dstpth)

    # Remove extraneous source directories
    dlist = ['zonebudusg', 'serial']
    for d in dlist:
        dname = os.path.join(srcpth, d)
        if os.path.isdir(dname):
            print('Removing ', dname)
            shutil.rmtree(os.path.join(srcpth, d))

    # compile MODFLOW-USG
    pymake.main(srcpth, target, 'gfortran', 'gcc', makeclean=True,
                expedite=False, dryrun=False, double=False, debug=False)
    assert os.path.isfile(target), 'Target does not exist.'
Beispiel #38
0
def make_mfusg():

    # get current directory
    dstpth = os.path.join('temp')
    if not os.path.exists(dstpth):
        os.makedirs(dstpth)
    os.chdir(dstpth)

    # Remove the existing mfusg.1_2 directory if it exists
    dirname = 'mfusg.1_2'
    if os.path.isdir(dirname):
        shutil.rmtree(dirname)

    url = 'http://water.usgs.gov/ogw/mfusg/mfusg.1_2_00.zip'
    download_and_unzip(url)

    # Set src and target
    srcdir = os.path.join('mfusg.1_2', 'src')
    target = 'mfusg'

    # Remove extraneous source directories
    dlist = ['zonebudusg', 'serial']
    for d in dlist:
        dname = os.path.join(srcdir, d)
        if os.path.isdir(dname):
            print('Removing ', dname)
            shutil.rmtree(os.path.join(srcdir, d))

    pymake.main(srcdir, target, 'gfortran', 'gcc', makeclean=True,
                expedite=False, dryrun=False, double=False, debug=False)

    assert os.path.isfile(target), 'Target does not exist.'

    # Remove the existing mfusg.1_2 directory if it exists
    dirname = 'mfusg.1_2'
    if os.path.isdir(dirname):
        shutil.rmtree(dirname)
Beispiel #39
0
def make_modpath6():

    # get current directory
    dstpth = os.path.join('temp')
    if not os.path.exists(dstpth):
        os.makedirs(dstpth)
    os.chdir(dstpth)

    # Download the MODFLOW-2005 distribution
    url = "http://water.usgs.gov/ogw/modpath/modpath.6_0_01.zip"
    download_and_unzip(url)
    dirname = 'modpath.6_0'
    dwpath = os.path.join(dstpth, dirname)
    if os.path.isdir(dwpath):
        shutil.rmtree(dwpath)

    # Name src folders
    srcdir = os.path.join(dirname, 'src')

    fname1 = os.path.join(srcdir, 'MP6Flowdata.for')
    f = open(fname1, 'r')

    fname2 = os.path.join(srcdir, 'MP6Flowdata_mod.for')
    f2 = open(fname2, 'w')
    for line in f:
        line = line.replace('CD.QX2', 'CD%QX2')
        f2.write(line)
    f.close()
    f2.close()
    os.remove(fname1)

    target = 'mp6'
    pymake.main(srcdir, target, 'gfortran', 'gcc', makeclean=True,
                expedite=False, dryrun=False, double=True, debug=False)

    assert os.path.isfile(target), 'Target does not exist.'
Beispiel #40
0
def make_mf2005():

    # get current directory
    dstpth = os.path.join('temp')
    if not os.path.exists(dstpth):
        os.makedirs(dstpth)
    os.chdir(dstpth)

    # Download the MODFLOW-2005 distribution
    url = "http://water.usgs.gov/ogw/modflow/MODFLOW-2005_v1.11.00/mf2005v1_11_00_unix.zip"
    download_and_unzip(url)

    # Rename Unix to a more reasonable name
    dirname = 'MF2005.1_11u'
    if os.path.isdir(dirname):
        shutil.rmtree(dirname)
    os.rename('Unix', 'MF2005.1_11u')

    # Remove two src folders
    srcdir = os.path.join(dirname, 'src')
    dlist = ['hydprograms', 'mnw1to2']
    for d in dlist:
        dname = os.path.join(srcdir, d)
        if os.path.isdir(dname):
            print('Removing ', dname)
            shutil.rmtree(os.path.join(srcdir, d))

    target = 'mf2005dbl'
    pymake.main(srcdir, target, 'gfortran', 'gcc', makeclean=True,
                expedite=False, dryrun=False, double=True, debug=False)

    assert os.path.isfile(target), 'Target does not exist.'

    dirname = 'MF2005.1_11u'
    if os.path.isdir(dirname):
        shutil.rmtree(dirname)
Beispiel #41
0
def make_mflgr():

    # get current directory
    dstpth = os.path.join('temp')
    if not os.path.exists(dstpth):
        os.makedirs(dstpth)
    os.chdir(dstpth)

    # Download the MODFLOW-LGR distribution
    url = "http://water.usgs.gov/ogw/modflow-lgr/modflow-lgr-v2.0.0/mflgrv2_0_00.zip"
    download_and_unzip(url)

    dirname = 'mflgr.2_0'
    srcdir = os.path.join(dirname, 'src')
    target = 'mflgrdbl'

    print('Present working directory: ', os.getcwd())
    # pymake.main(srcdir, target, 'ifort', 'gcc', makeclean=True,
    #            expedite=False, dryrun=False, double=True, debug=False)
    pymake.main(srcdir, target, 'gfortran', 'gcc', makeclean=True,
                expedite=False, dryrun=False, double=True, debug=False)


    assert os.path.isfile(target), 'Target does not exist.'
Beispiel #42
0
def make_mf2000():

    # get current directory
    dstpth = os.path.join('temp')
    if os.path.exists(dstpth):
        shutil.rmtree(dstpth)
    os.makedirs(dstpth)
    os.chdir(dstpth)

    # Download the MODFLOW-2005 distribution
    url = "http://water.usgs.gov/nrp/gwsoftware/modflow2000/mf2k1_19_01.tar.gz"
    download_and_unzip(url)

    dirname = 'mf2k.1_19'

    # Set source directory
    srcdir = os.path.join(dirname, 'src')
     
    # Remove six src folders
    dlist = ['beale2k', 'hydprgm', 'mf96to2k', 'mfpto2k', 'resan2k', 'ycint2k']
    for d in dlist:
        dname = os.path.join(srcdir, d)
        if os.path.isdir(dname):
            print('Removing ', dname)
            shutil.rmtree(os.path.join(srcdir, d))

      
    # Move src files and serial src file to src directory
    tpth = os.path.join(srcdir, 'mf2k')
    files = [f for f in os.listdir(tpth) if os.path.isfile(os.path.join(tpth, f))]
    for f in files:
        shutil.move(os.path.join(tpth, f), srcdir)
    tpth = os.path.join(srcdir, 'mf2k', 'serial')
    files = [f for f in os.listdir(tpth) if os.path.isfile(os.path.join(tpth, f))]
    for f in files:
        shutil.move(os.path.join(tpth, f), srcdir)
    
    # Remove mf2k directory in source directory
    tpth = os.path.join(srcdir, 'mf2k')
    shutil.rmtree(tpth)

    # Replace filespec with standard fortran
    l = '''
          CHARACTER*20 ACCESS,FORM,ACTION(2)
          DATA ACCESS/'STREAM'/
          DATA FORM/'UNFORMATTED'/
          DATA (ACTION(I),I=1,2)/'READ','READWRITE'/
    '''
    fn = os.path.join(srcdir, 'openspec.inc')
    f = open(fn, 'w')
    f.write(l)
    f.close()

    target = 'mf2000'
    pymake.main(srcdir, target, 'gfortran', 'gcc', makeclean=True,
                expedite=False, dryrun=False, double=False, debug=False)

    assert os.path.isfile(target), 'Target does not exist.'

    # Remove MODFLOW-2000 files
    if os.path.isdir(dirname):
        shutil.rmtree(dirname)
Beispiel #43
0
import sys
from io import open as io_open

# Get version from tqdm/_version.py
__version__ = None
src_dir = os.path.abspath(os.path.dirname(__file__))
version_file = os.path.join(src_dir, 'tqdm', '_version.py')
with io_open(version_file, mode='r') as fd:
    exec(fd.read())

# Executing makefile commands if specified
if sys.argv[1].lower().strip() == 'make':
    import pymake
    # Filename of the makefile
    fpath = os.path.join(src_dir, 'Makefile')
    pymake.main(['-f', fpath] + sys.argv[2:])
    # Stop to avoid setup.py raising non-standard command error
    sys.exit(0)

extras_require = {}
requirements_dev = os.path.join(src_dir, 'requirements-dev.txt')
with io_open(requirements_dev, mode='r') as fd:
    extras_require['dev'] = [i.strip().split('#', 1)[0].strip()
                             for i in fd.read().strip().split('\n')]

README_rst = ''
fndoc = os.path.join(src_dir, 'README.rst')
with io_open(fndoc, mode='r', encoding='utf-8') as fd:
    README_rst = fd.read()
setup(
    name='tqdm',