From 0eeda28eb1c19977d352d66e61780712f8b67430 Mon Sep 17 00:00:00 2001 From: Vecko <36369090+VeckoTheGecko@users.noreply.github.com> Date: Fri, 6 Dec 2024 16:58:04 +0100 Subject: [PATCH 01/11] migrate to pyproject.toml using `hatch new --init` https://stackoverflow.com/q/72832052/15545258 --- pyproject.toml | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++ setup.py | 33 ------------------------------- 2 files changed, 53 insertions(+), 33 deletions(-) delete mode 100644 setup.py diff --git a/pyproject.toml b/pyproject.toml index 774c93b..a65f814 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,3 +1,56 @@ +[build-system] +requires = ["hatchling"] +build-backend = "hatchling.build" + +[project] +name = "pyglider" +dynamic = ["version"] +description = "Glider data to netCDF translation in python" +readme = "README.md" +license = "Apache" +requires-python = ">=3.6" +authors = [ + { name = "Jody Klymak", email = "jklymak@gmail.com" }, +] +dependencies = [ + "bitstring", + "dask", + "gsw", + "netcdf4", + "polars", + "pooch", + "scipy", + "xarray", +] + +[project.optional-dependencies] +code_style = [ + "black", + "flake8<3.8.0,>=3.7.0", + "pre-commit==1.17.0", +] +docs = [ + "autoapi", + "myst-parser", + "numpydoc", + "pydata-sphinx-theme", + "sphinx", +] +testing = [ + "pytest", + "pytest-cov", +] + +[project.urls] +Homepage = "https://pyglider.readthedocs.io" + +[tool.hatch.version] +path = "pyglider/__init__.py" + +[tool.hatch.build.targets.sdist] +include = [ + "/pyglider", +] [tool.pytest.ini_options] addopts = ["--strict-config", "--strict-markers"] testpaths = ["tests"] diff --git a/setup.py b/setup.py deleted file mode 100644 index 32ea70f..0000000 --- a/setup.py +++ /dev/null @@ -1,33 +0,0 @@ -from setuptools import find_packages, setup - -from pyglider._version import __version__ - -setup( - name='pyglider', - version=__version__, - description='Glider data to netCDF translation in python', - author='Jody Klymak', - author_email='jklymak@gmail.com', - url='https://pyglider.readthedocs.io', - packages=find_packages(exclude=['tests']), - python_requires='>=3.6', - install_requires=[ - 'xarray', - 'dask', - 'netcdf4', - 'gsw', - 'scipy', - 'bitstring', - 'pooch', - 'polars', - ], - license='Apache', - extras_require={ - 'code_style': ['flake8<3.8.0,>=3.7.0', 'black', 'pre-commit==1.17.0'], - 'testing': ['pytest', 'pytest-cov'], - 'docs': ['pydata-sphinx-theme', 'numpydoc', 'autoapi', 'myst-parser', 'sphinx'], - }, - zip_safe=True, - long_description=open('README.md').read(), - long_description_content_type='text/markdown', -) From 1a8283376555fd14e88a27a06e28f243e4320231 Mon Sep 17 00:00:00 2001 From: Vecko <36369090+VeckoTheGecko@users.noreply.github.com> Date: Fri, 6 Dec 2024 17:00:51 +0100 Subject: [PATCH 02/11] pyproject: Update license ref to file and fix version --- pyproject.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index a65f814..d3d30be 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -7,7 +7,7 @@ name = "pyglider" dynamic = ["version"] description = "Glider data to netCDF translation in python" readme = "README.md" -license = "Apache" +license = { file = "LICENSE" } requires-python = ">=3.6" authors = [ { name = "Jody Klymak", email = "jklymak@gmail.com" }, @@ -45,7 +45,7 @@ testing = [ Homepage = "https://pyglider.readthedocs.io" [tool.hatch.version] -path = "pyglider/__init__.py" +path = "pyglider/_version.py" [tool.hatch.build.targets.sdist] include = [ From bb155225998cb3f9c4007465f07bc517f46b63c0 Mon Sep 17 00:00:00 2001 From: Vecko <36369090+VeckoTheGecko@users.noreply.github.com> Date: Fri, 6 Dec 2024 17:03:05 +0100 Subject: [PATCH 03/11] Update shell --- .github/workflows/tests.yml | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index f9641ed..7366b0e 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -1,5 +1,10 @@ name: Test pyglider on: [push, pull_request] + +defaults: + run: + shell: bash -el {0} + jobs: test-gliders: name: pyglider (${{ matrix.python-version }}, ${{ matrix.os }}) @@ -18,22 +23,16 @@ jobs: create-args: >- python=${{ matrix.python-version }} - name: Conda info - shell: micromamba-shell {0} run: conda info; conda list - name: install pyglider source - shell: micromamba-shell {0} run: which pip; pip install -e . - name: Process seaexplorer - shell: micromamba-shell {0} run: which python; cd tests/example-data/example-seaexplorer; make clean-all; python process_deploymentRealTime.py - name: Process slocum - shell: micromamba-shell {0} run: which python; cd tests/example-data/example-slocum; make clean-all; python process_deploymentRealTime.py - name: Process seaexplorer-legato-flntu-arod-ad2cp - shell: micromamba-shell {0} run: which python; cd tests/example-data/example-seaexplorer-legato-flntu-arod-ad2cp; make clean-all; python process_deploymentRealTime.py - name: Run tests - shell: micromamba-shell {0} run: which python; pytest --cov --cov-report xml - name: Upload coverage to Codecov uses: codecov/codecov-action@v4 From cb31aae95763322a16569478c1dd36e1aa45dd5a Mon Sep 17 00:00:00 2001 From: Vecko <36369090+VeckoTheGecko@users.noreply.github.com> Date: Fri, 6 Dec 2024 17:06:12 +0100 Subject: [PATCH 04/11] update formatting --- .github/workflows/tests.yml | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 7366b0e..754ce8f 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -23,16 +23,34 @@ jobs: create-args: >- python=${{ matrix.python-version }} - name: Conda info - run: conda info; conda list + run: | + conda info + conda list - name: install pyglider source - run: which pip; pip install -e . + run: | + which pip + pip install -e . - name: Process seaexplorer - run: which python; cd tests/example-data/example-seaexplorer; make clean-all; python process_deploymentRealTime.py + run: | + which python + cd tests/example-data/example-seaexplorer + make clean-all + python process_deploymentRealTime.py - name: Process slocum - run: which python; cd tests/example-data/example-slocum; make clean-all; python process_deploymentRealTime.py + run: | + which python + cd tests/example-data/example-slocum + make clean-all + python process_deploymentRealTime.py - name: Process seaexplorer-legato-flntu-arod-ad2cp - run: which python; cd tests/example-data/example-seaexplorer-legato-flntu-arod-ad2cp; make clean-all; python process_deploymentRealTime.py + run: | + which python + cd tests/example-data/example-seaexplorer-legato-flntu-arod-ad2cp + make clean-all + python process_deploymentRealTime.py - name: Run tests - run: which python; pytest --cov --cov-report xml + run: | + which python + pytest --cov --cov-report xml - name: Upload coverage to Codecov uses: codecov/codecov-action@v4 From f69674dafedda9202b1d36c2f45def3f74541003 Mon Sep 17 00:00:00 2001 From: Vecko <36369090+VeckoTheGecko@users.noreply.github.com> Date: Wed, 11 Dec 2024 17:36:36 +0100 Subject: [PATCH 05/11] update min python version to 3.9 --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index d3d30be..a881076 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -8,7 +8,7 @@ dynamic = ["version"] description = "Glider data to netCDF translation in python" readme = "README.md" license = { file = "LICENSE" } -requires-python = ">=3.6" +requires-python = ">=3.9" authors = [ { name = "Jody Klymak", email = "jklymak@gmail.com" }, ] From 8422f921a721df9a07210016c67cceec7fdd89d6 Mon Sep 17 00:00:00 2001 From: Vecko <36369090+VeckoTheGecko@users.noreply.github.com> Date: Wed, 11 Dec 2024 17:38:26 +0100 Subject: [PATCH 06/11] add classifiers and flag 3.13 support --- .github/workflows/tests.yml | 2 +- pyproject.toml | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 754ce8f..c9456fd 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -12,7 +12,7 @@ jobs: strategy: matrix: os: ["ubuntu-latest"] - python-version: ["3.9", "3.10", "3.11", "3.12"] + python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"] steps: - uses: actions/checkout@v4 - name: mamba setup enviroment diff --git a/pyproject.toml b/pyproject.toml index a881076..86f003a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -9,6 +9,17 @@ description = "Glider data to netCDF translation in python" readme = "README.md" license = { file = "LICENSE" } requires-python = ">=3.9" +classifiers = [ + "License :: OSI Approved :: Apache Software License", + "Programming Language :: Python :: 3.9", + "Programming Language :: Python :: 3.10", + "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: 3.12", + "Programming Language :: Python :: 3.13", + "Operating System :: OS Independent", + "Topic :: Scientific/Engineering", + "Intended Audience :: Science/Research", +] authors = [ { name = "Jody Klymak", email = "jklymak@gmail.com" }, ] From ac0facd565e84c80ba3d4bd622b35445d80e9610 Mon Sep 17 00:00:00 2001 From: Vecko <36369090+VeckoTheGecko@users.noreply.github.com> Date: Wed, 11 Dec 2024 17:44:44 +0100 Subject: [PATCH 07/11] Remove debugging statements in CI --- .github/workflows/tests.yml | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index c9456fd..1fb5c52 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -22,35 +22,25 @@ jobs: environment-file: tests/environment.yml create-args: >- python=${{ matrix.python-version }} - - name: Conda info - run: | - conda info - conda list - name: install pyglider source run: | - which pip pip install -e . - name: Process seaexplorer run: | - which python cd tests/example-data/example-seaexplorer make clean-all python process_deploymentRealTime.py - name: Process slocum run: | - which python cd tests/example-data/example-slocum make clean-all python process_deploymentRealTime.py - name: Process seaexplorer-legato-flntu-arod-ad2cp run: | - which python cd tests/example-data/example-seaexplorer-legato-flntu-arod-ad2cp make clean-all python process_deploymentRealTime.py - name: Run tests - run: | - which python - pytest --cov --cov-report xml + run: pytest --cov --cov-report xml - name: Upload coverage to Codecov uses: codecov/codecov-action@v4 From 5a9e77aeaf8b2be30e9e1b28ca359974c1cd5876 Mon Sep 17 00:00:00 2001 From: Vecko <36369090+VeckoTheGecko@users.noreply.github.com> Date: Wed, 11 Dec 2024 18:30:45 +0100 Subject: [PATCH 08/11] Add contributing page and consolidate installation Migrate all developer installation details to a single conda environment file --- .circleci/config.yml | 31 -------------------- .github/CONTRIBUTING.md | 1 + .github/workflows/tests.yml | 2 +- .readthedocs.yaml | 36 ++--------------------- docs-requirements.txt | 16 ----------- docs/Install.md | 12 +------- docs/contributing.md | 57 +++++++++++++++++++++++++++++++++++++ docs/index.md | 1 + environment.yml | 24 ++++++++++++++-- pyproject.toml | 18 ------------ tests/environment.yml | 22 -------------- 11 files changed, 86 insertions(+), 134 deletions(-) delete mode 100644 .circleci/config.yml create mode 100644 .github/CONTRIBUTING.md delete mode 100644 docs-requirements.txt create mode 100644 docs/contributing.md delete mode 100644 tests/environment.yml diff --git a/.circleci/config.yml b/.circleci/config.yml deleted file mode 100644 index 17da7d6..0000000 --- a/.circleci/config.yml +++ /dev/null @@ -1,31 +0,0 @@ -version: 2.1 - -orbs: - python: circleci/python@0.2.1 - -jobs: - build_docs: - executor: python/default - steps: - - checkout - - run: - name: Install Python dependencies - command: | - python -m pip install --user \ - -r docs-requirements.txt - - run: - name: install module - command: python -m pip install --user -ve . - - run: - name: Build docs - command: cd docs/ && make html - - persist_to_workspace: - root: docs/_build/html - paths: . - - store_artifacts: - path: docs/_build/html/ - -workflows: - main: - jobs: - - build_docs diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md new file mode 100644 index 0000000..05822e6 --- /dev/null +++ b/.github/CONTRIBUTING.md @@ -0,0 +1 @@ +Follow the instructions in our [contributing page](./contributing.md). diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 1fb5c52..746c34d 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -19,7 +19,7 @@ jobs: uses: mamba-org/setup-micromamba@v1.9.0 with: environment-name: test-env - environment-file: tests/environment.yml + environment-file: environment.yml create-args: >- python=${{ matrix.python-version }} - name: install pyglider source diff --git a/.readthedocs.yaml b/.readthedocs.yaml index e55e259..13922d8 100644 --- a/.readthedocs.yaml +++ b/.readthedocs.yaml @@ -1,41 +1,11 @@ -# Read the Docs configuration file for Sphinx projects -# See https://docs.readthedocs.io/en/stable/config-file/v2.html for details - -# Required version: 2 - -# Set the OS, Python version and other tools you might need build: os: ubuntu-22.04 tools: - python: "3.12" - # You can also specify other tool versions: - # nodejs: "20" - # rust: "1.70" - # golang: "1.20" + python: mambaforge-22.9 -# Build documentation in the "docs/" directory with Sphinx sphinx: configuration: docs/conf.py - # You can configure Sphinx to use a different builder, for instance use the dirhtml builder for simpler URLs - # builder: "dirhtml" - # Fail on all warnings to avoid broken references - # fail_on_warning: true - -python: - install: - - requirements: docs-requirements.txt - # Install our python package before building the docs - - method: pip - path: . -# Optionally build your docs in additional formats such as PDF and ePub -# formats: -# - pdf -# - epub -# Optional but recommended, declare the Python requirements required -# to build your documentation -# See https://docs.readthedocs.io/en/stable/guides/reproducible-builds.html -# python: -# install: -# - requirements: docs/requirements.txt +conda: + environment: environment.yml diff --git a/docs-requirements.txt b/docs-requirements.txt deleted file mode 100644 index 862da0e..0000000 --- a/docs-requirements.txt +++ /dev/null @@ -1,16 +0,0 @@ -numpy -xarray -dask -netcdf4 -gsw -scipy -pooch -bitstring -pydata-sphinx-theme -sphinx -pytest -autoapi -numpydoc -myst-parser -dbdreader -polars>=0.16 diff --git a/docs/Install.md b/docs/Install.md index b669500..d4ac905 100644 --- a/docs/Install.md +++ b/docs/Install.md @@ -14,14 +14,4 @@ conda install -c conda-forge pyglider ## Editable installation -If you want to be able to edit the files in `pyglider/pyglider` then install -the dependencies as above. Fork of PyGlider on github, and then clone it locally: - -``` -git clone https://github.com/yourname/pyglider.git -``` - -Navigate to the new `pyglider` directory and then do `pip install -e .`. -That will re-install pyglider with links to the local directory, so you -can edit the library files. If you do so, consider making a pull-request -with your changes! +Follow the instructions in our [contributing page](./contributing.md). diff --git a/docs/contributing.md b/docs/contributing.md new file mode 100644 index 0000000..d3b0e84 --- /dev/null +++ b/docs/contributing.md @@ -0,0 +1,57 @@ +# Contributing + +## Create a fork + +```{note} +TODO: Create contributing page noting: +- the forking process (trimmed down) +``` + +## Development environment + +Assuming that you have Anaconda/Miniconda installed, you can create a new environment for development: + +```bash +conda create -n pyglider-dev python=3.9 +conda activate pyglider-dev +``` + +Then install the dependencies: + +```bash +conda env update -f environment.yml -n pyglider-dev +``` + +And install the package in editable mode: + +```bash +pip install -e . --no-build-isolation --no-deps +``` + +Done! + +--- + +From here, you can make the changes you want, and add tests. When you are ready, you can create a pull request into the codebase. + +## Running tests + +Once the development environment is set up, you can run the tests with: + +```bash +pytest +``` + +## Building documentation + +```{note} +TODO +``` + +## [Optional] Running pre-commit + +We use pre-commit [TODO link] to run tooling on the code to make sure that it adheres to standards that we have adopted in the codebase. This is done automatically in the cloud on all pull requests, however this can also be done locally. + +Pre-commit is already a dependency in the `environment.yml` file, so you only have to do `pre-commit install` in the repository (this will install the hooks in the repository so that they run when you commit changes). + +That's it! If you want to, you can manually run the hooks by doing `pre-commit run --all-files` (or `pre-commit run` if you only want to run on staged files). diff --git a/docs/index.md b/docs/index.md index 3b4fcaa..e28f83b 100644 --- a/docs/index.md +++ b/docs/index.md @@ -29,6 +29,7 @@ Install getting-started-seaexplorer getting-started-slocum pyglider/pyglider +contributing ``` diff --git a/environment.yml b/environment.yml index 342ac48..0ffe2a2 100644 --- a/environment.yml +++ b/environment.yml @@ -1,8 +1,9 @@ -name: pyglider +name: pyglider-dev channels: - conda-forge dependencies: - - python>=3.10 + # Core + - python>=3.9 - numpy - pip - xarray @@ -13,5 +14,24 @@ dependencies: - scipy - bitstring - pooch + + # Testing + - pytest + - pytest-cov + - matplotlib + - compliance-checker + - cc-plugin-glider + + # Docs + - pydata-sphinx-theme + - sphinx + - sphinx-autoapi + - numpydoc + - myst-parser + + # QAQC + - pre_commit + - pip: + # Core - dbdreader diff --git a/pyproject.toml b/pyproject.toml index 86f003a..a820d9f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -34,24 +34,6 @@ dependencies = [ "xarray", ] -[project.optional-dependencies] -code_style = [ - "black", - "flake8<3.8.0,>=3.7.0", - "pre-commit==1.17.0", -] -docs = [ - "autoapi", - "myst-parser", - "numpydoc", - "pydata-sphinx-theme", - "sphinx", -] -testing = [ - "pytest", - "pytest-cov", -] - [project.urls] Homepage = "https://pyglider.readthedocs.io" diff --git a/tests/environment.yml b/tests/environment.yml deleted file mode 100644 index cde877e..0000000 --- a/tests/environment.yml +++ /dev/null @@ -1,22 +0,0 @@ -name: pyglider-test -channels: - - conda-forge -dependencies: - - python>=3.9 - - numpy - - pip - - xarray - - dask - - netcdf4 - - gsw - - scipy - - bitstring - - polars>=1.1 - - pytest - - pytest-cov - - pooch - - matplotlib - - compliance-checker - - cc-plugin-glider - - pip: - - dbdreader From 1f2961103f18d52b8cc26f3e644e5bef7fae9ac6 Mon Sep 17 00:00:00 2001 From: Vecko <36369090+VeckoTheGecko@users.noreply.github.com> Date: Wed, 11 Dec 2024 18:36:24 +0100 Subject: [PATCH 09/11] Add dependabot config Update every month --- .github/dependabot.yml | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 .github/dependabot.yml diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..8ac6b8c --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,6 @@ +version: 2 +updates: + - package-ecosystem: "github-actions" + directory: "/" + schedule: + interval: "monthly" From 70351325aa8000ba4b7bf25b7b8b184f9bd3e56a Mon Sep 17 00:00:00 2001 From: Vecko <36369090+VeckoTheGecko@users.noreply.github.com> Date: Wed, 11 Dec 2024 19:14:04 +0100 Subject: [PATCH 10/11] fix conf.py --- docs/conf.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/docs/conf.py b/docs/conf.py index 80cac14..11dbcaa 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -25,7 +25,8 @@ # The full version, including alpha/beta/rc tags release = __version__ - +master_doc = 'index' +source_suffix = ['.rst', '.md'] # -- General configuration --------------------------------------------------- # Add any Sphinx extension module names here, as strings. They can be @@ -36,7 +37,7 @@ 'myst_parser', 'sphinx.ext.autodoc', 'sphinx.ext.inheritance_diagram', - 'autoapi.sphinx', + 'autoapi.extension', ] extensions.append('sphinx.ext.intersphinx') @@ -46,7 +47,7 @@ 'python': ('https://docs.python.org/3/', None), } -autoapi_modules = {'pyglider': None} +autoapi_dirs = ['../pyglider'] # Add any paths that contain templates here, relative to this directory. templates_path = ['_templates'] From f0eed7ae35ca26a307e420301643022e5066884e Mon Sep 17 00:00:00 2001 From: Vecko <36369090+VeckoTheGecko@users.noreply.github.com> Date: Thu, 12 Dec 2024 11:24:22 +0100 Subject: [PATCH 11/11] Refactor test paths --- tests/__init__.py | 0 tests/test_pyglider.py | 34 +++++++++++++++------------------- tests/test_seaexplorer.py | 22 ++++++++++------------ tests/test_slocum.py | 25 +++++++++++-------------- tests/test_utils.py | 10 +++------- tests/utils.py | 6 ++++++ 6 files changed, 45 insertions(+), 52 deletions(-) create mode 100644 tests/__init__.py create mode 100644 tests/utils.py diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/test_pyglider.py b/tests/test_pyglider.py index f552d12..c072ca2 100644 --- a/tests/test_pyglider.py +++ b/tests/test_pyglider.py @@ -1,28 +1,24 @@ -from pathlib import Path - import numpy as np import pytest import xarray as xr import yaml import pyglider.seaexplorer as seaexplorer - -library_dir = Path(__file__).parent.parent.absolute() -example_dir = library_dir / 'tests/example-data/' +from tests.utils import EXAMPLE_DIR, LIBRARY_DIR # Create an L0 timeseries from seaexplorer data and test that the resulting netcdf # is identical to the test data -rawdir = str(example_dir / 'example-seaexplorer/realtime_raw/') + '/' -rawncdir = str(example_dir / 'example-seaexplorer/realtime_rawnc/') + '/' -deploymentyaml = str(example_dir / 'example-seaexplorer/deploymentRealtime.yml') -l0tsdir = str(example_dir / 'example-seaexplorer/L0-timeseries-test/') + '/' +rawdir = str(EXAMPLE_DIR / 'example-seaexplorer/realtime_raw/') + '/' +rawncdir = str(EXAMPLE_DIR / 'example-seaexplorer/realtime_rawnc/') + '/' +deploymentyaml = str(EXAMPLE_DIR / 'example-seaexplorer/deploymentRealtime.yml') +l0tsdir = str(EXAMPLE_DIR / 'example-seaexplorer/L0-timeseries-test/') + '/' seaexplorer.raw_to_rawnc(rawdir, rawncdir, deploymentyaml) seaexplorer.merge_parquet(rawncdir, rawncdir, deploymentyaml, kind='sub') outname = seaexplorer.raw_to_L0timeseries(rawncdir, l0tsdir, deploymentyaml, kind='sub') output = xr.open_dataset(outname) # Open test data file test_data = xr.open_dataset( - library_dir + LIBRARY_DIR / 'tests/expected/example-seaexplorer/L0-timeseries/dfo-eva035-20190718.nc' ) variables = list(output.variables) @@ -61,12 +57,12 @@ def test_example_seaexplorer_metadata(): # Test that interpolation over nans does not change the output with nrt data with open(deploymentyaml) as fin: deployment = yaml.safe_load(fin) -interp_yaml = str(example_dir / 'example-seaexplorer/deploymentRealtimeInterp.yml') +interp_yaml = str(EXAMPLE_DIR / 'example-seaexplorer/deploymentRealtimeInterp.yml') deployment['netcdf_variables']['interpolate'] = True with open(interp_yaml, 'w') as fout: yaml.dump(deployment, fout) l0tsdir_interp = ( - str(example_dir / 'example-seaexplorer/L0-timeseries-test-interp/') + '/' + str(EXAMPLE_DIR / 'example-seaexplorer/L0-timeseries-test-interp/') + '/' ) outname_interp = seaexplorer.raw_to_L0timeseries( @@ -91,10 +87,10 @@ def test_example_seaexplorer_interp_nrt(var): # Test raw (full resolution) seaexplorer data. -rawdir = str(example_dir / 'example-seaexplorer-raw/delayed_raw/') + '/' -rawncdir = str(example_dir / 'example-seaexplorer-raw/delayed_rawnc/') + '/' -deploymentyaml_raw = str(example_dir / 'example-seaexplorer-raw/deployment.yml') -l0tsdir = str(example_dir / 'example-seaexplorer-raw/L0-timeseries-test/') + '/' +rawdir = str(EXAMPLE_DIR / 'example-seaexplorer-raw/delayed_raw/') + '/' +rawncdir = str(EXAMPLE_DIR / 'example-seaexplorer-raw/delayed_rawnc/') + '/' +deploymentyaml_raw = str(EXAMPLE_DIR / 'example-seaexplorer-raw/deployment.yml') +l0tsdir = str(EXAMPLE_DIR / 'example-seaexplorer-raw/L0-timeseries-test/') + '/' seaexplorer.raw_to_rawnc(rawdir, rawncdir, deploymentyaml_raw) seaexplorer.merge_parquet(rawncdir, rawncdir, deploymentyaml_raw, kind='raw') outname_raw = seaexplorer.raw_to_L0timeseries( @@ -103,7 +99,7 @@ def test_example_seaexplorer_interp_nrt(var): output_raw = xr.open_dataset(outname_raw) # Open test data file test_data_raw = xr.open_dataset( - library_dir + LIBRARY_DIR / 'tests/expected/example-seaexplorer-raw/L0-timeseries/dfo-bb046-20200908.nc' ) @@ -138,12 +134,12 @@ def test_example_seaexplorer_metadata_raw(): # Test that interpolation over nans in raw data results in a greater or equal number of non-nan values with open(deploymentyaml_raw) as fin: deployment_raw = yaml.safe_load(fin) -interp_yaml = str(example_dir / 'example-seaexplorer-raw/deploymentDelayedInterp.yml') +interp_yaml = str(EXAMPLE_DIR / 'example-seaexplorer-raw/deploymentDelayedInterp.yml') deployment_raw['netcdf_variables']['interpolate'] = True with open(interp_yaml, 'w') as fout: yaml.dump(deployment_raw, fout) l0tsdir_interp_raw = ( - str(example_dir / 'example-seaexplorer-raw/L0-timeseries-test-interp/') + '/' + str(EXAMPLE_DIR / 'example-seaexplorer-raw/L0-timeseries-test-interp/') + '/' ) outname_interp_raw = seaexplorer.raw_to_L0timeseries( diff --git a/tests/test_seaexplorer.py b/tests/test_seaexplorer.py index c4b09f5..64c5a5d 100644 --- a/tests/test_seaexplorer.py +++ b/tests/test_seaexplorer.py @@ -1,5 +1,4 @@ import os -from pathlib import Path import numpy as np import polars as pl @@ -7,10 +6,9 @@ import yaml os.system('rm tests/data/realtime_rawnc/*') -library_dir = Path(__file__).parent.parent.absolute() -example_dir = library_dir / 'tests/example-data/' import pyglider.seaexplorer as seaexplorer +from tests.utils import EXAMPLE_DIR def test__outputname(): @@ -67,13 +65,13 @@ def test_merge_rawnc(): result_default = seaexplorer.merge_parquet( 'tests/data/realtime_rawnc/', 'tests/data/realtime_rawnc/', - str(example_dir / 'example-seaexplorer/deploymentRealtime.yml'), + str(EXAMPLE_DIR / 'example-seaexplorer/deploymentRealtime.yml'), ) result_sub = seaexplorer.merge_parquet( 'tests/data/realtime_rawnc/', 'tests/data/realtime_rawnc/', - str(example_dir / 'example-seaexplorer/deploymentRealtime.yml'), + str(EXAMPLE_DIR / 'example-seaexplorer/deploymentRealtime.yml'), kind='sub', ) assert result_default is False @@ -107,12 +105,12 @@ def test_raw_to_timeseries(): result_default = seaexplorer.raw_to_timeseries( 'tests/data/realtime_rawnc/', 'tests/data/l0-profiles/', - str(example_dir / 'example-seaexplorer/deploymentRealtime.yml'), + str(EXAMPLE_DIR / 'example-seaexplorer/deploymentRealtime.yml'), ) result_sub = seaexplorer.raw_to_timeseries( 'tests/data/realtime_rawnc/', 'tests/data/l0-profiles/', - str(example_dir / 'example-seaexplorer/deploymentRealtime.yml'), + str(EXAMPLE_DIR / 'example-seaexplorer/deploymentRealtime.yml'), kind='sub', ) assert 'No such file or directory' in str(missing_file_exc) @@ -121,26 +119,26 @@ def test_raw_to_timeseries(): def test_missing_bad_timebase(): # Prepare yaml files with bad timebase and no timebase - with open(example_dir / 'example-seaexplorer/deploymentRealtime.yml') as fin: + with open(EXAMPLE_DIR / 'example-seaexplorer/deploymentRealtime.yml') as fin: deployment = yaml.safe_load(fin) deployment['netcdf_variables']['timebase']['source'] = 'non existing sensor' - with open(example_dir / 'example-seaexplorer/bad_timebase.yml', 'w') as fin: + with open(EXAMPLE_DIR / 'example-seaexplorer/bad_timebase.yml', 'w') as fin: yaml.dump(deployment, fin) deployment['netcdf_variables'].pop('timebase') - with open(example_dir / 'example-seaexplorer/no_timebase.yml', 'w') as fin: + with open(EXAMPLE_DIR / 'example-seaexplorer/no_timebase.yml', 'w') as fin: yaml.dump(deployment, fin) with pytest.raises(ValueError) as bad_timebase_exc: result_bad_timebase = seaexplorer.raw_to_timeseries( 'tests/data/realtime_rawnc/', 'tests/data/l0-profiles/', - str(example_dir / 'example-seaexplorer/bad_timebase.yml'), + str(EXAMPLE_DIR / 'example-seaexplorer/bad_timebase.yml'), kind='sub', ) with pytest.raises(ValueError) as no_timebase_exc: result_no_timebase = seaexplorer.raw_to_timeseries( 'tests/data/realtime_rawnc/', 'tests/data/l0-profiles/', - str(example_dir / 'example-seaexplorer/no_timebase.yml'), + str(EXAMPLE_DIR / 'example-seaexplorer/no_timebase.yml'), kind='sub', ) assert 'sensor not found in pld1 columns' in str(bad_timebase_exc) diff --git a/tests/test_slocum.py b/tests/test_slocum.py index 565667a..c07b031 100644 --- a/tests/test_slocum.py +++ b/tests/test_slocum.py @@ -1,5 +1,4 @@ import json -from pathlib import Path import numpy as np import pytest @@ -8,21 +7,19 @@ import pyglider.ncprocess as ncprocess import pyglider.slocum as slocum - -library_dir = Path(__file__).parent.parent.absolute() -example_dir = library_dir / 'tests/example-data/' +from tests.utils import EXAMPLE_DIR, LIBRARY_DIR # Create an L0 timeseries from slocum data and test that the resulting netcdf is # identical to the test data -cacdir = example_dir / 'example-slocum/cac/' -sensorlist = str(example_dir / 'example-slocum/dfo-rosie713_sensors.txt') -binarydir = str(example_dir / 'example-slocum/realtime_raw/') + '/' -rawdir_slocum = str(example_dir / 'example-slocum/realtime_rawnc/') + '/' -deploymentyaml_slocum = str(example_dir / 'example-slocum/deploymentRealtime.yml') -tsdir = str(example_dir / 'example-slocum/L0-timeseries/') + '/' +cacdir = EXAMPLE_DIR / 'example-slocum/cac/' +sensorlist = str(EXAMPLE_DIR / 'example-slocum/dfo-rosie713_sensors.txt') +binarydir = str(EXAMPLE_DIR / 'example-slocum/realtime_raw/') + '/' +rawdir_slocum = str(EXAMPLE_DIR / 'example-slocum/realtime_rawnc/') + '/' +deploymentyaml_slocum = str(EXAMPLE_DIR / 'example-slocum/deploymentRealtime.yml') +tsdir = str(EXAMPLE_DIR / 'example-slocum/L0-timeseries/') + '/' scisuffix = 'tbd' glidersuffix = 'sbd' -profiledir = str(example_dir / 'example-slocum/L0-profiles/') +profiledir = str(EXAMPLE_DIR / 'example-slocum/L0-profiles/') do_direct = True # This needs to get run every time the tests are run, so do at top level: @@ -45,7 +42,7 @@ output_slocum = xr.open_dataset(outname_slocum) # Open test data file test_data_slocum = xr.open_dataset( - library_dir / 'tests/expected/example-slocum/L0-timeseries/dfo-rosie713-20190615.nc' + LIBRARY_DIR / 'tests/expected/example-slocum/L0-timeseries/dfo-rosie713-20190615.nc' ) variables_slocum = list(output_slocum.variables) @@ -95,7 +92,7 @@ def test_profiles_compliant(): checker_names = ['gliderdac', 'cf:1.8'] verbose = 0 criteria = 'normal' - output_filename = example_dir / 'report.json' + output_filename = EXAMPLE_DIR / 'report.json' output_format = 'json' """ Inputs to ComplianceChecker.run_checker @@ -139,7 +136,7 @@ def test_timeseries_compliant(): checker_names = ['cf:1.8'] verbose = 0 criteria = 'normal' - output_filename = example_dir / 'report.json' + output_filename = EXAMPLE_DIR / 'report.json' output_format = 'json' """ Inputs to ComplianceChecker.run_checker diff --git a/tests/test_utils.py b/tests/test_utils.py index 0d3e935..ed93de4 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -1,21 +1,17 @@ -from pathlib import Path - import numpy as np import pytest import xarray as xr import yaml import pyglider.utils as utils - -library_dir = Path(__file__).parent.parent.absolute() -example_dir = library_dir / 'tests/example-data/' +from tests.utils import EXAMPLE_DIR, LIBRARY_DIR test_data = xr.open_dataset( - library_dir + LIBRARY_DIR / 'tests/expected/example-seaexplorer/L0-timeseries/dfo-eva035-20190718.nc' ) deploymentyaml = ( - example_dir / 'example-seaexplorer-legato-flntu-arod-ad2cp/deploymentRealtime.yml' + EXAMPLE_DIR / 'example-seaexplorer-legato-flntu-arod-ad2cp/deploymentRealtime.yml' ) with open(deploymentyaml) as fin: deployment = yaml.safe_load(fin) diff --git a/tests/utils.py b/tests/utils.py new file mode 100644 index 0000000..aac3421 --- /dev/null +++ b/tests/utils.py @@ -0,0 +1,6 @@ +"""Utilities specific to the test suite.""" + +from pathlib import Path + +LIBRARY_DIR = Path(__file__).parent.parent.absolute() +EXAMPLE_DIR = LIBRARY_DIR / 'tests/example-data/'