Skip to content

Commit

Permalink
Merge pull request #37 from csdms/mcflugen/remove-model-metadata-scri…
Browse files Browse the repository at this point in the history
…pting

Remove model_metadata.scripting
  • Loading branch information
mcflugen authored Jan 30, 2024
2 parents 0635f7b + 32a0f54 commit 3d2abe8
Show file tree
Hide file tree
Showing 36 changed files with 353 additions and 269 deletions.
24 changes: 0 additions & 24 deletions .github/workflows/black.yml

This file was deleted.

4 changes: 2 additions & 2 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ jobs:
if:
github.event_name == 'push' || github.event.pull_request.head.repo.full_name !=
github.repository

runs-on: ubuntu-latest

defaults:
run:
shell: bash -l {0}
Expand Down
25 changes: 0 additions & 25 deletions .github/workflows/flake8.yml

This file was deleted.

2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
62 changes: 3 additions & 59 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,62 +1,6 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.egg-info/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
env/
.coverage
__pycache__/
build/
develop-eggs/
dist/
downloads/
eggs/
.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
.coverage.*
.cache
nosetests.xml
coverage.xml
*,cover
.hypothesis/

# Translations
*.mo
*.pot

# Django stuff:
*.log

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# Vim swap files
.*.sw*
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
args: [--force-single-line-imports]

- 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: bmi_tester/.*\.py$
1 change: 0 additions & 1 deletion LICENSE.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,3 @@ 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.

15 changes: 6 additions & 9 deletions bmi_tester/__init__.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
from importlib.metadata import version
from bmi_tester._version import __version__
from bmi_tester.api import check_bmi
from bmi_tester.api import check_unit_is_dimensionless
from bmi_tester.api import check_unit_is_time
from bmi_tester.api import check_unit_is_valid

from .api import (
check_bmi,
check_unit_is_dimensionless,
check_unit_is_time,
check_unit_is_valid,
)

__version__ = version("bmi-tester")
__all__ = [
"__version__",
"check_bmi",
"check_unit_is_valid",
"check_unit_is_time",
Expand Down
1 change: 1 addition & 0 deletions bmi_tester/_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__version__ = "0.5.7.dev0"
6 changes: 2 additions & 4 deletions bmi_tester/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
import numpy as np
import pkg_resources
import pytest
import six


SECONDS = gimli.units.Unit("s")

Expand All @@ -29,8 +27,8 @@ def check_bmi(
os.environ["BMI_VERSION_STRING"] = bmi_version

if manifest:
if isinstance(manifest, six.string_types):
with open(manifest, "r") as fp:
if isinstance(manifest, str):
with open(manifest) as fp:
manifest = fp.read()
else:
manifest = os.linesep.join(manifest)
Expand Down
4 changes: 2 additions & 2 deletions bmi_tester/bmi.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import numpy as np


class Bmi(object):
class Bmi:
_input_var_names = ("land_surface__elevation", "land_surface_air__temperature")
_output_var_names = (
"land_surface__elevation",
Expand All @@ -22,7 +22,7 @@ def __init__(self):
}

def initialize(self, config_file):
with open(config_file, "r"):
with open(config_file):
pass

def update(self):
Expand Down
22 changes: 16 additions & 6 deletions bmi_tester/bmipytest.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
#! /usr/bin/env python
import contextlib
import importlib
import os
import pathlib
import re
import sys
import tempfile
from collections.abc import Generator
from functools import partial

import click
import pkg_resources
from model_metadata import MetadataNotFoundError
from model_metadata.api import query, stage
from model_metadata.api import query
from model_metadata.api import stage
from pytest import ExitCode
from model_metadata.scripting import as_cwd

from . import __version__
from .api import check_bmi
Expand All @@ -33,12 +35,12 @@ def validate_entry_point(ctx, param, value):
)
if not re.match(MODULE_REGEX, module_name):
raise click.BadParameter(
"Bad module name ({0})".format(module_name),
f"Bad module name ({module_name})",
param_hint="module_name:ClassName",
)
if not re.match(CLASS_REGEX, class_name):
raise click.BadParameter(
"Bad class name ({0})".format(class_name),
f"Bad class name ({class_name})",
param_hint="module_name:ClassName",
)
return value
Expand Down Expand Up @@ -78,7 +80,7 @@ def _tree(files):


@click.command(
context_settings=dict(ignore_unknown_options=True, allow_extra_args=True)
context_settings={"ignore_unknown_options": True, "allow_extra_args": True}
)
@click.version_option(version=__version__)
@click.option(
Expand Down Expand Up @@ -195,7 +197,7 @@ def main(
if manifest:
out(_tree(manifest))
out(f"> cat {stage_dir}/{config_file}")
with open(os.path.join(stage_dir, config_file), "r") as fp:
with open(os.path.join(stage_dir, config_file)) as fp:
out(fp.read())

with as_cwd(stage_dir):
Expand All @@ -220,3 +222,11 @@ def main(
err("😞 There were errors")

sys.exit(status)


@contextlib.contextmanager
def as_cwd(path: str) -> Generator[None, None, None]:
prev_cwd = os.getcwd()
os.chdir(path)
yield
os.chdir(prev_cwd)
17 changes: 9 additions & 8 deletions bmi_tester/bootstrap/test_control.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import importlib
import os
import shutil

import pytest
from model_metadata.scripting import cp

# from .conftest import INPUT_FILE, Bmi


def load_component(entry_point):
Expand All @@ -31,7 +29,7 @@ def load_component(entry_point):
else:
Bmi = load_component(class_to_test)

INPUT_FILE = os.environ.get("BMITEST_INPUT_FILE", None)
INPUT_FILE = os.environ.get("BMITEST_INPUT_FILE")


@pytest.mark.dependency()
Expand All @@ -53,13 +51,14 @@ def test_has_finalize():
)
def test_initialize(tmpdir):
"""Test component can initialize itself."""
infile = os.environ.get("BMITEST_INPUT_FILE", None)
infile = os.environ.get("BMITEST_INPUT_FILE")
manifest = os.environ.get("BMITEST_MANIFEST", infile or "").splitlines()

with tmpdir.as_cwd() as prev:
for file_ in [fname.strip() for fname in manifest]:
if file_:
cp(os.path.join(str(prev), file_), tmpdir / file_, create_dirs=True)
os.makedirs(tmpdir / os.path.dirname(file_), exist_ok=True)
shutil.copy2(os.path.join(prev, file_), tmpdir / file_)

bmi = Bmi()
assert bmi.initialize(INPUT_FILE) is None
Expand All @@ -69,13 +68,15 @@ def test_initialize(tmpdir):
@pytest.mark.dependency(depends=["initialize_works"])
def test_update(tmpdir):
"""Test component can update itself."""
infile = os.environ.get("BMITEST_INPUT_FILE", None)
infile = os.environ.get("BMITEST_INPUT_FILE")
manifest = os.environ.get("BMITEST_MANIFEST", infile or "").splitlines()

with tmpdir.as_cwd() as prev:
for file_ in [fname.strip() for fname in manifest]:
if file_:
cp(os.path.join(str(prev), file_), tmpdir / file_, create_dirs=True)
os.makedirs(tmpdir / os.path.dirname(file_), exist_ok=True)
shutil.copy2(os.path.join(prev, file_), tmpdir / file_)
# cp(os.path.join(str(prev), file_), tmpdir / file_, create_dirs=True)

bmi = Bmi()
bmi.initialize(INPUT_FILE)
Expand Down
Loading

0 comments on commit 3d2abe8

Please sign in to comment.