From a7789465f1f51017e3d6867a86e4d93986aaab52 Mon Sep 17 00:00:00 2001 From: vincentsarago Date: Thu, 16 Mar 2023 21:36:06 +0100 Subject: [PATCH] replace ciso8601 by iso8601 --- pyproject.toml | 2 +- setup.py | 39 --------------------------------- tipg/dbmodel.py | 2 +- tipg/factory.py | 2 +- tipg/utils.py | 57 +++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 60 insertions(+), 42 deletions(-) delete mode 100644 setup.py create mode 100644 tipg/utils.py diff --git a/pyproject.toml b/pyproject.toml index af66b153..83a89a71 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -29,7 +29,7 @@ dependencies = [ "morecantile>=3.1,<4.0", "geojson-pydantic>=0.4.3", "pygeofilter>=0.2.0,<0.3.0", - "ciso8601~=2.2.0", + "iso8601~=1.0.2", "starlette-cramjam>=0.3,<0.4", "importlib_resources>=1.1.0; python_version < '3.9'", "typing_extensions; python_version < '3.9.2'", diff --git a/setup.py b/setup.py deleted file mode 100644 index fa85db68..00000000 --- a/setup.py +++ /dev/null @@ -1,39 +0,0 @@ -"""Fake tipg setup.py for github.""" -import sys - -from setuptools import setup - -sys.stderr.write( - """ -=============================== -Unsupported installation method -=============================== -tifeatures no longer supports installation with `python setup.py install`. -Please use `python -m pip install .` instead. -""" -) -sys.exit(1) - - -# The below code will never execute, however GitHub is particularly -# picky about where it finds Python packaging metadata. -# See: https://github.com/github/feedback/discussions/6456 -# -# To be removed once GitHub catches up. - -setup( - name="tipg", - install_requires=[ - "orjson", - "asyncpg>=0.23.0", - "buildpg>=0.3", - "fastapi>=0.87", - "jinja2>=2.11.2,<4.0.0", - "geojson-pydantic>=0.4.3", - "pygeofilter>=0.2.0,<0.3.0", - "ciso8601~=2.2.0", - "starlette-cramjam>=0.3,<0.4", - "importlib_resources>=1.1.0; python_version < '3.9'", - "typing_extensions; python_version < '3.9.2'", - ], -) diff --git a/tipg/dbmodel.py b/tipg/dbmodel.py index 274d1cf4..40021c16 100644 --- a/tipg/dbmodel.py +++ b/tipg/dbmodel.py @@ -7,7 +7,6 @@ from buildpg import asyncpg, clauses from buildpg import funcs as pg_funcs from buildpg import logic, render -from ciso8601 import parse_rfc3339 from morecantile import Tile, TileMatrixSet from pydantic import BaseModel, Field, root_validator from pygeofilter.ast import AstType @@ -24,6 +23,7 @@ from tipg.filter.filters import bbox_to_wkt from tipg.model import Extent from tipg.settings import TableSettings, TileSettings +from tipg.utils import parse_rfc3339 tile_settings = TileSettings() diff --git a/tipg/factory.py b/tipg/factory.py index d6ea56ec..c8ae3a05 100644 --- a/tipg/factory.py +++ b/tipg/factory.py @@ -18,7 +18,6 @@ import jinja2 import orjson -from ciso8601 import parse_rfc3339 from morecantile import TileMatrixSet from morecantile import tms as default_tms from morecantile.defaults import TileMatrixSets @@ -45,6 +44,7 @@ from tipg.resources.enums import MediaType from tipg.resources.response import GeoJSONResponse, SchemaJSONResponse from tipg.settings import TileSettings +from tipg.utils import parse_rfc3339 from fastapi import APIRouter, Depends, Path, Query from fastapi.responses import ORJSONResponse diff --git a/tipg/utils.py b/tipg/utils.py new file mode 100644 index 00000000..b67b0d91 --- /dev/null +++ b/tipg/utils.py @@ -0,0 +1,57 @@ +"""tipg.utils.""" + +import re +from datetime import datetime + +from iso8601 import parse_date + +RFC33339_PATTERN = r"^(\d\d\d\d)\-(\d\d)\-(\d\d)(T|t)(\d\d):(\d\d):(\d\d)([.]\d+)?(Z|([-+])(\d\d):(\d\d))$" + + +def parse_rfc3339(s: str) -> datetime: + """Convert a string conforming to RFC 3339 to a :class:`datetime.datetime`. + + Uses :meth:`iso8601.parse_date` under the hood. + + Args: + s (str) : The string to convert to :class:`datetime.datetime`. + Returns: + str: The datetime represented by the ISO8601 (RFC 3339) formatted string. + Raises: + ValueError: If the string is not a valid RFC 3339 string. + + code from https://github.com/stac-utils/stac-fastapi/blob/3edb62ec91a1eacfbfae8a12646b0422943c34ec/stac_fastapi/types/stac_fastapi/types/rfc3339.py#L9-L35 + + MIT License + + Copyright (c) 2020 Arturo AI + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + 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. + + """ + # Uppercase the string + s = s.upper() + + # Match against RFC3339 regex. + result = re.match(RFC33339_PATTERN, s) + if not result: + raise ValueError("Invalid RFC3339 datetime.") + + # Parse with pyiso8601 + return parse_date(s)