Skip to content

Commit

Permalink
Addresses utcnow deprecation.
Browse files Browse the repository at this point in the history
Improves mypy tox environment.
  • Loading branch information
Daverball committed Sep 3, 2024
1 parent d110358 commit 1006856
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
7 changes: 6 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,12 @@ deps =
-e{toxinidir}
mypy
mitogen
commands = mypy -p suitable
commands =
mypy -p suitable --python-version 3.8
mypy -p suitable --python-version 3.9
mypy -p suitable --python-version 3.10
mypy -p suitable --python-version 3.11
mypy -p suitable --python-version 3.12
[testenv:report]
deps =
Expand Down
13 changes: 11 additions & 2 deletions src/suitable/module_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,15 @@
from suitable.api import Api


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

def utcnow() -> datetime:
return datetime.now(UTC)
else:
utcnow = datetime.utcnow


@contextmanager
def ansible_verbosity(verbosity: int) -> Generator[None, None, None]:
""" Temporarily changes the ansible verbosity. Relies on a single display
Expand Down Expand Up @@ -215,7 +224,7 @@ def execute(self, *args: Any, **kwargs: Any) -> RunnerResults:
}

try:
start = datetime.utcnow()
start = utcnow()
task_queue_manager = None
callback = SilentCallbackModule()

Expand Down Expand Up @@ -297,7 +306,7 @@ def execute(self, *args: Any, **kwargs: Any) -> RunnerResults:
GlobalCLIArgs)
GlobalCLIArgs._Singleton__instance = None

log.debug(f'took {datetime.utcnow() - start} to complete')
log.debug(f'took {utcnow() - start} to complete')

return self.evaluate_results(callback)

Expand Down

0 comments on commit 1006856

Please sign in to comment.