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

All the recent changes, now against master 🤦‍♂️ #163

Merged
merged 5 commits into from
Dec 8, 2024
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
47 changes: 31 additions & 16 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,20 @@ workflows:
- test_old_pythons:
matrix:
parameters:
python_version: ["2.7", "3.5", "3.6", "3.7"]
python_version: ["2.7", "3.5"]
- test:
matrix:
parameters:
python_version: ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13"]
python_version:
["3.6", "3.7", "3.8", "3.9", "3.10", "3.11", "3.12", "3.13"]
- test_old_pypy:
matrix:
parameters:
python_version: ["2.7"]
- test_pypy:
matrix:
parameters:
python_version: ["2.7", "3.7", "3.8", "3.9", "3.10"]
python_version: ["3.7", "3.8", "3.9", "3.10"]
- lint-rst
- clang-format

Expand All @@ -31,7 +36,7 @@ jobs:
docker:
- image: circleci/python:3.4

test_old_pythons:
test_old_pythons: &old_python_tests
parameters:
python_version:
type: string
Expand All @@ -43,30 +48,40 @@ jobs:
docker:
- image: cimg/python:<<parameters.python_version>>

test:
test_old_pypy:
<<: *old_python_tests
docker:
- image: pypy:<<parameters.python_version>>

test: &tests
parameters:
python_version:
type: string
steps:
- checkout
- run:
name: Install ciso8601
command: |
python -m venv venv
. venv/bin/activate
pip install --upgrade build
python -m build -s
pip install dist/ciso8601-*.tar.gz
- run:
name: Install testing dependencies
command: |
. venv/bin/activate
pip install pytz
- run:
name: Test
# setuptools dropped support for being a test runner in v72.0.0
command: |
pip install --force-reinstall 'setuptools==71.1.0'
python setup.py test
. venv/bin/activate
python -m unittest
docker:
- image: cimg/python:<<parameters.python_version>>

test_pypy:
parameters:
python_version:
type: string
steps:
- checkout
- run:
name: Test
command: pypy setup.py test
<<: *tests
docker:
- image: pypy:<<parameters.python_version>>

Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
* Add support for aarch64 wheels. Thank you @bbayles!
* Add wheels for PyPy 3.10
* Added Python 3.13 support
* Better error message when attempting to parse a BCE year (#156). Thanks @javiabellan

# 2.x.x

Expand Down
174 changes: 87 additions & 87 deletions README.rst

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions benchmarking/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ RUN apt-get update && \
# Install the other dependencies
RUN apt-get install -y git curl gcc build-essential

# Install the Rust toolchain for `pendulum`
RUN curl --proto '=https' --tlsv1.3 -sSf https://sh.rustup.rs | sh -s -- -y

# Install tzdata non-iteractively
# https://stackoverflow.com/questions/44331836/apt-get-install-tzdata-noninteractive/44333806#44333806
RUN DEBIAN_FRONTEND=noninteractive apt-get install -y tzdata
Expand Down
8 changes: 2 additions & 6 deletions benchmarking/perform_comparison.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"python-dateutil": ("import dateutil.parser", "dateutil.parser.parse('{timestamp}')"),
"iso8601": ("import iso8601", "iso8601.parse_date('{timestamp}')"),
"isodate": ("import isodate", "isodate.parse_datetime('{timestamp}')"),
"pendulum": ("from pendulum.parsing import parse_iso8601", "parse_iso8601('{timestamp}')"),
"PySO8601": ("import PySO8601", "PySO8601.parse('{timestamp}')"),
"str2date": ("from str2date import str2date", "str2date('{timestamp}')"),
}
Expand Down Expand Up @@ -59,15 +60,10 @@
# `arrow` no longer supports Python 3.4
ISO_8601_MODULES["arrow"] = ("import arrow", "arrow.get('{timestamp}').datetime")

if sys.version_info.major >= 3 and (sys.version_info.major, sys.version_info.minor) < (3, 12):
if sys.version_info.major >= 3:
# `maya` uses a version of `regex` which no longer supports Python 2
# `maya` uses `pendulum`, which doesn't yet support Python 3.12
ISO_8601_MODULES["maya"] = ("import maya", "maya.parse('{timestamp}').datetime()")

if (sys.version_info.major, sys.version_info.minor) < (3, 12):
# `pendulum` doesn't yet support Python 3.12
ISO_8601_MODULES["pendulum"] = ("from pendulum.parsing import parse_iso8601", "parse_iso8601('{timestamp}')")

if (sys.version_info.major, sys.version_info.minor) >= (3, 5):
# `moment` is built on `times`, which is built on `arrow`, which no longer supports Python 3.4
# `moment` uses a version of `regex` which no longer supports Python 2
Expand Down
8 changes: 3 additions & 5 deletions benchmarking/tox.ini
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[tox]
requires =
tox>=4
envlist = py313,py312,py311,py310,py39,py38,py37
envlist = py313,py312,py311,py310,py39,py38
setupdir=..

[testenv]
Expand All @@ -26,14 +26,12 @@ deps=
iso8601utils; python_version != '3.6' and python_version != '3.10'
isodate
; `maya` uses a version of `regex` which no longer supports Python 2
; `maya` uses `pendulum`, which doesn't yet support Python 3.12
maya; python_version > '3' and python_version < '3.12'
maya; python_version > '3'
metomi-isodatetime; python_version >= '3.5'
; `moment` is built on `times`, which is built on `arrow`, which no longer supports Python 3.4
; `moment` uses a version of `regex` which no longer supports Python 2
moment; python_version >= '3.5'
; `pendulum` doesn't yet support Python 3.12
pendulum; python_version < '3.12'
pendulum
pyso8601
python-dateutil
str2date
Expand Down
8 changes: 8 additions & 0 deletions module.c
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,14 @@ format_unexpected_character_exception(char *field_name, const char *c,
field_name, expected_character_count,
(expected_character_count != 1) ? "s" : "");
}
else if (*c == '-' && index == 0 && strcmp(field_name, "year") == 0) {
PyErr_Format(
PyExc_ValueError,
"Invalid character while parsing %s ('-', Index: 0). "
"While valid ISO 8601 years, BCE years are not supported by "
"Python's `datetime` objects.",
field_name);
}
else {
#if PY_VERSION_AT_LEAST_33
PyObject *unicode_str = PyUnicode_FromString(c);
Expand Down
11 changes: 11 additions & 0 deletions tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,17 @@ def test_mixed_basic_and_extended_formats(self):
"20140102T01:02:03",
)

def test_bce_years(self):
"""
These are technically valid ISO 8601 datetimes.
However, cPython cannot support values non-positive year values
"""
self.assertRaisesRegex(
ValueError,
r"Invalid character while parsing year \('-', Index: 0\). While valid ISO 8601 years, BCE years are not supported by Python's `datetime` objects.",
parse_datetime,
"-2014-01-02",
)

class Rfc3339TestCase(unittest.TestCase):
def test_valid_rfc3339_timestamps(self):
Expand Down
5 changes: 2 additions & 3 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[tox]
requires =
tox>=4
envlist = {py27,py34,py35,py36,py37,py38,py39,py310,py311,py312}-caching_{enabled,disabled}
envlist = {py313,py312,py311,py310,py39,py38}-caching_{enabled,disabled}

[testenv]
package = sdist
Expand All @@ -11,5 +11,4 @@ setenv =
caching_disabled: CISO8601_CACHING_ENABLED = 0
deps =
pytz
nose
commands=nosetests
commands=python -m unittest
6 changes: 3 additions & 3 deletions why_ciso8601.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ graph TD;
H--yes-->V;
H--no-->Z;

V[Use `backports.datetime_fromisoformat`]
Y[Use `ciso8601`]
Z[Use `datetime.fromisoformat`]
V[Use backports.datetime_fromisoformat]
Y[Use ciso8601]
Z[Use datetime.fromisoformat]
```

## Do you care about the performance of timestamp parsing?
Expand Down