From 81f3a2c5cf683c18588d9e9697589fa08e242aac Mon Sep 17 00:00:00 2001 From: Daniel Osborne Date: Thu, 6 Nov 2025 11:00:17 -0800 Subject: [PATCH 1/5] Migrate to pyproject.toml to improve build compatibility. --- converter/convert_report.py | 9 ++++--- pyproject.toml | 50 +++++++++++++++++++++++++++++++++++++ setup.py | 45 --------------------------------- 3 files changed, 55 insertions(+), 49 deletions(-) create mode 100644 pyproject.toml delete mode 100644 setup.py diff --git a/converter/convert_report.py b/converter/convert_report.py index 7922f4d..3630cef 100644 --- a/converter/convert_report.py +++ b/converter/convert_report.py @@ -744,7 +744,10 @@ def map_ELEMENT(*args): #endregion -def main(input: str, output: str): +def main(): + input = sys.argv[1] + output = sys.argv[2] + remapped_variables = {} # If any variables had to be renamed, keep track of this mapping def getName(name: str): @@ -1157,8 +1160,6 @@ def cleanup(indent=False): print(f"Saving to: {output}") if __name__ == "__main__": - input = sys.argv[1] - output = sys.argv[2] - main(input, output) + main() # vim: ts=4 sw=4 expandtab fileencoding=utf-8 diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..df6e120 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,50 @@ +[project] +name = "cwms-repgen" +dynamic = ["version"] +dependencies = [ + "requests>=2.27.1", + "pytz", +] +requires-python = ">=3.8" +authors = [ + { name = "USACE-HEC" }, +] +description = "This is a partial copy of HEC's (Hydrologic Engineering Center) repgen program. The program creates fixed form text reports from a time series database, and textfiles." +readme = "README.md" +license = "MIT" +license-files = [ "LICEN[CS]E.*" ] +classifiers = [ + "Programming Language :: Python :: 3", + "Operating System :: OS Independent", +] +urls = { GitHub = "https://github.com/USACE-WaterManagement/repgen5" } + +[project.optional-dependencies] +dateutil = [ + "python-dateutil>=2.8.2", +] +dev = [ + "sphinx", + "sphinx_rtd_theme", + "sphinx-copybutton", + "myst-parser", + "twine", + "wheel", +] + +[project.scripts] +repgen = "repgen.__main__:main" +repgen5 = "repgen.__main__:main" +convert_report = "converter.convert_report:main" + +[build-system] +# These are the assumed default build requirements from pip: +# https://pip.pypa.io/en/stable/reference/pip/#pep-517-and-518-support +requires = [ "setuptools>=43.0.0", "wheel" ] +build-backend = "setuptools.build_meta" + +[tool.setuptools] +package-dir = { "repgen" = "repgen", "converter" = "converter" } + +[tool.setuptools.dynamic] +version = { attr = "repgen.__main__.version" } \ No newline at end of file diff --git a/setup.py b/setup.py deleted file mode 100644 index 6e04081..0000000 --- a/setup.py +++ /dev/null @@ -1,45 +0,0 @@ -from setuptools import setup, find_packages -from repgen.__main__ import version - -with open("README.md", "r", encoding="utf-8") as fh: - long_description = fh.read() - -setup( - name="cwms-repgen", - version=version, - license="MIT", - author="USACE-HEC", - description="""This is a partial copy of HEC's (Hydrologic Engineering Center) repgen program. -The program creates fixed form text reports from a time series database, and textfiles.""", - long_description=long_description, - long_description_content_type="text/markdown", - url="https://github.com/USACE-WaterManagement/repgen5", - packages=find_packages(exclude=["tests", "docs"]), - classifiers=[ - "Programming Language :: Python :: 3", - "License :: OSI Approved :: MIT License", - "Operating System :: OS Independent", - ], - python_requires=">=3.8", - install_requires=[ - "pytz", - "python-dateutil>=2.8.2", - "requests" - ], - extras_require={ - "dev": [ - "sphinx", - "sphinx_rtd_theme", - "sphinx-copybutton", - "myst-parser", - "twine", - "wheel", - ], - }, - entry_points={ - "console_scripts": [ - "repgen5=repgen.__main__:main", - "repgen=repgen.__main__:main", - ], - }, -) \ No newline at end of file From 500822f014ae4a22f7dcc56cc2c7f5720cafe15d Mon Sep 17 00:00:00 2001 From: Daniel Osborne Date: Fri, 14 Nov 2025 11:39:40 -0800 Subject: [PATCH 2/5] Fix test environment. --- .github/workflows/tests.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 50a5dbc..b559aba 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -6,7 +6,7 @@ on: jobs: tests: - runs-on: ubuntu-20.04 + runs-on: ubuntu-latest strategy: matrix: python-version: ['3.8','3.9','3.10', '3.11', '3.12'] @@ -21,7 +21,7 @@ jobs: - name: run tests run: pytest -v canpackage: - runs-on: ubuntu-20.04 + runs-on: ubuntu-latest strategy: matrix: python-version: ['3.8','3.9','3.10', '3.11', '3.12'] From f77a84d7f453cee9dbd63955e9079672397608c1 Mon Sep 17 00:00:00 2001 From: Daniel Osborne Date: Fri, 14 Nov 2025 11:41:06 -0800 Subject: [PATCH 3/5] Use case insensitive replace to fix inf loop. --- repgen/report/report.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/repgen/report/report.py b/repgen/report/report.py index f67fd7f..0657a2a 100644 --- a/repgen/report/report.py +++ b/repgen/report/report.py @@ -113,7 +113,7 @@ def fill_report(self, output): newval = data_point.misstr # Replace every instance in the line *exactly* with the new value if self.compatibility: - tmp = tmp.replace(v.upper(), newval) + tmp = re.sub(re.escape(v), newval, tmp, flags=re.IGNORECASE) else: tmp = tmp.replace(v, newval) if self.compatibility: From a9ac5a5a00cab167caad46315bbbeb3f645f46da Mon Sep 17 00:00:00 2001 From: Daniel Osborne Date: Fri, 14 Nov 2025 11:49:01 -0800 Subject: [PATCH 4/5] Fix converter tests. --- converter/convert_report.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/converter/convert_report.py b/converter/convert_report.py index 3630cef..ca8e771 100644 --- a/converter/convert_report.py +++ b/converter/convert_report.py @@ -744,10 +744,12 @@ def map_ELEMENT(*args): #endregion -def main(): - input = sys.argv[1] - output = sys.argv[2] - +def main(input = None, output = None): + if input is None: + input = sys.argv[1] + if output is None: + output = sys.argv[2] + remapped_variables = {} # If any variables had to be renamed, keep track of this mapping def getName(name: str): From 429cd03b8dd93d9da15b46140d5dbc9b1f809abe Mon Sep 17 00:00:00 2001 From: Daniel Osborne Date: Fri, 14 Nov 2025 17:00:33 -0800 Subject: [PATCH 5/5] Remove older python versions due to outdated TLS. --- .github/workflows/release.yml | 2 +- .github/workflows/tests.yml | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index f0c0983..e12acad 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -12,7 +12,7 @@ jobs: uses: actions/checkout@v4.1.1 - uses: actions/setup-python@v5.1.0 with: - python-version: 3.8 + python-version: 3.11 architecture: x64 - name: install requirements run: pip3 install -r tests/requirements.txt diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index b559aba..56e11b8 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -9,7 +9,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: ['3.8','3.9','3.10', '3.11', '3.12'] + python-version: ['3.10', '3.11', '3.12'] steps: - uses: actions/checkout@v4.1.1 - uses: actions/setup-python@v5.1.0 @@ -24,7 +24,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: ['3.8','3.9','3.10', '3.11', '3.12'] + python-version: ['3.10', '3.11', '3.12'] steps: - uses: actions/checkout@v2 - uses: actions/setup-python@v2