Skip to content

Commit

Permalink
Merge branch 'master' into v03_with_new_fields
Browse files Browse the repository at this point in the history
  • Loading branch information
zdefne-usgs authored Jun 9, 2022
2 parents ecb904a + 433a9e2 commit 98c3f11
Show file tree
Hide file tree
Showing 12 changed files with 209 additions and 198 deletions.
36 changes: 36 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Tests

on:
pull_request:
push:
branches: [master,main]

jobs:
run:
runs-on: ${{ matrix.os }}
strategy:
matrix:
python-version: ["3.7", "3.8", "3.9", "3.10"]
os: [windows-latest, ubuntu-latest, macos-latest]
fail-fast: false

steps:
- uses: actions/checkout@v3

- name: Setup Micromamba
uses: mamba-org/provision-with-micromamba@main
with:
environment-file: false

- name: Python ${{ matrix.python-version }}
shell: bash -l {0}
run: |
micromamba create --name TEST python=${{ matrix.python-version }} --file requirements.txt --file requirements-dev.txt --channel conda-forge
micromamba activate TEST
python -m pip install -e . --no-deps --force-reinstall
- name: Tests
shell: bash -l {0}
run: |
micromamba activate TEST
python -m pytest -rxs tests
28 changes: 0 additions & 28 deletions .travis.yml

This file was deleted.

1 change: 0 additions & 1 deletion LICENSE.txt
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.

6 changes: 3 additions & 3 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ roms.yaml
title: "USGS-CMG-COAWST Model: CBLAST2007 Ripples with SWAN-40m res"
summary: "Simulation of hydrodynamics and bottom stress south of Marthas Vineyard, MA using the COAWST modeling system. These results are from the 40m inner nest of a four-level nested simulation."
project:
- CMG_Portal
- Sandy_Portal
Expand Down Expand Up @@ -85,9 +85,9 @@ roms.yaml
pattern: .*test_nc4_[0-9]{4}\.nc$
Notes on the YAML file:
Notes on the YAML file:

1. The aggregation `dir:` is the directory where the data (e.g. NetCDF files) are located, relative to the directory where the NcML will be. In the above example, the NetCDF files are located in a subdirectory called "Output". If the NetCDF files will be in the same directory as the NcML file, specify `dir: '.'`.
1. The aggregation `dir:` is the directory where the data (e.g. NetCDF files) are located, relative to the directory where the NcML will be. In the above example, the NetCDF files are located in a subdirectory called "Output". If the NetCDF files will be in the same directory as the NcML file, specify `dir: '.'`.

2. Specify that all variables should appear in the aggregation (none excluded) like this:

Expand Down
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
docopt
netCDF4
ruamel.yaml
six
64 changes: 34 additions & 30 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,29 +1,31 @@
import os
import sys

from setuptools import setup
from setuptools.command.test import test as TestCommand


class PyTest(TestCommand):
def finalize_options(self):
TestCommand.finalize_options(self)
self.test_args = ['--verbose']
self.test_args = ["--verbose"]
self.test_suite = True

def run_tests(self):
import pytest

errno = pytest.main(self.test_args)
sys.exit(errno)


def extract_version():
version = None
fdir = os.path.dirname(__file__)
fnme = os.path.join(fdir, 'yaml2ncml', '__init__.py')
fnme = os.path.join(fdir, "yaml2ncml", "__init__.py")
with open(fnme) as fd:
for line in fd:
if (line.startswith('__version__')):
_, version = line.split('=')
if line.startswith("__version__"):
_, version = line.split("=")
version = version.strip()[1:-1]
break
return version
Expand All @@ -33,35 +35,37 @@ def extract_version():


def read(*parts):
return open(os.path.join(rootpath, *parts), 'r').read()
return open(os.path.join(rootpath, *parts)).read()


long_description = '{}\n{}'.format(read('README.rst'), read('CHANGES.txt'))
LICENSE = read('LICENSE.txt')
long_description = "{}\n{}".format(read("README.rst"), read("CHANGES.txt"))
LICENSE = read("LICENSE.txt")

with open('requirements.txt') as f:
with open("requirements.txt") as f:
require = f.readlines()
install_requires = [r.strip() for r in require]

setup(name='yaml2ncml',
version=extract_version(),
packages=['yaml2ncml'],
license=LICENSE,
description='ncML aggregation from YAML specifications',
long_description=long_description,
author='Rich Signell',
author_email='rsignell@usgs.gov',
install_requires=install_requires,
entry_points=dict(console_scripts=[
'yaml2ncml = yaml2ncml.yaml2ncml:main']
),
url='https://github.com/rsignell-usgs/yaml2ncml',
keywords=['YAML', 'ncml'],
classifiers=['Development Status :: 4 - Beta',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
'License :: OSI Approved :: MIT License'],
tests_require=['pytest'],
cmdclass=dict(test=PyTest),
zip_safe=False)
setup(
name="yaml2ncml",
version=extract_version(),
packages=["yaml2ncml"],
license=LICENSE,
description="ncML aggregation from YAML specifications",
long_description=long_description,
author="Rich Signell",
author_email="rsignell@usgs.gov",
install_requires=install_requires,
entry_points=dict(console_scripts=["yaml2ncml = yaml2ncml.yaml2ncml:main"]),
url="https://github.com/rsignell-usgs/yaml2ncml",
keywords=["YAML", "ncml"],
classifiers=[
"Development Status :: 4 - Beta",
"Programming Language :: Python :: 2.7",
"Programming Language :: Python :: 3.4",
"Programming Language :: Python :: 3.5",
"License :: OSI Approved :: MIT License",
],
tests_require=["pytest"],
cmdclass=dict(test=PyTest),
zip_safe=False,
)
2 changes: 1 addition & 1 deletion tests/base_roms_test.ncml
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,6 @@
<values start="-1.0" increment="-0.01"/>
</variable>
<aggregation dimName="ocean_time" type="joinExisting">
<scan location="data/" regExp=".*test_nc4_[0-9]{4}\.nc$" subdirs="false"/>
<scan location="tests/data/" regExp=".*test_nc4_[0-9]{4}\.nc$" subdirs="false"/>
</aggregation>
</netcdf>
2 changes: 1 addition & 1 deletion tests/roms_0.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,6 @@ variables:

aggregation:
time_var: ocean_time
dir: data/
dir: tests/data/
sample_file: test_nc4_0001.nc
pattern: .*test_nc4_[0-9]{4}\.nc$
15 changes: 6 additions & 9 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
from __future__ import (absolute_import, division, print_function)

import pytest
from docopt import DocoptExit
from docopt import docopt

from yaml2ncml import yaml2ncml
Expand All @@ -10,18 +7,18 @@


def test_noarg_call():
with pytest.raises(DocoptExit):
with pytest.raises(SystemExit):
yaml2ncml.main()


def test_mandatory_arg():
fin = 'roms.yaml'
fin = "roms.yaml"
args = docopt(__doc__, [fin])
assert args['INFILE'] == fin
assert args["INFILE"] == fin


def test_optional_arg():
fin = 'test6.ncml'
fout = '--output=test6.ncml'
fin = "test6.ncml"
fout = "--output=test6.ncml"
args = docopt(__doc__, [fin, fout])
assert args['--output'] == fout.split('=')[1]
assert args["--output"] == fout.split("=")[1]
36 changes: 18 additions & 18 deletions tests/test_yaml2ncml.py
Original file line number Diff line number Diff line change
@@ -1,41 +1,41 @@
from __future__ import (absolute_import, division, print_function)

import subprocess
import tempfile
from pathlib import Path

import pytest
import ruamel.yaml as yaml

from yaml2ncml import build

path = Path(__file__).parent.resolve()


def test_call():
output = subprocess.check_output(['yaml2ncml', 'roms_0.yaml'])
with open('base_roms_test.ncml') as f:
expected = f.read()
assert output.decode() == expected
fname = str(path.joinpath("roms_0.yaml"))
output = subprocess.check_output(["yaml2ncml", fname]).decode()
output = [line.strip() for line in output.splitlines()]
with path.joinpath("base_roms_test.ncml").open() as f:
expected = [line.strip() for line in f.read().splitlines()]
assert output == expected


def test_save_file():
outfile = tempfile.mktemp(suffix='.ncml')
subprocess.call(['yaml2ncml',
'roms_0.yaml',
'--output={}'.format(outfile)])
with open('base_roms_test.ncml') as f:
outfile = tempfile.mktemp(suffix=".ncml")
fname = str(path.joinpath("roms_0.yaml"))
subprocess.call(["yaml2ncml", fname, f"--output={outfile}"])
with path.joinpath("base_roms_test.ncml").open() as f:
expected = f.read()
with open(outfile) as f:
output = f.read()
assert output == expected


@pytest.fixture
def load_ymal(fname='roms_1.yaml'):
with open(fname, 'r') as stream:
yml = yaml.load(stream, Loader=yaml.RoundTripLoader)
return yml
def load_ymal(fname=path.joinpath("roms_1.yaml")):
with open(fname) as stream:
yield yaml.load(stream, Loader=yaml.RoundTripLoader)


def test_bad_yaml():
def test_bad_yaml(load_ymal):
with pytest.raises(ValueError):
yml = load_ymal(fname='roms_1.yaml')
build(yml)
build(load_ymal)
12 changes: 3 additions & 9 deletions yaml2ncml/__init__.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
from __future__ import (absolute_import, division, print_function)
from yaml2ncml.yaml2ncml import build, main

from yaml2ncml.yaml2ncml import main, build
__version__ = "0.7.3"


__version__ = '0.7.2'

__all__ = [
'main',
'build'
]
__all__ = ["main", "build"]
Loading

0 comments on commit 98c3f11

Please sign in to comment.