Skip to content

Commit

Permalink
bye pytz (#4890)
Browse files Browse the repository at this point in the history
* pytz is not needed in Python 3.9+, or with the zoneinfo backport

* make diff_mypy: quieter and target the correct branch

* Linting.

* Satisfy MyPy more (new MyPy?)

---------

Co-authored-by: Adam Novak <[email protected]>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: DailyDreaming <[email protected]>
  • Loading branch information
4 people authored May 1, 2024
1 parent 016f7a6 commit 144d1f1
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 14 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -325,8 +325,8 @@ diff_pydocstyle_report: pydocstyle_report.txt
diff-quality --compare-branch=master --violations=pycodestyle --fail-under=100 $^

diff_mypy:
mypy --cobertura-xml-report . src/toil || true
diff-cover --fail-under=100 cobertura.xml
mypy --cobertura-xml-report . src/toil > /dev/null || true
diff-cover --fail-under=100 --compare-branch origin/master cobertura.xml

pyupgrade: $(PYSOURCES)
pyupgrade --exit-zero-even-if-changed --py37-plus $^
Expand Down
9 changes: 7 additions & 2 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,15 @@ sphinx-autodoc-typehints>=1.24.0,<3
sphinxcontrib-autoprogram==0.1.9
cwltest>=2.2.20211116163652
mypy==1.10.0
types-aws-xray-sdk
types-boto<2.49.18.20240205
types-Flask-Cors
types-requests
types-psutil
types-python-dateutil
types-setuptools
types-boto<2.49.18.20240205
types-pytz
types-xmltodict
backports.zoneinfo[tzdata];python_version<"3.9"
flake8>=3.8.4,<8
flake8-bugbear>=20.11.1,<25
black
Expand Down
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ python-dateutil
psutil >= 3.0.1, <6
PyPubSub >=4.0.3, <5
addict>=2.2.1, <2.5
pytz>=2012
enlighten>=1.5.2, <2
configargparse>=1.7,<2
ruamel.yaml>=0.15
Expand Down
2 changes: 1 addition & 1 deletion src/toil/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
from typing import TYPE_CHECKING, Optional, Tuple

import requests
from pytz import timezone

from docker.errors import ImageNotFound
from toil.lib.memoize import memoize
Expand Down Expand Up @@ -475,5 +474,6 @@ def str_to_datetime(s):
datetime.datetime(1970, 1, 1, 0, 0)
"""
return datetime.strptime(s, datetime_format)

except ImportError:
pass
4 changes: 1 addition & 3 deletions src/toil/lib/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
from contextlib import closing
from typing import Iterator, List, Optional

import pytz

logger = logging.getLogger(__name__)


Expand Down Expand Up @@ -56,7 +54,7 @@ def get_user_name() -> str:

def utc_now() -> datetime.datetime:
"""Return a datetime in the UTC timezone corresponding to right now."""
return datetime.datetime.utcnow().replace(tzinfo=pytz.UTC)
return datetime.datetime.utcnow().replace(tzinfo=datetime.timezone.utc)

def unix_now_ms() -> float:
"""Return the current time in milliseconds since the Unix epoch."""
Expand Down
2 changes: 1 addition & 1 deletion src/toil/lib/threading.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
from contextlib import contextmanager
from typing import Dict, Iterator, Optional, Union, cast

import psutil # type: ignore
import psutil

from toil.lib.exceptions import raise_
from toil.lib.io import robust_rmtree
Expand Down
2 changes: 1 addition & 1 deletion src/toil/server/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def create_app(args: argparse.Namespace) -> "connexion.FlaskApp":

if args.cors:
# enable cross origin resource sharing
from flask_cors import CORS # type: ignore
from flask_cors import CORS
CORS(flask_app.app, resources={r"/ga4gh/*": {"origins": args.cors_origins}})

# add workflow execution service (WES) API endpoints
Expand Down
7 changes: 4 additions & 3 deletions src/toil/test/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,13 @@
from urllib.error import HTTPError, URLError
from urllib.request import urlopen

import pytz

if sys.version_info >= (3, 8):
from typing import Literal
import zoneinfo
else:
from typing_extensions import Literal
from backports import zoneinfo

from toil import ApplianceImageNotFound, applianceSelf, toilPackageDirPath
from toil.lib.accelerators import (have_working_nvidia_docker_runtime,
Expand Down Expand Up @@ -85,8 +86,8 @@ class ToilTest(unittest.TestCase):
_tempDirs: List[str] = []

def setup_method(self, method: Any) -> None:
western = pytz.timezone('America/Los_Angeles')
california_time = western.localize(datetime.datetime.now())
western = zoneinfo.ZoneInfo("America/Los_Angeles")
california_time = datetime.datetime.now(tz=western)
timestamp = california_time.strftime("%b %d %Y %H:%M:%S:%f %Z")
print(f"\n\n[TEST] {strclass(self.__class__)}:{self._testMethodName} ({timestamp})\n\n")

Expand Down

0 comments on commit 144d1f1

Please sign in to comment.