From ad5cdfbb26edfe1c385f4957d9dc838e4f955f6d Mon Sep 17 00:00:00 2001 From: mcflugen Date: Mon, 29 Jan 2024 18:47:50 -0700 Subject: [PATCH 01/11] add a nox file --- noxfile.py | 103 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 103 insertions(+) create mode 100644 noxfile.py diff --git a/noxfile.py b/noxfile.py new file mode 100644 index 0000000..bcb4d20 --- /dev/null +++ b/noxfile.py @@ -0,0 +1,103 @@ +from __future__ import annotations + +import os +import pathlib +import shutil + +import nox + +PROJECT = "heat" +ROOT = pathlib.Path(__file__).parent + + +@nox.session +def test(session: nox.Session) -> None: + """Run the tests.""" + session.install(".[testing]") + + args = ["--cov", PROJECT, "-vvv"] + session.posargs + + if "CI" in os.environ: + args.append(f"--cov-report=xml:{ROOT.absolute()!s}/coverage.xml") + session.run("pytest", *args) + + if "CI" not in os.environ: + session.run("coverage", "report", "--ignore-errors", "--show-missing") + + +@nox.session +def lint(session: nox.Session) -> None: + """Look for lint.""" + session.install("pre-commit") + session.run("pre-commit", "run", "--all-files") + + +@nox.session +def build(session: nox.Session) -> None: + session.install("pip") + session.install("build") + session.run("python", "--version") + session.run("pip", "--version") + session.run("python", "-m", "build", "--outdir", "./build/wheelhouse") + + +@nox.session(name="publish-testpypi") +def publish_testpypi(session): + """Publish wheelhouse/* to TestPyPI.""" + session.run("twine", "check", "build/wheelhouse/*") + session.run( + "twine", + "upload", + "--skip-existing", + "--repository-url", + "https://test.pypi.org/legacy/", + "build/wheelhouse/*.tar.gz", + ) + + +@nox.session(name="publish-pypi") +def publish_pypi(session): + """Publish wheelhouse/* to PyPI.""" + session.run("twine", "check", "build/wheelhouse/*") + session.run( + "twine", + "upload", + "--skip-existing", + "build/wheelhouse/*.tar.gz", + ) + + +@nox.session(python=False) +def clean(session): + """Remove all .venv's, build files and caches in the directory.""" + folders = ( + (ROOT,) if not session.posargs else (pathlib.Path(f) for f in session.posargs) + ) + for folder in folders: + if not str(folder.resolve()).startswith(str(ROOT.resolve())): + session.log(f"skipping {folder}: folder is outside of repository") + continue + + with session.chdir(folder): + session.log(f"cleaning {folder}") + + shutil.rmtree("build", ignore_errors=True) + shutil.rmtree("dist", ignore_errors=True) + shutil.rmtree(f"src/{PROJECT}.egg-info", ignore_errors=True) + shutil.rmtree(".pytest_cache", ignore_errors=True) + shutil.rmtree(".venv", ignore_errors=True) + + for pattern in ["*.py[co]", "__pycache__"]: + _clean_rglob(pattern) + + +def _clean_rglob(pattern): + nox_dir = pathlib.Path(".nox") + + for p in pathlib.Path(".").rglob(pattern): + if nox_dir in p.parents: + continue + if p.is_dir(): + p.rmdir() + else: + p.unlink() From c7674fbdde4c2f443ad38530df5f998f0cd48185 Mon Sep 17 00:00:00 2001 From: mcflugen Date: Mon, 29 Jan 2024 19:04:46 -0700 Subject: [PATCH 02/11] add pre-commit config file for linting --- .pre-commit-config.yaml | 64 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 .pre-commit-config.yaml diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..ab8dce0 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,64 @@ +repos: +- repo: https://github.com/psf/black + rev: 23.12.1 + hooks: + - id: black + name: black + description: "Black: The uncompromising Python code formatter" + entry: black + language: python + language_version: python3 + minimum_pre_commit_version: 2.9.2 + require_serial: true + types_or: [python, pyi] + +- repo: https://github.com/pycqa/flake8 + rev: 7.0.0 + hooks: + - id: flake8 + additional_dependencies: + - flake8-bugbear + - flake8-comprehensions + - flake8-simplify + args: [--max-line-length=88] + +- repo: https://github.com/asottile/pyupgrade + rev: v3.15.0 + hooks: + - id: pyupgrade + args: [--py310-plus] + +- repo: https://github.com/pycqa/isort + rev: 5.13.2 + hooks: + - id: isort + +- repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.5.0 + hooks: + - id: check-builtin-literals + - id: check-added-large-files + - id: check-case-conflict + - id: check-toml + - id: check-yaml + - id: debug-statements + - id: end-of-file-fixer + - id: forbid-new-submodules + - id: mixed-line-ending + - id: trailing-whitespace + - id: name-tests-test + - id: file-contents-sorter + files: | + (?x)^( + .*requirements(-\w+)?.(in|txt)| + requirements/.*\.txt| + .gitignore + ) + +- repo: https://github.com/pre-commit/mirrors-mypy + rev: v1.8.0 + hooks: + - id: mypy + language_version: python3.12 + additional_dependencies: [types-all] + files: src/.*\.py$ From 72062b41ad739b9cd822bba4b958b586553525fc Mon Sep 17 00:00:00 2001 From: mcflugen Date: Thu, 17 Oct 2024 22:01:43 -0600 Subject: [PATCH 03/11] remove types-all from mypy hook --- .pre-commit-config.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index ab8dce0..84e982d 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -60,5 +60,4 @@ repos: hooks: - id: mypy language_version: python3.12 - additional_dependencies: [types-all] files: src/.*\.py$ From 59b3da60af70e0e6d0dbaa44c2f1b8427c12627c Mon Sep 17 00:00:00 2001 From: mcflugen Date: Thu, 17 Oct 2024 20:55:51 -0600 Subject: [PATCH 04/11] remove name-tests-test hook --- .pre-commit-config.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 84e982d..b85586d 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -46,7 +46,6 @@ repos: - id: forbid-new-submodules - id: mixed-line-ending - id: trailing-whitespace - - id: name-tests-test - id: file-contents-sorter files: | (?x)^( From a847d22ae7a03dc6eb94a2bbf655b71d6a9d7704 Mon Sep 17 00:00:00 2001 From: mcflugen Date: Thu, 17 Oct 2024 22:45:11 -0600 Subject: [PATCH 05/11] remove file contents sorter --- .pre-commit-config.yaml | 7 ------- 1 file changed, 7 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index b85586d..553ebb7 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -46,13 +46,6 @@ repos: - id: forbid-new-submodules - id: mixed-line-ending - id: trailing-whitespace - - id: file-contents-sorter - files: | - (?x)^( - .*requirements(-\w+)?.(in|txt)| - requirements/.*\.txt| - .gitignore - ) - repo: https://github.com/pre-commit/mirrors-mypy rev: v1.8.0 From d7c5fb1797ecd960e3406b7d401a0beec6416078 Mon Sep 17 00:00:00 2001 From: mcflugen Date: Thu, 17 Oct 2024 20:56:12 -0600 Subject: [PATCH 06/11] remove trailing whitespace --- CHANGES.rst | 3 +-- LICENSE | 1 - 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index 94a262c..4ee2ffa 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -31,7 +31,7 @@ Changelog for bmi-example-python - Match bmipy (#12) - Use GitHub Actions for continuous integration (#15) - Dimensionalize flattened values passed into set_value (#17) -- Update CI (#18) +- Update CI (#18) - Switch from versioneer to zest.releaser - Remove obsolete docs directory @@ -46,4 +46,3 @@ Changelog for bmi-example-python ------------------ - Initial release - diff --git a/LICENSE b/LICENSE index 514dd15..0f18cdf 100644 --- a/LICENSE +++ b/LICENSE @@ -19,4 +19,3 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - From f0e15d0e37529322a05a893faea8a029ff8d0920 Mon Sep 17 00:00:00 2001 From: mcflugen Date: Thu, 17 Oct 2024 20:57:00 -0600 Subject: [PATCH 07/11] upgrade py3.10 syntax --- heat/bmi_heat.py | 2 +- heat/heat.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/heat/bmi_heat.py b/heat/bmi_heat.py index 310855a..76daf23 100644 --- a/heat/bmi_heat.py +++ b/heat/bmi_heat.py @@ -39,7 +39,7 @@ def initialize(self, filename=None): if filename is None: self._model = Heat() elif isinstance(filename, str): - with open(filename, "r") as file_obj: + with open(filename) as file_obj: self._model = Heat.from_file_like(file_obj.read()) else: self._model = Heat.from_file_like(filename) diff --git a/heat/heat.py b/heat/heat.py index e940511..baa20d8 100644 --- a/heat/heat.py +++ b/heat/heat.py @@ -53,7 +53,7 @@ def solve_2d(temp, spacing, out=None, alpha=1.0, time_step=1.0): return np.add(temp, out, out=out) -class Heat(object): +class Heat: """Solve the Heat equation on a grid. From 1ef58683a93730512dd0586aa13e7c8fcb9dd865 Mon Sep 17 00:00:00 2001 From: mcflugen Date: Thu, 17 Oct 2024 20:20:57 -0600 Subject: [PATCH 08/11] remove lint workflow --- .github/workflows/lint.yml | 23 ----------------------- 1 file changed, 23 deletions(-) delete mode 100644 .github/workflows/lint.yml diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml deleted file mode 100644 index cd1822f..0000000 --- a/.github/workflows/lint.yml +++ /dev/null @@ -1,23 +0,0 @@ -name: Lint - -on: [push, pull_request] - -jobs: - - lint: - # We want to run on external PRs, but not on our own internal PRs as they'll be run - # by the push to the branch. Without this if check, checks are duplicated since - # internal PRs match both the push and pull_request events. - if: - github.event_name == 'push' || github.event.pull_request.head.repo.full_name != - github.repository - - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - uses: actions/setup-python@v4 - - - name: Lint - run: | - pip install ruff - ruff check . From d73f4a6b9583ed01746e868e3af3b2d8157d4918 Mon Sep 17 00:00:00 2001 From: mcflugen Date: Mon, 29 Jan 2024 23:23:22 -0700 Subject: [PATCH 09/11] remove format workflow --- .github/workflows/format.yml | 21 --------------------- 1 file changed, 21 deletions(-) delete mode 100644 .github/workflows/format.yml diff --git a/.github/workflows/format.yml b/.github/workflows/format.yml deleted file mode 100644 index 2d7a6b9..0000000 --- a/.github/workflows/format.yml +++ /dev/null @@ -1,21 +0,0 @@ -name: Format - -on: [push, pull_request] - -jobs: - - format: - # We want to run on external PRs, but not on our own internal PRs as they'll be run - # by the push to the branch. Without this if check, checks are duplicated since - # internal PRs match both the push and pull_request events. - if: - github.event_name == 'push' || github.event.pull_request.head.repo.full_name != - github.repository - - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - uses: actions/setup-python@v4 - - uses: psf/black@stable - with: - args: ". --check" From 2ca1b727dc7b0b96f451f0cc92a03b6952a91925 Mon Sep 17 00:00:00 2001 From: mcflugen Date: Tue, 30 Jan 2024 10:23:38 -0700 Subject: [PATCH 10/11] drop python 3.9 from testing; install with pip --- .github/workflows/test.yml | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index f6df638..7e14823 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -20,7 +20,7 @@ jobs: strategy: matrix: os: [ubuntu-latest, macos-latest, windows-latest] - python-version: ["3.9", "3.10", "3.11", "3.12"] + python-version: ["3.10", "3.11", "3.12"] steps: - uses: actions/checkout@v4 @@ -36,12 +36,8 @@ jobs: conda info conda list - - name: Install requirements - run: | - mamba install --file=requirements.txt --file=requirements-testing.txt - - name: Build and install package - run: pip install -e . + run: pip install -e .[testing] - name: Test run: | From 64b04e9400c6b38c0501e60bc7cce515a8fdbc52 Mon Sep 17 00:00:00 2001 From: mcflugen Date: Thu, 17 Oct 2024 21:21:59 -0600 Subject: [PATCH 11/11] use absolute path to examples folder --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 7e14823..90eabdd 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -42,7 +42,7 @@ jobs: - name: Test run: | pytest --cov=heat --cov-report=xml:./coverage.xml -vvv - bmi-test heat:BmiHeat --config-file=./examples/heat.yaml --root-dir=./examples -vvv + bmi-test heat:BmiHeat --config-file=${GITHUB_WORKSPACE}/examples/heat.yaml --root-dir=examples -vvv - name: Coveralls if: matrix.os == 'ubuntu-latest' && matrix.python-version == '3.11'