diff --git a/pyproject.toml b/pyproject.toml index feed8b2..9858d8b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,7 +1,51 @@ [build-system] -requires = ["setuptools>=42", "wheel", "setuptools_scm[toml]>=3.4"] +requires = ["setuptools>=61", "wheel", "setuptools_scm[toml]>=3.4"] build-backend = "setuptools.build_meta" +[project] +name = "xpublish_edr" +description = "" +readme = "README.md" +requires-python = ">=3.7" +keywords = [] +license = { file = "LICENSE.txt" } + +classifiers = [ + "Development Status :: 5 - Production/Stable", + "Intended Audience :: Science/Research", + "Operating System :: OS Independent", + "License :: OSI Approved :: BSD License", + "Programming Language :: Python", + "Programming Language :: Python :: 3", + "Programming Language :: Python :: 3.7", + "Programming Language :: Python :: 3.8", + "Programming Language :: Python :: 3.9", + "Programming Language :: Python :: 3.10", + "Topic :: Scientific/Engineering", +] + +dynamic = ["version", "dependencies"] + +[tool.setuptools] +packages = ["xpublish_edr"] + +[tool.setuptools.dynamic] +dependencies = { file = ["requirements.txt"] } + +[tool.setuptools_scm] +write_to = "xpublish_edr/_version.py" + +[project.entry-points."xpublish.plugin"] +cf_edr = "xpublish_edr.plugin:CfEdrPlugin" + +[project.entry-points.xpublish_edr_position_formats] +cf_covjson = "xpublish_edr.formats.to_covjson:to_cf_covjson" +csv = "xpublish_edr.formats.to_csv:to_csv" +nc = "xpublish_edr.formats.to_netcdf:to_netcdf" +netcdf = "xpublish_edr.formats.to_netcdf:to_netcdf" +nc4 = "xpublish_edr.formats.to_netcdf:to_netcdf" +netcdf4 = "xpublish_edr.formats.to_netcdf:to_netcdf" + [tool.interrogate] ignore-init-method = true ignore-init-module = false diff --git a/setup.cfg b/setup.cfg deleted file mode 100644 index 853ba8e..0000000 --- a/setup.cfg +++ /dev/null @@ -1,54 +0,0 @@ -[metadata] -name = xpublish_edr -description = My Awesome module -author = Alex Kerney -author_email = abk@mac.com -url = https://github.com/gulfofmaine/xpublish-edr -long_description = file: README.md -long_description_content_type = text/markdown -license = BSD-3-Clause -license_file = LICENSE.txt -classifiers = - Development Status :: 5 - Production/Stable - Intended Audience :: Science/Research - Operating System :: OS Independent - License :: OSI Approved :: BSD License - Programming Language :: Python - Programming Language :: Python :: 3 - Programming Language :: Python :: 3.7 - Programming Language :: Python :: 3.8 - Programming Language :: Python :: 3.9 - Programming Language :: Python :: 3.10 - Topic :: Scientific/Engineering - -[options] -zip_safe = False -install_requires = - shapely - xarray - xpublish -python_requires = >=3.7 -packages = - xpublish_edr - xpublish_edr.formats - -[sdist] -formats = gztar - -[check-manifest] -ignore = - *.yml - *.yaml - .coveragerc - docs - docs/* - *.enc - notebooks - notebooks/* - tests - tests/* - -[flake8] -max-line-length = 105 -ignore = E203, E501, W503 -exclude = xpublish_edr/_version.py diff --git a/setup.py b/setup.py deleted file mode 100644 index c366c32..0000000 --- a/setup.py +++ /dev/null @@ -1,22 +0,0 @@ -from setuptools import setup - -pkg_name = "xpublish_edr" - -setup( - use_scm_version={ - "write_to": f"{pkg_name}/_version.py", - "write_to_template": '__version__ = "{version}"', - "tag_regex": r"^(?Pv)?(?P[^\+]+)(?P.*)?$", - }, - entry_points={ - "xpublish_edr_position_formats": [ - "cf_covjson = xpublish_edr.formats.to_covjson:to_cf_covjson", - "csv = xpublish_edr.formats.to_csv:to_csv", - "nc = xpublish_edr.formats.to_netcdf:to_netcdf", - "netcdf = xpublish_edr.formats.to_netcdf:to_netcdf", - "nc4 = xpublish_edr.formats.to_netcdf:to_netcdf", - "netcdf4 = xpublish_edr.formats.to_netcdf:to_netcdf", - ], - "xpublish.plugin": ["cf_edr = xpublish_edr.plugin:CfEdrPlugin"], - }, -) diff --git a/xpublish_edr/plugin.py b/xpublish_edr/plugin.py index 1c4833b..fb2abd9 100644 --- a/xpublish_edr/plugin.py +++ b/xpublish_edr/plugin.py @@ -2,13 +2,12 @@ OGC EDR router for datasets with CF convention metadata """ import logging -from dataclasses import dataclass, field from typing import List, Optional import pkg_resources import xarray as xr -from fastapi import Depends, HTTPException, Request -from xpublish.plugins import XpublishPluginFactory +from fastapi import APIRouter, Depends, HTTPException, Request +from xpublish import Plugin, hookimpl from .formats.to_covjson import to_cf_covjson from .query import EDRQuery, edr_query, edr_query_params @@ -18,7 +17,8 @@ def position_formats(): """ - Return response format functions from registered `xpublish_edr_position_formats` entry_points + Return response format functions from registered + `xpublish_edr_position_formats` entry_points """ formats = {} @@ -28,17 +28,25 @@ def position_formats(): return formats -@dataclass -class CfEdrPlugin(XpublishPluginFactory): - """Provides access to data via a OGC EDR compatible API for datasets that are CF compliant""" +class CfEdrPlugin(Plugin): + """ + OGC EDR compatible endpoints for Xpublish datasets + """ + + name = "cf_edr" + + app_router_prefix: str = "/edr" + app_router_tags: List[str] = ["edr"] dataset_router_prefix: str = "/edr" - dataset_router_tags: List[str] = field(default_factory=lambda: ["edr"]) + dataset_router_tags: List[str] = ["edr"] - def register_routes(self): - """Register EDR dataset routes""" + @hookimpl + def app_router(self): + """Register an application level router for EDR format info""" + router = APIRouter(prefix=self.app_router_prefix, tags=self.app_router_tags) - @self.dataset_router.get( + @router.get( "/position/formats", summary="Position query response formats", ) @@ -50,11 +58,18 @@ def get_position_formats(): return formats - @self.dataset_router.get("/position", summary="Position query") + return router + + @hookimpl + def dataset_router(self): + """Register dataset level router for EDR endpoints""" + router = APIRouter(prefix=self.app_router_prefix, tags=self.dataset_router_tags) + + @router.get("/position", summary="Position query") def get_position( request: Request, query: EDRQuery = Depends(edr_query), - dataset: xr.Dataset = Depends(self.dataset_dependency), + dataset: xr.Dataset = Depends(self.dependencies.dataset), ): """ Returns position data based on WKT `Point(lon lat)` coordinates @@ -128,9 +143,12 @@ def get_position( except KeyError: raise HTTPException( 404, - f"{query.format} is not a valid format for EDR position queries. Get `./formats` for valid formats", + f"{query.format} is not a valid format for EDR position queries. " + "Get `./formats` for valid formats", ) return format_fn(ds) return to_cf_covjson(ds) + + return router