-
Notifications
You must be signed in to change notification settings - Fork 25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix datetime.utcnow() deprecation #134
Fix datetime.utcnow() deprecation #134
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #134 +/- ##
=======================================
Coverage 59.15% 59.15%
=======================================
Files 24 24
Lines 1611 1611
=======================================
Hits 953 953
Misses 658 658 ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for making this update! I made a suggestion that should work with python 3.9 to fix the CI.
src/stpipe/config.py
Outdated
@@ -111,7 +111,10 @@ def to_asdf(self, include_metadata=False): | |||
meta = deepcopy(_META_TEMPLATE) | |||
meta["date"] = meta["date"].replace( | |||
_TEMPLATE_PLACEHOLDER, | |||
datetime.utcnow().replace(microsecond=0).isoformat(), | |||
datetime.now(UTC) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
datetime.now(UTC) | |
datetime.now(timezone.utc) |
I believe this and the other suggestion should allow the CI to work with 3.9 and matches the changes made in jwst.
Although not necessary with this PR, would you add a python 3.12 environment to tox and the CI? This would be great to verify that the DeprecationWarning
is fixed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. Done.
This actually doesn't get picked up in the stpipe
unit tests, but does in the jwst
unit tests, which test config_parser.py
better than stpipe
does. One might want to think about adding coverage to the downstream tests, specifically jwst
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! I totally missed that the lines weren't covered by the unit tests. It might be worth moving some of those over (if that's possible) but that's a problem for another day.
LGTM.
Agree that it would be nice if this package could self-test better. Another day. I will note that by putting coverage on the downstream test workflows and adding codecov flags, you can keep track separately of which coverage is coming from the package unit tests and how well the downstream packages test it. But currently the OpenAstronomy CI workflows don't support specifying codecov flags, though it would be easy enough to add probably. Flags are used in the |
This fixes the following deprecation warning:
Note that when you pass any timezone to
datetime.now()
, it returns the offset from UTC (format +HH:MM) appended to the string. The offset from UTC is always zero, anddatetime.utcnow()
didn't include it. So here it is removed so that timestamps have a consistent format.