Skip to content
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

Clean up config and address warnings #1353

Merged
merged 4 commits into from
Nov 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 7 additions & 13 deletions jupyter_server/_tz.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
# Distributed under the terms of the Modified BSD License.
from __future__ import annotations

from datetime import datetime, timedelta, tzinfo
from typing import Callable
from datetime import datetime, timedelta, timezone, tzinfo

# constant for zero offset
ZERO = timedelta(0)
Expand All @@ -26,21 +25,16 @@ def dst(self, d: datetime | None) -> timedelta:
return ZERO


UTC = tzUTC() # type:ignore[abstract]

def utcnow() -> datetime:
"""Return timezone-aware UTC timestamp"""
return datetime.now(timezone.utc)

def utc_aware(unaware: Callable[..., datetime]) -> Callable[..., datetime]:
"""decorator for adding UTC tzinfo to datetime's utcfoo methods"""

def utc_method(*args, **kwargs):
dt = unaware(*args, **kwargs)
return dt.replace(tzinfo=UTC)
def utcfromtimestamp(timestamp):
return datetime.fromtimestamp(timestamp, timezone.utc)

return utc_method


utcfromtimestamp = utc_aware(datetime.utcfromtimestamp)
utcnow = utc_aware(datetime.utcnow)
UTC = tzUTC() # type:ignore[abstract]


def isoformat(dt: datetime) -> str:
Expand Down
18 changes: 4 additions & 14 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@ classifiers = [
"Programming Language :: Python",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3 :: Only",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
]
requires-python = ">=3.8"
dependencies = [
Expand Down Expand Up @@ -249,7 +245,7 @@ minversion = "6.0"
xfail_strict = true
log_cli_level = "info"
addopts = [
"-raXs", "--durations=10", "--color=yes", "--doctest-modules",
"-ra", "--durations=10", "--color=yes", "--doctest-modules",
"--showlocals", "--strict-markers", "--strict-config"
]
testpaths = [
Expand All @@ -265,14 +261,8 @@ filterwarnings = [
"always:unclosed <socket.socket:ResourceWarning",
"module:Jupyter is migrating its paths to use standard platformdirs:DeprecationWarning",
"ignore:jupyter_server.base.zmqhandlers module is deprecated in Jupyter Server 2.0:DeprecationWarning",
"ignore:datetime.datetime.utcfromtimestamp:DeprecationWarning",
"ignore:datetime.datetime.utcnow:DeprecationWarning",
# from nbformat
"ignore:Importing ErrorTree directly from the jsonschema package:DeprecationWarning",
# From jupyter_events
"module:jsonschema.RefResolver is deprecated as of:DeprecationWarning",
# ignore pytest warnings.
"ignore:::_pytest",
"ignore:datetime.datetime.utc:DeprecationWarning:dateutil",
"ignore:datetime.datetime.utc:DeprecationWarning:tornado",
]

[tool.coverage.report]
Expand Down Expand Up @@ -325,4 +315,4 @@ exclude = ["docs", "test"]
ignore = ["W002"]

[tool.repo-review]
ignore = ["PY007", "PP308", "GH102", "MY101"]
ignore = ["PY007", "GH102"]
2 changes: 1 addition & 1 deletion tests/test_gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def generate_kernelspec(name):

def generate_model(name):
"""Generate a mocked kernel model. Caller is responsible for adding model to running_kernels dictionary."""
dt = datetime.utcnow().isoformat() + "Z" # noqa
dt = datetime.now(timezone.utc).isoformat().replace("+00:00", "Z")
kernel_id = str(uuid.uuid4())
model = {
"id": kernel_id,
Expand Down
Loading