Skip to content

Commit

Permalink
Merge branch 'master' into mdpiper/update-examples-for-realz
Browse files Browse the repository at this point in the history
  • Loading branch information
mdpiper committed Oct 18, 2024
2 parents bd09d79 + 143800a commit 4576176
Show file tree
Hide file tree
Showing 16 changed files with 182 additions and 110 deletions.
21 changes: 0 additions & 21 deletions .github/workflows/format.yml

This file was deleted.

23 changes: 0 additions & 23 deletions .github/workflows/lint.yml

This file was deleted.

6 changes: 1 addition & 5 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,8 @@ jobs:
conda info
conda list
- name: Install requirements
run: |
conda 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: |
Expand Down
55 changes: 4 additions & 51 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,54 +1,7 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.egg-info/
*.py[cod]

# C extensions
*.so

# Distribution / packaging
.Python
env/
.coverage
.ipynb_checkpoints/
__pycache__/
build/
develop-eggs/
dist/
downloads/
eggs/
lib/
lib64/
parts/
sdist/
var/
*.egg-info/
.installed.cfg
*.egg

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.cache
nosetests.xml
coverage.xml

# Translations
*.mo
*.pot

# Django stuff:
*.log

# Sphinx documentation
docs/_build/

# PyBuilder
target/
65 changes: 65 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
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
files: heat/.*\.py$
additional_dependencies:
- types-PyYAML
3 changes: 1 addition & 2 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -46,4 +46,3 @@ Changelog for bmi-example-python
------------------

- Initial release

1 change: 0 additions & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -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.

2 changes: 1 addition & 1 deletion heat/bmi_heat.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,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)
Expand Down
3 changes: 2 additions & 1 deletion heat/heat.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ 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.
Examples
Expand Down
103 changes: 103 additions & 0 deletions noxfile.py
Original file line number Diff line number Diff line change
@@ -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()
6 changes: 3 additions & 3 deletions requirements-testing.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
black
bmi-tester
coveralls
isort
pytest
pytest-cov
black
isort
ruff
bmi-tester
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
bmipy
numpy
scipy
pyyaml
bmipy
scipy
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 4576176

Please sign in to comment.