Skip to content

Commit

Permalink
Merge pull request #3670 from yarikoptic/bf-3.12
Browse files Browse the repository at this point in the history
Use regular ".now" instead of ".utcnow" with UTC zone
  • Loading branch information
effigies authored Oct 6, 2024
2 parents 32a711e + cd4bd5b commit 0375126
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
5 changes: 3 additions & 2 deletions nipype/interfaces/base/support.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import platform

from ... import logging, config
from ...utils.datetime import utcnow
from ...utils.misc import is_container, rgetcwd
from ...utils.filemanip import md5, hash_infile

Expand Down Expand Up @@ -72,15 +73,15 @@ def __enter__(self):
if self._runtime.redirect_x:
self._runtime.environ["DISPLAY"] = config.get_display()

self._runtime.startTime = dt.isoformat(dt.utcnow())
self._runtime.startTime = dt.isoformat(utcnow())
self._resmon.start()
# TODO: Perhaps clean-up path and ensure it exists?
os.chdir(self._runtime.cwd)
return self._runtime

def __exit__(self, exc_type, exc_value, exc_tb):
"""Tear-down interface execution."""
self._runtime.endTime = dt.isoformat(dt.utcnow())
self._runtime.endTime = dt.isoformat(utcnow())
timediff = parseutc(self._runtime.endTime) - parseutc(self._runtime.startTime)
self._runtime.duration = (
timediff.days * 86400 + timediff.seconds + timediff.microseconds / 1e6
Expand Down
4 changes: 2 additions & 2 deletions nipype/pipeline/engine/workflows.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
import os
import os.path as op
import sys
from datetime import datetime
from copy import deepcopy
import pickle
import shutil

import numpy as np

from ... import config, logging
from ...utils.datetime import utcnow
from ...utils.misc import str2bool
from ...utils.functions import getsource, create_function_from_source

Expand Down Expand Up @@ -623,7 +623,7 @@ def run(self, plugin=None, plugin_args=None, updatehash=False):
if str2bool(self.config["execution"]["create_report"]):
self._write_report_info(self.base_dir, self.name, execgraph)
runner.run(execgraph, updatehash=updatehash, config=self.config)
datestr = datetime.utcnow().strftime("%Y%m%dT%H%M%S")
datestr = utcnow().strftime("%Y%m%dT%H%M%S")
if str2bool(self.config["execution"]["write_provenance"]):
prov_base = op.join(self.base_dir, "workflow_provenance_%s" % datestr)
logger.info("Provenance file prefix: %s" % prov_base)
Expand Down
19 changes: 19 additions & 0 deletions nipype/utils/datetime.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*-
# vi: set ft=python sts=4 ts=4 sw=4 et:
"""
Utilities for dates and time
"""

from datetime import datetime as dt
import sys

if sys.version_info >= (3, 11):
from datetime import UTC

def utcnow():
"""Adapter since 3.12 prior utcnow is deprecated,
but not EOLed 3.8 does not have datetime.UTC"""
return dt.now(UTC)

else:
utcnow = dt.utcnow

0 comments on commit 0375126

Please sign in to comment.