From 096c93032335d43fd45433297e804f8582c803a5 Mon Sep 17 00:00:00 2001 From: Jonathan Healy Date: Thu, 9 May 2024 23:17:07 +0800 Subject: [PATCH] Remove pystac (#690) * remove pystac * update, fix changelog * fix link * Update stac_fastapi/types/stac_fastapi/types/rfc3339.py Co-authored-by: Pete Gadomski --------- Co-authored-by: Pete Gadomski --- CHANGES.md | 12 +++++--- stac_fastapi/api/setup.py | 1 - stac_fastapi/types/setup.py | 1 - .../types/stac_fastapi/types/rfc3339.py | 29 ++++++++++++++++++- 4 files changed, 36 insertions(+), 7 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index f60e95f9..940b7b84 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,11 +1,15 @@ # Changelog -[Unreleased] - TBD +## [Unreleased] - TBD -## Changed +### Changed + +* switch from `fastapi` to `fastapi-slim` to avoid installing unwanted dependencies. ([#687](https://github.com/stac-utils/stac-fastapi/pull/687)) +* replace Enum with `Literal` for `FilterLang`. ([#686](https://github.com/stac-utils/stac-fastapi/pull/686)) + +### Removed -* switch from `fastapi` to `fastapi-slim` to avoid installing unwanted dependencies -* replace Enum with `Literal` for `FilterLang` +* Pystac as it was just used for a datetime to string function. ([#690](https://github.com/stac-utils/stac-fastapi/pull/690)) ## [3.0.0a0] - 2024-05-06 diff --git a/stac_fastapi/api/setup.py b/stac_fastapi/api/setup.py index af596adf..5050d3a7 100644 --- a/stac_fastapi/api/setup.py +++ b/stac_fastapi/api/setup.py @@ -18,7 +18,6 @@ "pytest-asyncio", "pre-commit", "requests", - "pystac[validation]==1.*", ], "benchmark": [ "pytest-benchmark", diff --git a/stac_fastapi/types/setup.py b/stac_fastapi/types/setup.py index 55f3ea10..0dd166ec 100644 --- a/stac_fastapi/types/setup.py +++ b/stac_fastapi/types/setup.py @@ -10,7 +10,6 @@ "attrs>=23.2.0", "pydantic-settings>=2", "stac_pydantic>=3", - "pystac==1.*", "iso8601>=1.0.2,<2.2.0", ] diff --git a/stac_fastapi/types/stac_fastapi/types/rfc3339.py b/stac_fastapi/types/stac_fastapi/types/rfc3339.py index 2f0a1f34..a551b45d 100644 --- a/stac_fastapi/types/stac_fastapi/types/rfc3339.py +++ b/stac_fastapi/types/stac_fastapi/types/rfc3339.py @@ -6,7 +6,6 @@ import iso8601 from fastapi import HTTPException -from pystac.utils import datetime_to_str RFC33339_PATTERN = ( r"^(\d\d\d\d)\-(\d\d)\-(\d\d)(T|t)(\d\d):(\d\d):(\d\d)([.]\d+)?" @@ -21,6 +20,34 @@ ] +# Borrowed from pystac - https://github.com/stac-utils/pystac/blob/f5e4cf4a29b62e9ef675d4a4dac7977b09f53c8f/pystac/utils.py#L370-L394 +def datetime_to_str(dt: datetime, timespec: str = "auto") -> str: + """Converts a :class:`datetime.datetime` instance to an ISO8601 string in the + `RFC 3339, section 5.6 + `__ format required by + the :stac-spec:`STAC Spec `. + + Args: + dt : The datetime to convert. + timespec: An optional argument that specifies the number of additional + terms of the time to include. Valid options are 'auto', 'hours', + 'minutes', 'seconds', 'milliseconds' and 'microseconds'. The default value + is 'auto'. + + Returns: + str: The ISO8601 (RFC 3339) formatted string representing the datetime. + """ + if dt.tzinfo is None: + dt = dt.replace(tzinfo=timezone.utc) + + timestamp = dt.isoformat(timespec=timespec) + zulu = "+00:00" + if timestamp.endswith(zulu): + timestamp = f"{timestamp[: -len(zulu)]}Z" + + return timestamp + + def rfc3339_str_to_datetime(s: str) -> datetime: """Convert a string conforming to RFC 3339 to a :class:`datetime.datetime`.