Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(usgsprograms): update triangle and mt3d to use GitHub repos #133

Merged
merged 3 commits into from
Jul 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions autotest/test_cli_cmds.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
import subprocess

import pytest
from flaky import flaky

RERUNS = 3

targets = (
"triangle",
Expand Down Expand Up @@ -47,6 +50,7 @@ def clean_up() -> None:

@pytest.mark.dependency(name="make_program")
@pytest.mark.base
@flaky(max_runs=RERUNS)
@pytest.mark.parametrize("target", targets)
def test_make_program(target: str) -> None:
cmd = [
Expand Down
92 changes: 1 addition & 91 deletions pymake/utils/_usgs_src_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
import types
from typing import Union

from .usgsprograms import usgs_program_data


def _get_function_names(module, select_name=None):
"""Get a dictionary of functions available in a user-specified source file.
Expand Down Expand Up @@ -111,15 +109,9 @@ def _update_triangle_files(srcdir, fc, cc, arch, double):
-------

"""
# move the downloaded files
rootdir = os.path.join(*(srcdir.split(os.path.sep)[:1]))
prog_dict = usgs_program_data().get_target("triangle")
dirname = prog_dict.dirname
dstpth = os.path.join(rootdir, dirname)

# modify long to long long on windows
if "win32" in sys.platform.lower() and cc in ("icl", "cl"):
src = os.path.join(rootdir, "triangle.c")
src = os.path.join(srcdir, "triangle.c")
with open(src, "r") as f:
lines = f.readlines()
for idx, line in enumerate(lines):
Expand All @@ -129,28 +121,6 @@ def _update_triangle_files(srcdir, fc, cc, arch, double):
with open(src, "w") as f:
for line in lines:
f.write(line)

# make destination directory
if not os.path.exists(dstpth):
os.makedirs(dstpth, exist_ok=True)

# make src directory
if not os.path.exists(srcdir):
os.makedirs(srcdir)

# move the source files
src = os.path.join(rootdir, "triangle.c")
dst = os.path.join(srcdir, "triangle.c")
shutil.move(src, dst)
src = os.path.join(rootdir, "triangle.h")
dst = os.path.join(srcdir, "triangle.h")
shutil.move(src, dst)

# remove remaining downloaded files
for file in os.listdir(rootdir):
src = os.path.join(rootdir, file)
if os.path.isfile(src):
os.remove(src)
return


Expand All @@ -175,66 +145,6 @@ def _update_mt3dms_files(srcdir, fc, cc, arch, double):
-------

"""
# move the downloaded files
rootdir = os.path.join(*(srcdir.split(os.path.sep)[:1]))
prog_dict = usgs_program_data().get_target("mt3dms")
dirname = prog_dict.dirname
dstpth = os.path.join(rootdir, dirname)

# Clean up unneeded files
for f in ["ReadMe_MT3DMS.pdf", "upgrade.pdf"]:
fpth = os.path.join(rootdir, f)
if os.path.isfile(fpth):
print(f'Removing..."{f}"')
os.remove(fpth)

# remove some unneeded folders
dir_list = ["bin", "doc", "examples", "utility"]
for d in dir_list:
dname = os.path.join(rootdir, d)
if os.path.isdir(dname):
print(f'Removing..."{dname}"')
shutil.rmtree(dname)

# make destination directory
if not os.path.exists(dstpth):
os.makedirs(dstpth, exist_ok=True)

# move the files
for src_dir, _, files in os.walk(rootdir):
# skip target directory (dirname)
if dirname in src_dir:
continue
if src_dir is rootdir:
continue
else:
dst_dir = src_dir.replace(rootdir + os.path.sep, "")
dst_dir = os.path.join(dstpth, dst_dir)
if not os.path.exists(dst_dir):
os.mkdir(dst_dir)
for file_ in files:
src_file = os.path.join(src_dir, file_)
dst_file = os.path.join(dst_dir, file_)
if os.path.exists(dst_file):
os.remove(dst_file)
print(f"{src_file} -> {dst_dir}")
# shutil.copy(src_file, dst_dir)
shutil.move(src_file, dst_file)

# remove the original source directory
dname = os.path.join(rootdir, "src")
if os.path.isdir(dname):
print(f'Removing..."{dname}"')
shutil.rmtree(dname)

# remove some unneeded files
file_list = ["automake.fig", "mt3dms5b.exe"]
for f in file_list:
dname = os.path.join(srcdir, f)
if os.path.isfile(dname):
print(f'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")
Expand Down
4 changes: 2 additions & 2 deletions pymake/utils/usgsprograms.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ mf6 , 6.4.2 , True , https://github.com/MODFLOW-USGS/modflow6/releas
zbud6 , 6.4.2 , True , https://github.com/MODFLOW-USGS/modflow6/releases/download/6.4.2/mf6.4.2_linux.zip , mf6.4.2_linux , utils/zonebudget/src, True , False , False
libmf6 , 6.4.2 , True , https://github.com/MODFLOW-USGS/modflow6/releases/download/6.4.2/mf6.4.2_linux.zip , mf6.4.2_linux , srcbmi , True , False , True
mp7 , 7.2.001, True , https://water.usgs.gov/water-resources/software/MODPATH/modpath_7_2_001.zip , modpath_7_2_001 , source , True , False , False
mt3dms , 5.3.0 , True , https://hydro.geo.ua.edu/mt3d/mt3dms_530.exe , mt3dms5.3.0 , src/true-binary , True , False , False
mt3dms , 5.3.0 , True , https://github.com/MODFLOW-USGS/mt3dms/releases/download/2.0/mt3dms-2.0.zip , mt3dms-2.0 , true-binary , True , False , False
mt3dusgs , 1.1.0 , True , https://water.usgs.gov/water-resources/software/MT3D-USGS/mt3dusgs1.1.0.zip , mt3dusgs1.1.0 , src , True , False , False
vs2dt , 3.3 , True , https://water.usgs.gov/water-resources/software/VS2DI/vs2dt3_3.zip , vs2dt3_3 , include , True , False , False
triangle , 1.6 , True , https://www.netlib.org/voronoi/triangle.zip , triangle1.6 , src , True , False , False
triangle , 1.6 , True , https://github.com/MODFLOW-USGS/triangle/releases/download/1.0/triangle-1.0.zip , triangle-1.0 , src , True , False , False
gridgen , 1.0.02 , True , https://water.usgs.gov/water-resources/software/GRIDGEN/gridgen.1.0.02.zip , gridgen.1.0.02 , src , True , False , False
crt , 1.3.1 , True , https://water.usgs.gov/ogw/CRT/CRT_1.3.1.zip , CRT_1.3.1 , SOURCE , True , False , False
sutra , 3.0 , True , https://water.usgs.gov/water-resources/software/sutra/SUTRA_3_0_0.zip , SutraSuite , SUTRA_3_0/source , True , False , False
Expand Down