Skip to content

Commit 1bb088f

Browse files
authored
feat: optional ciso8601 (influxdata#120)
1 parent d19ff96 commit 1bb088f

File tree

10 files changed

+50
-12
lines changed

10 files changed

+50
-12
lines changed

.circleci/config.yml

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,14 @@ commands:
1616
parameters:
1717
python-image:
1818
type: string
19+
enabled-ciso-8601:
20+
type: boolean
1921
steps:
2022
- restore_cache:
2123
name: Restoring Pip Cache
2224
keys:
23-
- &cache-key pip-cache-v8-<< parameters.python-image >>-{{ checksum "requirements.txt" }}-{{ checksum "test-requirements.txt" }}-{{ checksum "extra-requirements.txt" }}
24-
- pip-cache-v8-<< parameters.python-image >>-
25+
- &cache-key pip-cache-v9-<< parameters.python-image >>-<< parameters.enabled-ciso-8601 >>-{{ checksum "requirements.txt" }}-{{ checksum "test-requirements.txt" }}-{{ checksum "extra-requirements.txt" }}-{{ checksum "ciso-requirements.txt" }}
26+
- pip-cache-v9-<< parameters.python-image >>-<< parameters.enabled-ciso-8601 >>-
2527
- run:
2628
command: | # use pipenv to install dependencies
2729
sudo pip install pipenv
@@ -48,15 +50,20 @@ jobs:
4850
influxdb-image:
4951
type: string
5052
default: "influxdb:2.0.0-beta"
53+
enabled-ciso-8601:
54+
type: boolean
55+
default: true
5156
docker:
5257
- image: << parameters.python-image >>
5358
environment: # environment variables for primary container
5459
PIPENV_VENV_IN_PROJECT: true
60+
ENABLED_CISO_8601: << parameters.enabled-ciso-8601 >>
5561
- image: quay.io/influxdb/<< parameters.influxdb-image >>
5662
steps:
5763
- prepare
5864
- client-test:
5965
python-image: << parameters.python-image >>
66+
enabled-ciso-8601: << parameters.enabled-ciso-8601 >>
6067
- store_test_results:
6168
path: test-reports
6269
- run:
@@ -69,6 +76,9 @@ workflows:
6976
jobs:
7077
- tests-python:
7178
name: python-3.6
79+
- tests-python:
80+
name: python-3.6-without-ciso8601
81+
enabled-ciso-8601: false
7282
- tests-python:
7383
name: python-3.6-nightly
7484
influxdb-image: "influx:nightly"

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
### Features
44
1. [#112](https://github.com/influxdata/influxdb-client-python/pull/113): Support timestamp with different timezone in _convert_timestamp
5+
1. [#120](https://github.com/influxdata/influxdb-client-python/pull/120): ciso8601 is an optional dependency and has to be installed separably
56

67
### Bug Fixes
78
1. [#117](https://github.com/influxdata/influxdb-client-python/pull/117): Fixed appending default tags for single Point

README.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ InfluxDB python library uses `RxPY <https://github.com/ReactiveX/RxPY>`__ - The
7676

7777
.. note::
7878

79-
The client uses ``ciso8601`` for parsing dates. ``ciso8601`` is much faster than built-in Python datetime. Since it's written as a ``C`` module the best way is build it from sources:
79+
It is recommended to use ``ciso8601`` with client for parsing dates. ``ciso8601`` is much faster than built-in Python datetime. Since it's written as a ``C`` module the best way is build it from sources:
8080

8181
**Windows**:
8282

@@ -93,7 +93,7 @@ The python package is hosted on `PyPI <https://pypi.org/project/influxdb-client/
9393

9494
.. code-block:: sh
9595
96-
pip install influxdb-client
96+
pip install influxdb-client[ciso]
9797
9898
Then import the package:
9999

ciso-requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ciso8601>=2.1.1

influxdb_client/client/date_utils.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from dateutil import parser
2+
3+
parse_function = None
4+
5+
6+
def get_date_parse_function():
7+
global parse_function
8+
if parse_function is None:
9+
try:
10+
import ciso8601
11+
parse_function = ciso8601.parse_datetime
12+
except ModuleNotFoundError:
13+
parse_function = parser.parse
14+
15+
return parse_function

influxdb_client/client/flux_csv_parser.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
from enum import Enum
55
from typing import List
66

7-
import ciso8601
87
from urllib3 import HTTPResponse
98

9+
from influxdb_client.client.date_utils import get_date_parse_function
1010
from influxdb_client.client.flux_table import FluxTable, FluxColumn, FluxRecord
1111

1212

@@ -194,7 +194,7 @@ def _to_value(self, str_val, column):
194194
if "dateTime:RFC3339" == column.data_type or "dateTime:RFC3339Nano" == column.data_type:
195195
# todo nanosecods precision
196196
# return str_val
197-
return ciso8601.parse_datetime(str_val)
197+
return get_date_parse_function()(str_val)
198198
# return timestamp_parser(str_val)
199199

200200
if "duration" == column.data_type:
@@ -230,4 +230,4 @@ def add_column_names_and_tags(table, csv):
230230

231231
def _insert_table(self, table, table_index):
232232
if self._serialization_mode is FluxSerializationMode.tables:
233-
self.tables.insert(table_index, table)
233+
self.tables.insert(table_index, table)

influxdb_client/client/write/point.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
from decimal import Decimal
55
from numbers import Integral
66

7-
import ciso8601
87
from pytz import UTC
98
from six import iteritems
109

10+
from influxdb_client.client.date_utils import get_date_parse_function
1111
from influxdb_client.domain.write_precision import WritePrecision
1212

1313
EPOCH = UTC.localize(datetime.utcfromtimestamp(0))
@@ -45,6 +45,7 @@ def __init__(self, measurement_name):
4545
self._name = measurement_name
4646
self._time = None
4747
self._write_precision = DEFAULT_WRITE_PRECISION
48+
pass
4849

4950
def time(self, time, write_precision=DEFAULT_WRITE_PRECISION):
5051
"""
@@ -153,7 +154,7 @@ def _convert_timestamp(timestamp, precision=DEFAULT_WRITE_PRECISION):
153154
return timestamp # assume precision is correct if timestamp is int
154155

155156
if isinstance(timestamp, str):
156-
timestamp = ciso8601.parse_datetime(timestamp)
157+
timestamp = get_date_parse_function()(timestamp)
157158

158159
if isinstance(timestamp, timedelta) or isinstance(timestamp, datetime):
159160

requirements.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,4 @@ six >= 1.10
44
python_dateutil >= 2.5.3
55
setuptools >= 21.0.0
66
urllib3 >= 1.15.1
7-
ciso8601>=2.1.1
87
pytz>=2019.1

scripts/ci-test.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,21 @@
22

33
set -e
44

5+
ENABLED_CISO_8601="${ENABLED_CISO_8601:-true}"
6+
57
#
68
# Install requirements
79
#
810
python --version
911
pip install -r requirements.txt --user
1012
pip install -r extra-requirements.txt --user
1113
pip install -r test-requirements.txt --user
14+
if [ "$ENABLED_CISO_8601" = true ] ; then
15+
echo "ciso8601 is enabled"
16+
pip install -r ciso-requirements.txt --user
17+
else
18+
echo "ciso8601 is disabled"
19+
fi
1220
pip install pytest pytest-cov --user
1321
pip install twine --user
1422
python setup.py sdist bdist_wheel

setup.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
with open('extra-requirements.txt', 'r') as f:
1414
extra_requires = [x.strip() for x in f if x.strip()]
1515

16+
with open('ciso-requirements.txt', 'r') as f:
17+
ciso_requires = [x.strip() for x in f if x.strip()]
18+
1619
with open('README.rst', 'r') as f:
1720
readme = f.read()
1821

@@ -32,13 +35,13 @@
3235
keywords=["InfluxDB", "InfluxDB Python Client"],
3336
tests_require=test_requires,
3437
install_requires=requires,
35-
extras_require={'extra': extra_requires},
38+
extras_require={'extra': extra_requires, 'ciso': ciso_requires},
3639
long_description_content_type="text/x-rst",
3740
packages=find_packages(),
3841
test_suite='tests',
3942
python_requires='>=3.6',
4043
include_package_data=True,
41-
data_files=['requirements.txt', 'extra-requirements.txt', 'test-requirements.txt'],
44+
data_files=['requirements.txt', 'extra-requirements.txt', 'test-requirements.txt', 'ciso-requirements.txt'],
4245
classifiers = [
4346
'Development Status :: 4 - Beta',
4447
'Intended Audience :: Developers',

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy