From b454063f6e1653a5ee827ad6bad8ed55882fef77 Mon Sep 17 00:00:00 2001 From: Joseph D Hughes Date: Mon, 17 Jun 2024 09:45:17 -0500 Subject: [PATCH 1/2] ci: update code.json for release workflow --- README.md | 2 +- code.json | 233 ++++++++++++++++++++++++++++++++++++++ pixi.toml | 1 + pymake/config.py | 13 ++- pyproject.toml | 1 + scripts/update_version.py | 56 +++++---- version.txt | 2 +- 7 files changed, 284 insertions(+), 24 deletions(-) create mode 100644 code.json diff --git a/README.md b/README.md index 14dda82..47b236f 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ Python package for building MODFLOW-based programs from source files. -### Version 1.2.10 +### Version 1.2.10.dev0 [![PyPI Version](https://img.shields.io/pypi/v/mfpymake.png)](https://pypi.python.org/pypi/mfpymake) [![Anaconda Version](https://anaconda.org/conda-forge/mfpymake/badges/version.svg)](https://anaconda.org/conda-forge/mfpymake) diff --git a/code.json b/code.json new file mode 100644 index 0000000..a49cc53 --- /dev/null +++ b/code.json @@ -0,0 +1,233 @@ +{ + "crt": { + "current": true, + "dirname": "CRT_1.3.1", + "double_switch": false, + "shared_object": false, + "srcdir": "SOURCE", + "standard_switch": true, + "url": "https://water.usgs.gov/ogw/CRT/CRT_1.3.1.zip", + "url_download_asset_date": "04/11/2017", + "version": "1.3.1" + }, + "gridgen": { + "current": true, + "dirname": "gridgen.1.0.02", + "double_switch": false, + "shared_object": false, + "srcdir": "src", + "standard_switch": true, + "url": "https://water.usgs.gov/water-resources/software/GRIDGEN/gridgen.1.0.02.zip", + "url_download_asset_date": "10/24/2018", + "version": "1.0.02" + }, + "libmf6": { + "current": true, + "dirname": "mf6.5.0_linux", + "double_switch": false, + "shared_object": true, + "srcdir": "srcbmi", + "standard_switch": true, + "url": "https://github.com/MODFLOW-USGS/modflow6/releases/download/6.5.0/mf6.5.0_linux.zip", + "url_download_asset_date": "05/23/2024", + "version": "6.5.0" + }, + "mf2000": { + "current": true, + "dirname": "mf2k.1_19", + "double_switch": false, + "shared_object": false, + "srcdir": "src", + "standard_switch": true, + "url": "https://water.usgs.gov/nrp/gwsoftware/modflow2000/mf2k1_19_01.tar.gz", + "url_download_asset_date": "03/30/2010", + "version": "1.19.01" + }, + "mf2005": { + "current": true, + "dirname": "MF2005.1_12u", + "double_switch": false, + "shared_object": false, + "srcdir": "src", + "standard_switch": true, + "url": "https://github.com/MODFLOW-USGS/mf2005/releases/download/v.1.12.00/MF2005.1_12u.zip", + "url_download_asset_date": "12/07/2021", + "version": "1.12.00" + }, + "mf6": { + "current": true, + "dirname": "mf6.5.0_linux", + "double_switch": false, + "shared_object": false, + "srcdir": "src", + "standard_switch": true, + "url": "https://github.com/MODFLOW-USGS/modflow6/releases/download/6.5.0/mf6.5.0_linux.zip", + "url_download_asset_date": "05/23/2024", + "version": "6.5.0" + }, + "mflgr": { + "current": true, + "dirname": "mflgr.2_0", + "double_switch": false, + "shared_object": false, + "srcdir": "src", + "standard_switch": true, + "url": "https://water.usgs.gov/ogw/modflow-lgr/modflow-lgr-v2.0.0/mflgrv2_0_00.zip", + "url_download_asset_date": "09/20/2013", + "version": "2.0.0" + }, + "mfnwt": { + "current": true, + "dirname": "MODFLOW-NWT", + "double_switch": false, + "shared_object": false, + "srcdir": "src", + "standard_switch": true, + "url": "https://water.usgs.gov/water-resources/software/MODFLOW-NWT/MODFLOW-NWT_1.3.0.zip", + "url_download_asset_date": "09/07/2022", + "version": "1.3.0" + }, + "mfusg": { + "current": true, + "dirname": "mfusg1_5", + "double_switch": false, + "shared_object": false, + "srcdir": "src", + "standard_switch": true, + "url": "https://water.usgs.gov/water-resources/software/MODFLOW-USG/mfusg1_5.zip", + "url_download_asset_date": "02/27/2019", + "version": "1.5" + }, + "mfusg_gsi": { + "current": true, + "dirname": "USGT-v2-3-0-Source", + "double_switch": false, + "shared_object": false, + "srcdir": ".", + "standard_switch": true, + "url": "https://www.gsienv.com/wp-content/uploads/2024/03/USG-Transport_Version-2.3.0.zip", + "url_download_asset_date": null, + "version": "2.3.0" + }, + "mp6": { + "current": true, + "dirname": "modpath.6_0", + "double_switch": false, + "shared_object": false, + "srcdir": "src", + "standard_switch": true, + "url": "https://water.usgs.gov/water-resources/software/MODPATH/modpath.6_0_01.zip", + "url_download_asset_date": "10/23/2018", + "version": "6.0.1" + }, + "mp7": { + "current": true, + "dirname": "modpath_7_2_001", + "double_switch": false, + "shared_object": false, + "srcdir": "source", + "standard_switch": true, + "url": "https://water.usgs.gov/water-resources/software/MODPATH/modpath_7_2_001.zip", + "url_download_asset_date": "10/23/2018", + "version": "7.2.001" + }, + "mt3dms": { + "current": true, + "dirname": "mt3dms-2.0", + "double_switch": false, + "shared_object": false, + "srcdir": "true-binary", + "standard_switch": true, + "url": "https://github.com/MODFLOW-USGS/mt3dms/releases/download/2.0/mt3dms-2.0.zip", + "url_download_asset_date": "07/05/2023", + "version": "5.3.0" + }, + "mt3dusgs": { + "current": true, + "dirname": "mt3dusgs1.1.0", + "double_switch": false, + "shared_object": false, + "srcdir": "src", + "standard_switch": true, + "url": "https://water.usgs.gov/water-resources/software/MT3D-USGS/mt3dusgs1.1.0.zip", + "url_download_asset_date": "07/12/2019", + "version": "1.1.0" + }, + "sutra": { + "current": true, + "dirname": "SutraSuite", + "double_switch": false, + "shared_object": false, + "srcdir": "SUTRA_3_0/source", + "standard_switch": true, + "url": "https://water.usgs.gov/water-resources/software/sutra/SUTRA_3_0_0.zip", + "url_download_asset_date": "08/20/2019", + "version": "3.0" + }, + "swtv4": { + "current": true, + "dirname": "swt_v4_00_05", + "double_switch": true, + "shared_object": false, + "srcdir": "source", + "standard_switch": false, + "url": "https://water.usgs.gov/water-resources/software/SEAWAT/swt_v4_00_05.zip", + "url_download_asset_date": "10/24/2018", + "version": "4.00.05" + }, + "triangle": { + "current": true, + "dirname": "triangle-1.0", + "double_switch": false, + "shared_object": false, + "srcdir": "src", + "standard_switch": true, + "url": "https://github.com/MODFLOW-USGS/triangle/releases/download/1.0/triangle-1.0.zip", + "url_download_asset_date": "07/05/2023", + "version": "1.6" + }, + "vs2dt": { + "current": true, + "dirname": "vs2dt3_3", + "double_switch": false, + "shared_object": false, + "srcdir": "include", + "standard_switch": true, + "url": "https://water.usgs.gov/water-resources/software/VS2DI/vs2dt3_3.zip", + "url_download_asset_date": "04/02/2018", + "version": "3.3" + }, + "zbud6": { + "current": true, + "dirname": "mf6.5.0_linux", + "double_switch": false, + "shared_object": false, + "srcdir": "utils/zonebudget/src", + "standard_switch": true, + "url": "https://github.com/MODFLOW-USGS/modflow6/releases/download/6.5.0/mf6.5.0_linux.zip", + "url_download_asset_date": "05/23/2024", + "version": "6.5.0" + }, + "zonbud3": { + "current": true, + "dirname": "Zonbud.3_01", + "double_switch": false, + "shared_object": false, + "srcdir": "Src", + "standard_switch": true, + "url": "https://water.usgs.gov/water-resources/software/ZONEBUDGET/zonbud3_01.exe", + "url_download_asset_date": "10/25/2018", + "version": "3.01" + }, + "zonbudusg": { + "current": true, + "dirname": "mfusg1_5", + "double_switch": false, + "shared_object": false, + "srcdir": "src/zonebudusg", + "standard_switch": true, + "url": "https://water.usgs.gov/water-resources/software/MODFLOW-USG/mfusg1_5.zip", + "url_download_asset_date": "02/27/2019", + "version": "1.5" + } +} diff --git a/pixi.toml b/pixi.toml index 1e27565..9b13c7a 100644 --- a/pixi.toml +++ b/pixi.toml @@ -52,3 +52,4 @@ coverage-report = { cmd = "coverage report", cwd = "autotest"} # release update-version = { cmd = "python scripts/update_version.py -v"} +create-codejson = { cmd = "make-code-json" } \ No newline at end of file diff --git a/pymake/config.py b/pymake/config.py index d85dc48..7dc7cd5 100644 --- a/pymake/config.py +++ b/pymake/config.py @@ -1,9 +1,18 @@ +# mfpymake version file automatically created using +# update_version.py on June 17, 2024 09:42:26 + +# mfpymake version file automatically created using +# update_version.py on June 17, 2024 09:33:29 + +# mfpymake version file automatically created using +# update_version.py on June 17, 2024 09:31:39 + # mfpymake version file automatically created using # update_version.py on June 16, 2024 18:36:44 __author__ = "Joseph D. Hughes" -__date__ = "June 16, 2024" -__version__ = "1.2.10" +__date__ = "June 17, 2024" +__version__ = "1.2.10.dev0" __maintainer__ = "Joseph D. Hughes" __email__ = "jdhughes@usgs.gov" __status__ = "Production" diff --git a/pyproject.toml b/pyproject.toml index db98945..b80a73d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -98,6 +98,7 @@ include = [ "pymake/**/*.py", "autotest/**/*.py", "docs/**/*.py", + "scripts/**/*.py", ] [tool.ruff.lint] diff --git a/scripts/update_version.py b/scripts/update_version.py index 59bdc8d..7ab2e49 100644 --- a/scripts/update_version.py +++ b/scripts/update_version.py @@ -1,4 +1,5 @@ import argparse +import json import re import textwrap from datetime import datetime @@ -14,12 +15,14 @@ # file names and the path to the file relative to the repo root directory file_paths_list = [ + _project_root_path / "code.json", _project_root_path / "README.md", _project_root_path / "version.txt", _project_root_path / "pymake" / "config.py", ] file_paths = {pth.name: pth for pth in file_paths_list} # keys for each file + def split_nonnumeric(s): match = re.compile("[^0-9]").search(s) return [s[: match.start()], s[match.start() :]] if match else s @@ -37,7 +40,7 @@ def update_version_txt(version: Version): def update_version_py(timestamp: datetime, version: Version): lines = file_paths["config.py"].read_text().rstrip().split("\n") - + with open(_version_py_path, "w") as f: f.write( f"# {_project_name} version file automatically created using\n" @@ -52,12 +55,12 @@ def update_version_py(timestamp: datetime, version: Version): print(f"Updated {_version_py_path} to version {version}") - def update_readme_markdown( - timestamp: datetime, version: Version, approved: bool = False + timestamp: datetime, + version: Version, ): fpth = file_paths["README.md"] - + # read README.md into memory lines = fpth.read_text().rstrip().split("\n") @@ -73,10 +76,28 @@ def update_readme_markdown( print(f"Updated {fpth} to version {version}") + +def update_codejson( + timestamp: datetime, + version: Version, +): + # define json filename + json_fname = file_paths["code.json"] + + # load and modify json file + data = json.loads(json_fname.read_text()) + + # rewrite the json file + with open(json_fname, "w") as f: + json.dump(data, f, indent=4) + f.write("\n") + + print(f"Updated {json_fname} to version {version}") + + def update_version( timestamp: datetime = datetime.now(), version: Version = None, - approved: bool = False, ): lock_path = Path(_version_txt_path.name + ".lock") try: @@ -91,7 +112,8 @@ def update_version( with lock: update_version_txt(version) update_version_py(timestamp, version) - update_readme_markdown(timestamp, version, approved) + update_readme_markdown(timestamp, version) + update_codejson(timestamp, version) finally: try: lock_path.unlink() @@ -105,11 +127,12 @@ def update_version( formatter_class=argparse.RawDescriptionHelpFormatter, epilog=textwrap.dedent( """\ - Update version information stored in version.txt in the project root, - as well as several other files in the repository. If --version is not - provided, the version number will not be changed. A file lock is held - to synchronize file access. The version tag must comply with standard - '..' format conventions for semantic versioning. + Update version information stored in version.txt in the project + root, as well as several other files in the repository. If + --version is not provided, the version number will not be + changed. A file lock is held to synchronize file access. The + version tag must comply with standard '..' + format conventions for semantic versioning. """ ), ) @@ -119,19 +142,13 @@ def update_version( required=False, help="Specify the release version", ) - parser.add_argument( - "-a", - "--approve", - required=False, - action="store_true", - help="Approve the release (defaults false)", - ) parser.add_argument( "-g", "--get", required=False, action="store_true", - help="Just get the current version number, no updates (defaults false)", + help="Just get the current version number, " + + "no updates (defaults false)", ) args = parser.parse_args() @@ -145,5 +162,4 @@ def update_version( version=( Version(args.version) if args.version else _current_version ), - approved=args.approve, ) diff --git a/version.txt b/version.txt index 732aa7d..5924f6d 100644 --- a/version.txt +++ b/version.txt @@ -1 +1 @@ -1.2.10 \ No newline at end of file +1.2.10.dev0 \ No newline at end of file From 7c4bc643cd135857dfd30eede9a252425384aa38 Mon Sep 17 00:00:00 2001 From: Joseph D Hughes Date: Mon, 17 Jun 2024 10:11:06 -0500 Subject: [PATCH 2/2] * update --- .github/workflows/ci.yml | 4 +-- pymake/config.py | 12 ------- scripts/update_version.py | 72 +++++++++++++++++++++++++++------------ 3 files changed, 53 insertions(+), 35 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f9935c6..49a8001 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -20,7 +20,7 @@ concurrency: jobs: pymake-os-compiler: - name: pymake CI on different OSs with gcc and intel-classic + name: pymake compilers runs-on: ${{ matrix.os }} strategy: fail-fast: false @@ -114,7 +114,7 @@ jobs: file: ./autotest/coverage.xml pymake-schedule: - name: pymake scheduled CI different OSs with gcc and intel-classic + name: pymake scheduled if: ${{ github.event_name == 'schedule' }} runs-on: ${{ matrix.os }} strategy: diff --git a/pymake/config.py b/pymake/config.py index 7dc7cd5..49edbe6 100644 --- a/pymake/config.py +++ b/pymake/config.py @@ -1,15 +1,3 @@ -# mfpymake version file automatically created using -# update_version.py on June 17, 2024 09:42:26 - -# mfpymake version file automatically created using -# update_version.py on June 17, 2024 09:33:29 - -# mfpymake version file automatically created using -# update_version.py on June 17, 2024 09:31:39 - -# mfpymake version file automatically created using -# update_version.py on June 16, 2024 18:36:44 - __author__ = "Joseph D. Hughes" __date__ = "June 17, 2024" __version__ = "1.2.10.dev0" diff --git a/scripts/update_version.py b/scripts/update_version.py index 7ab2e49..b797417 100644 --- a/scripts/update_version.py +++ b/scripts/update_version.py @@ -32,20 +32,32 @@ def split_nonnumeric(s): _current_version = Version(_version_txt_path.read_text().strip()) -def update_version_txt(version: Version): - with open(_version_txt_path, "w") as f: +def update_version_txt(version: Version) -> None: + """Update version number in version.txt + + Parameters + ---------- + version : Version + version number + """ + with open(_version_txt_path, "w", encoding="utf8") as f: f.write(str(version)) print(f"Updated {_version_txt_path} to version {version}") -def update_version_py(timestamp: datetime, version: Version): +def update_version_py(timestamp: datetime, version: Version) -> None: + """Update version number in config.py + + Parameters + ---------- + timestamp : datetime + current datetime + version : Version + version number + """ lines = file_paths["config.py"].read_text().rstrip().split("\n") - with open(_version_py_path, "w") as f: - f.write( - f"# {_project_name} version file automatically created using\n" - f"# {Path(__file__).name} on {timestamp:%B %d, %Y %H:%M:%S}\n\n" - ) + with open(_version_py_path, "w", encoding="utf8") as f: for line in lines: if "__date__" in line: line = f'__date__ = "{timestamp:%B %d, %Y}"' @@ -55,10 +67,14 @@ def update_version_py(timestamp: datetime, version: Version): print(f"Updated {_version_py_path} to version {version}") -def update_readme_markdown( - timestamp: datetime, - version: Version, -): +def update_readme_markdown(version: Version) -> None: + """Update README.md + + Parameters + ---------- + version : Version + version number + """ fpth = file_paths["README.md"] # read README.md into memory @@ -66,7 +82,7 @@ def update_readme_markdown( # rewrite README.md terminate = False - with open(fpth, "w") as f: + with open(fpth, "w", encoding="utf8") as f: for line in lines: if "### Version " in line: line = f"### Version {version}" @@ -77,10 +93,14 @@ def update_readme_markdown( print(f"Updated {fpth} to version {version}") -def update_codejson( - timestamp: datetime, - version: Version, -): +def update_codejson(version: Version) -> None: + """Update code.json + + Parameters + ---------- + version : Version + version number + """ # define json filename json_fname = file_paths["code.json"] @@ -88,7 +108,7 @@ def update_codejson( data = json.loads(json_fname.read_text()) # rewrite the json file - with open(json_fname, "w") as f: + with open(json_fname, "w", encoding="utf8") as f: json.dump(data, f, indent=4) f.write("\n") @@ -98,7 +118,17 @@ def update_codejson( def update_version( timestamp: datetime = datetime.now(), version: Version = None, -): +) -> None: + """Main function for updating all of the files containing + version information + + Parameters + ---------- + timestamp : datetime, optional + datetime object, by default datetime.now() + version : Version, optional + version number, by default None + """ lock_path = Path(_version_txt_path.name + ".lock") try: lock = FileLock(lock_path) @@ -112,8 +142,8 @@ def update_version( with lock: update_version_txt(version) update_version_py(timestamp, version) - update_readme_markdown(timestamp, version) - update_codejson(timestamp, version) + update_readme_markdown(version) + update_codejson(version) finally: try: lock_path.unlink()