Skip to content

Commit 096c930

Browse files
jonhealy1gadomski
andauthored
Remove pystac (#690)
* remove pystac * update, fix changelog * fix link * Update stac_fastapi/types/stac_fastapi/types/rfc3339.py Co-authored-by: Pete Gadomski <[email protected]> --------- Co-authored-by: Pete Gadomski <[email protected]>
1 parent add05de commit 096c930

File tree

4 files changed

+36
-7
lines changed

4 files changed

+36
-7
lines changed

CHANGES.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
# Changelog
22

3-
[Unreleased] - TBD
3+
## [Unreleased] - TBD
44

5-
## Changed
5+
### Changed
6+
7+
* switch from `fastapi` to `fastapi-slim` to avoid installing unwanted dependencies. ([#687](https://github.com/stac-utils/stac-fastapi/pull/687))
8+
* replace Enum with `Literal` for `FilterLang`. ([#686](https://github.com/stac-utils/stac-fastapi/pull/686))
9+
10+
### Removed
611

7-
* switch from `fastapi` to `fastapi-slim` to avoid installing unwanted dependencies
8-
* replace Enum with `Literal` for `FilterLang`
12+
* Pystac as it was just used for a datetime to string function. ([#690](https://github.com/stac-utils/stac-fastapi/pull/690))
913

1014
## [3.0.0a0] - 2024-05-06
1115

stac_fastapi/api/setup.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
"pytest-asyncio",
1919
"pre-commit",
2020
"requests",
21-
"pystac[validation]==1.*",
2221
],
2322
"benchmark": [
2423
"pytest-benchmark",

stac_fastapi/types/setup.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
"attrs>=23.2.0",
1111
"pydantic-settings>=2",
1212
"stac_pydantic>=3",
13-
"pystac==1.*",
1413
"iso8601>=1.0.2,<2.2.0",
1514
]
1615

stac_fastapi/types/stac_fastapi/types/rfc3339.py

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
import iso8601
88
from fastapi import HTTPException
9-
from pystac.utils import datetime_to_str
109

1110
RFC33339_PATTERN = (
1211
r"^(\d\d\d\d)\-(\d\d)\-(\d\d)(T|t)(\d\d):(\d\d):(\d\d)([.]\d+)?"
@@ -21,6 +20,34 @@
2120
]
2221

2322

23+
# Borrowed from pystac - https://github.com/stac-utils/pystac/blob/f5e4cf4a29b62e9ef675d4a4dac7977b09f53c8f/pystac/utils.py#L370-L394
24+
def datetime_to_str(dt: datetime, timespec: str = "auto") -> str:
25+
"""Converts a :class:`datetime.datetime` instance to an ISO8601 string in the
26+
`RFC 3339, section 5.6
27+
<https://datatracker.ietf.org/doc/html/rfc3339#section-5.6>`__ format required by
28+
the :stac-spec:`STAC Spec <master/item-spec/common-metadata.md#date-and-time>`.
29+
30+
Args:
31+
dt : The datetime to convert.
32+
timespec: An optional argument that specifies the number of additional
33+
terms of the time to include. Valid options are 'auto', 'hours',
34+
'minutes', 'seconds', 'milliseconds' and 'microseconds'. The default value
35+
is 'auto'.
36+
37+
Returns:
38+
str: The ISO8601 (RFC 3339) formatted string representing the datetime.
39+
"""
40+
if dt.tzinfo is None:
41+
dt = dt.replace(tzinfo=timezone.utc)
42+
43+
timestamp = dt.isoformat(timespec=timespec)
44+
zulu = "+00:00"
45+
if timestamp.endswith(zulu):
46+
timestamp = f"{timestamp[: -len(zulu)]}Z"
47+
48+
return timestamp
49+
50+
2451
def rfc3339_str_to_datetime(s: str) -> datetime:
2552
"""Convert a string conforming to RFC 3339 to a :class:`datetime.datetime`.
2653

0 commit comments

Comments
 (0)