Skip to content

Commit

Permalink
Dependencies: drop the python-dateutil library
Browse files Browse the repository at this point in the history
This was only used in `aiida.common.timezone.isoformat_to_datetime` and
in the `aiida.restapi.common.utils` module to parse a datetime object
from a string in ISO format. Since Python 3.7 this functionality is
provided in the `datetime` standard library:

    https://docs.python.org/3/library/datetime.html#datetime.datetime.fromisoformat

The only relevant difference between the two implementations is that the
standard library is intentionally strict and will raise for invalid
formats whereas the `python-dateutil` will be lenient and try to guess
the intention in case of invalid formats. For both cases, we prefer not
to guess and potentially guess wrong, so the change is appropriate.
  • Loading branch information
sphuber committed Apr 21, 2022
1 parent f58d711 commit 8c50bd4
Show file tree
Hide file tree
Showing 7 changed files with 2 additions and 14 deletions.
6 changes: 1 addition & 5 deletions aiida/common/timezone.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
"""Utility functions to operate on datetime objects."""
from datetime import datetime

from dateutil import parser


def get_current_timezone():
"""Return the current timezone.
Expand Down Expand Up @@ -134,6 +132,4 @@ def isoformat_to_datetime(value):
:param value: a ISO format string representation of a datetime object
"""
if value is None:
return None
return parser.parse(value)
return datetime.fromisoformat(value) if value is not None else value
5 changes: 1 addition & 4 deletions aiida/restapi/common/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -663,8 +663,6 @@ def parse_query_string(self, query_string):
:param query_string (as obtained from request.query_string)
:return: parsed values for the querykeys
"""

from dateutil import parser as dtparser
from psycopg2.tz import FixedOffsetTimezone
from pyparsing import Combine, Group, Literal, OneOrMore, Optional, ParseException, QuotedString
from pyparsing import StringEnd as SE
Expand Down Expand Up @@ -722,15 +720,14 @@ def validate_time(toks):
:param toks: datetime string passed in tokens
:return: datetime object
"""

datetime_string = toks[0]

# Check the precision
precision = len(datetime_string.replace('T', ':').split(':'))

# Parse
try:
dtobj = dtparser.parse(datetime_string)
dtobj = datetime.fromisoformat(datetime_string)
except ValueError:
raise RestInputValidationError(
'time value has wrong format. The '
Expand Down
1 change: 0 additions & 1 deletion environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ dependencies:
- pgsu~=0.2.1
- psutil~=5.6
- psycopg2-binary~=2.8
- python-dateutil~=2.8
- pytz~=2021.1
- pyyaml~=5.4
- sqlalchemy~=1.4.22
Expand Down
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ dependencies = [
"pgsu~=0.2.1",
"psutil~=5.6",
"psycopg2-binary~=2.8",
"python-dateutil~=2.8",
"pytz~=2021.1",
"pyyaml~=5.4",
"sqlalchemy~=1.4.22",
Expand Down
1 change: 0 additions & 1 deletion requirements/requirements-py-3.10.txt
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ pytest-datadir==1.3.1
pytest-regressions==2.2.0
pytest-rerunfailures==9.1.1
pytest-timeout==1.4.2
python-dateutil==2.8.2
python-memcached==1.59
pytray==0.3.2
pytz==2021.3
Expand Down
1 change: 0 additions & 1 deletion requirements/requirements-py-3.8.txt
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ pytest-datadir==1.3.1
pytest-regressions==2.2.0
pytest-rerunfailures==9.1.1
pytest-timeout==1.4.2
python-dateutil==2.8.2
python-memcached==1.59
pytray==0.3.2
pytz==2021.3
Expand Down
1 change: 0 additions & 1 deletion requirements/requirements-py-3.9.txt
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ pytest-datadir==1.3.1
pytest-regressions==2.2.0
pytest-rerunfailures==9.1.1
pytest-timeout==1.4.2
python-dateutil==2.8.2
python-memcached==1.59
pytray==0.3.2
pytz==2021.3
Expand Down

0 comments on commit 8c50bd4

Please sign in to comment.