Skip to content

Commit

Permalink
Update project metadata and continuous integration (#2)
Browse files Browse the repository at this point in the history
* Remove deprecated versioneer package

* Move metadata from setup.py to pyproject.toml

* Add version file

* Rename license file

* Move README from rst to md

* Add credits doc and changelog

* Include version in package

* Include netcdf4 dependency

* Replace deprecated np.int and np.float types

* Use float64 instead of float32 values

* Use conda environment file over pip requirements files

* Update Makefile and manifest

* Also test the component's BMI

* Remove deprecated numpy types

* Set up CI with GitHub Actions

* Make pretty

* Use conda convention of .yml

* Include coverage dependency
  • Loading branch information
mdpiper authored Nov 11, 2024
1 parent b59caad commit 876c888
Show file tree
Hide file tree
Showing 26 changed files with 325 additions and 2,583 deletions.
1 change: 0 additions & 1 deletion .gitattributes

This file was deleted.

32 changes: 32 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Lint

on: [push, pull_request]

concurrency:
group: ${{ github.ref }}-${{ github.workflow }}
cancel-in-progress: true

jobs:

lint:
name: Check for lint and format code to a standard style
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: conda-incubator/setup-miniconda@v3
with:
miniforge-version: latest
python-version: 3.12
auto-activate-base: false

- name: Install black and flake8
run: pip install black flake8

- name: Format code
run: |
flake8 .
black .
56 changes: 56 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: Test

on: [push, pull_request]

concurrency:
group: ${{ github.ref }}-${{ github.workflow }}
cancel-in-progress: true

jobs:
build-and-test:
if:
github.event_name == 'push' || github.event.pull_request.head.repo.full_name != github.repository

runs-on: ${{ matrix.os }}

defaults:
run:
shell: bash -l {0}

strategy:
matrix:
os: [ubuntu-latest, macos-latest]
python-version: ["3.10", "3.11", "3.12", "3.13"]

steps:
- uses: actions/checkout@v4

- uses: conda-incubator/setup-miniconda@v3
with:
miniforge-version: latest
activate-environment: gridmet_bmi
environment-file: environment.yml
python-version: ${{ matrix.python-version }}

- name: Show conda installation info
run: |
conda info
conda list
- name: Build and install package
run: |
make install
- name: Run unit tests
run: |
pytest
- name: Test BMI
if: ${{ matrix.python-version == '3.12' }}
run: |
make test-bmi
- name: Run examples
working-directory: ${{ github.workspace }}/examples
run: |
python debug.py
41 changes: 0 additions & 41 deletions .travis.yml

This file was deleted.

10 changes: 10 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Changes for gridmet_bmi

## 0.2.0 (unreleased)

- Nothing yet.


## 0.1 (2021-01-15)

- Initial release.
16 changes: 16 additions & 0 deletions CREDITS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Credits

## Project lead

* Rich McDonald

## Contributors

* Eric Hutton
* Mark Piper

## Acknowledgments

This work was supported by the National Science Foundation under Award No.
[2026951](https://www.nsf.gov/awardsearch/showAward?AWD_ID=2026951),
*EarthCube Capabilities: Cloud-Based Accessible and Reproducible Modeling for Water and Sediment Research*.
File renamed without changes.
7 changes: 4 additions & 3 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
include versioneer.py
include gridmet_bmi/_version.py

include *.md
include environment.yml
include examples/*
recursive-include tests *
20 changes: 12 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,21 @@ clean-test: ## remove test and coverage artifacts
rm -fr .pytest_cache

lint: ## check style with flake8

flake8 gridmet_bmi tests
flake8 gridmet_bmi tests examples

pretty: ## reformat files to make them look pretty
find gridmet_bmi tests -name '*.py' | xargs isort
black setup.py gridmet_bmi tests
find gridmet_bmi tests examples -name '*.py' | xargs isort
black gridmet_bmi tests examples

test: ## run tests quickly with the default Python
pytest --cov=gridmet_bmi

test-bmi: ## test the component's BMI
bmi-test gridmet_bmi.bmi_gridmet:BmiGridmet \
--config-file=${PWD}/examples/gridmet_bmi.yaml \
--root-dir=examples \
-vvv

benchmark: ## run benchmarks only
pytest --benchmark-only --benchmark-autosave

Expand All @@ -75,7 +80,6 @@ coverage: ## check code coverage quickly with the default Python
$(BROWSER) htmlcov/index.html

docs: ## generate Sphinx HTML documentation, including API docs

rm -f docs/api/gridmet_bmi.rst
rm -f docs/api/modules.rst
# sphinx-apidoc -o docs/api --separate --no-toc gridmet_bmi
Expand All @@ -88,12 +92,12 @@ servedocs: docs ## compile the docs watching for changes
watchmedo shell-command -p '*.rst' -c '$(MAKE) -C docs html' -R -D .

release: dist ## package and upload a release
twine check dist/*
twine upload dist/*

dist: clean ## builds source and wheel package
python setup.py sdist
python setup.py bdist_wheel
python -m build
ls -l dist

install: clean ## install the package to the active Python's site-packages
python setup.py install
pip install .
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Gridmet_BMI

Python and command-line interface to the GridMet climate data services.
11 changes: 0 additions & 11 deletions README.rst

This file was deleted.

6 changes: 5 additions & 1 deletion environment.yaml → environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,9 @@ dependencies:
- requests
- netcdf4
- xarray
- pandas
- geopandas
- matplotlib
- rasterio
- pytest
- coverage
- bmi-tester
16 changes: 6 additions & 10 deletions examples/debug.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import matplotlib.pyplot as plt
from gridmet_bmi import BmiGridmet
import numpy as np
import numpy.testing as npt
import tempfile
import yaml
import datetime


def print_times(x):
Expand All @@ -20,19 +16,19 @@ def print_times(x):
x.initialize()
print(x.get_input_var_names())
print(x.get_output_var_names())
grid_id = x.get_var_grid('daily_maximum_temperature')
grid_id = x.get_var_grid("daily_maximum_temperature")
size = x.get_grid_size(grid_id)
shape = np.empty(2, dtype=np.int)
origin = np.empty(2, dtype=np.float)
delta = np.empty(2, dtype=np.float)
shape = np.empty(2, dtype=int)
origin = np.empty(2, dtype=float)
delta = np.empty(2, dtype=float)
x.get_grid_origin(grid_id, origin)
x.get_grid_spacing(grid_id, spacing=delta)
tmp = x.get_grid_shape(grid_id, shape)
print(type(shape), shape[0], shape[1], shape)
tmp2 = np.array([585, 1386])
npt.assert_almost_equal(shape, np.array([585, 1386]))
vals = np.zeros(size)
x.get_value('daily_maximum_temperature', vals)
x.get_value("daily_maximum_temperature", vals)
print(np.nanmin(vals))
print(np.nanmax(vals))
print_times(x)
Expand All @@ -46,4 +42,4 @@ def print_times(x):
# fp.write((yaml.dump(yamldict, sort_keys=False)))
# name = fp.name

# print(name)
# print(name)
9 changes: 4 additions & 5 deletions examples/debug2.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import matplotlib.pyplot as plt
from gridmet_bmi import BmiGridmet, Gridmet
import numpy as np
from gridmet_bmi import Gridmet

gridmet = Gridmet(start_date='2019-03-15', end_date='2019-03-21', lazy=True)

gridmet = Gridmet(start_date="2019-03-15", end_date="2019-03-21", lazy=True)
# assert len(getattr(gridmet, 'tmax')) == 1
print(len(gridmet.tmax), type(gridmet.tmax))
tmp = 0
tmp = 0
9 changes: 2 additions & 7 deletions gridmet_bmi/__init__.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
from ._version import get_versions
from .bmi_gridmet import BmiGridmet

# from examples.bmi import BmiGridmet
from .gridmet import Gridmet
from .helpers import getaverage, np_get_wval
from ._version import __version__

__all__ = ["BmiGridmet", "Gridmet", "np_get_wval", "getaverage"]

__version__ = get_versions()["version"]
del get_versions
__all__ = ["BmiGridmet", "Gridmet", "np_get_wval", "getaverage", "__version__"]
Loading

0 comments on commit 876c888

Please sign in to comment.