Skip to content

Commit

Permalink
fix: replace datetime.datetime.utcnow which is deprecated (deepmode…
Browse files Browse the repository at this point in the history
…ling#4067)

Fix deepmodeling#4063.

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit


- **Improvements**
- Enhanced the accuracy and clarity of time representation in the model
saving feature.
- Updated copyright year retrieval to ensure timezone awareness for
improved precision.
- Expanded linting capabilities by adding datetime-related checks, which
can improve code quality.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Signed-off-by: Jinzhe Zeng <jinzhe.zeng@rutgers.edu>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
2 people authored and Mathieu Taillefumier committed Sep 18, 2024
1 parent 2dda536 commit 3238359
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
6 changes: 2 additions & 4 deletions deepmd/dpmodel/utils/serialization.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# SPDX-License-Identifier: LGPL-3.0-or-later
import datetime
import json
from datetime import (
datetime,
)
from pathlib import (
Path,
)
Expand Down Expand Up @@ -90,7 +88,7 @@ def save_dp_model(filename: str, model_dict: dict) -> None:
"software": "deepmd-kit",
"version": __version__,
# use UTC+0 time
"time": str(datetime.utcnow()),
"time": str(datetime.datetime.now(tz=datetime.timezone.utc)),
}
if filename_extension == ".dp":
variable_counter = Counter()
Expand Down
9 changes: 5 additions & 4 deletions doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,14 @@

# -- Path setup --------------------------------------------------------------

import datetime

# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
#
import os
import sys
from datetime import (
date,
)

from deepmd.utils.argcheck import (
ACTIVATION_FN_DICT,
Expand All @@ -29,7 +28,9 @@
# -- Project information -----------------------------------------------------

project = "DeePMD-kit"
copyright = "2017-%d, DeepModeling" % date.today().year
copyright = (
"2017-%d, DeepModeling" % datetime.datetime.now(tz=datetime.timezone.utc).year
)
author = "DeepModeling"

autoapi_dirs = ["../deepmd"]
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,7 @@ select = [
"B904", # raise-without-from-inside-except
"N804", # invalid-first-argument-name-for-class-method
"N805", # invalid-first-argument-name-for-method
"DTZ", # datetime
]

ignore = [
Expand Down

0 comments on commit 3238359

Please sign in to comment.