Skip to content

feat: optional ciso8601 #120

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

Merged
merged 11 commits into from
Jun 30, 2020
14 changes: 12 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@ commands:
parameters:
python-image:
type: string
enabled-ciso-8601:
type: boolean
steps:
- restore_cache:
name: Restoring Pip Cache
keys:
- &cache-key pip-cache-v8-<< parameters.python-image >>-{{ checksum "requirements.txt" }}-{{ checksum "test-requirements.txt" }}-{{ checksum "extra-requirements.txt" }}
- pip-cache-v8-<< parameters.python-image >>-
- &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" }}
- pip-cache-v9-<< parameters.python-image >>-<< parameters.enabled-ciso-8601 >>-
- run:
command: | # use pipenv to install dependencies
sudo pip install pipenv
Expand All @@ -48,15 +50,20 @@ jobs:
influxdb-image:
type: string
default: "influxdb:2.0.0-beta"
enabled-ciso-8601:
type: boolean
default: true
docker:
- image: << parameters.python-image >>
environment: # environment variables for primary container
PIPENV_VENV_IN_PROJECT: true
ENABLED_CISO_8601: << parameters.enabled-ciso-8601 >>
- image: quay.io/influxdb/<< parameters.influxdb-image >>
steps:
- prepare
- client-test:
python-image: << parameters.python-image >>
enabled-ciso-8601: << parameters.enabled-ciso-8601 >>
- store_test_results:
path: test-reports
- run:
Expand All @@ -69,6 +76,9 @@ workflows:
jobs:
- tests-python:
name: python-3.6
- tests-python:
name: python-3.6-without-ciso8601
enabled-ciso-8601: false
- tests-python:
name: python-3.6-nightly
influxdb-image: "influx:nightly"
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

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

## 1.8.0 [2020-06-19]

Expand Down
4 changes: 2 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ InfluxDB python library uses `RxPY <https://github.com/ReactiveX/RxPY>`__ - The

.. note::

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:
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:

**Windows**:

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

.. code-block:: sh

pip install influxdb-client
pip install influxdb-client[ciso]

Then import the package:

Expand Down
1 change: 1 addition & 0 deletions ciso-requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ciso8601>=2.1.1
15 changes: 15 additions & 0 deletions influxdb_client/client/date_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from dateutil import parser

parse_function = None


def get_date_parse_function():
global parse_function
if parse_function is None:
try:
import ciso8601
parse_function = ciso8601.parse_datetime
except ModuleNotFoundError:
parse_function = parser.parse

return parse_function
6 changes: 3 additions & 3 deletions influxdb_client/client/flux_csv_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
from enum import Enum
from typing import List

import ciso8601
from urllib3 import HTTPResponse

from influxdb_client.client.date_utils import get_date_parse_function
from influxdb_client.client.flux_table import FluxTable, FluxColumn, FluxRecord


Expand Down Expand Up @@ -194,7 +194,7 @@ def _to_value(self, str_val, column):
if "dateTime:RFC3339" == column.data_type or "dateTime:RFC3339Nano" == column.data_type:
# todo nanosecods precision
# return str_val
return ciso8601.parse_datetime(str_val)
return get_date_parse_function()(str_val)
# return timestamp_parser(str_val)

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

def _insert_table(self, table, table_index):
if self._serialization_mode is FluxSerializationMode.tables:
self.tables.insert(table_index, table)
self.tables.insert(table_index, table)
5 changes: 3 additions & 2 deletions influxdb_client/client/write/point.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
from decimal import Decimal
from numbers import Integral

import ciso8601
from pytz import UTC
from six import iteritems

from influxdb_client.client.date_utils import get_date_parse_function
from influxdb_client.domain.write_precision import WritePrecision

EPOCH = UTC.localize(datetime.utcfromtimestamp(0))
Expand Down Expand Up @@ -45,6 +45,7 @@ def __init__(self, measurement_name):
self._name = measurement_name
self._time = None
self._write_precision = DEFAULT_WRITE_PRECISION
pass

def time(self, time, write_precision=DEFAULT_WRITE_PRECISION):
"""
Expand Down Expand Up @@ -153,7 +154,7 @@ def _convert_timestamp(timestamp, precision=DEFAULT_WRITE_PRECISION):
return timestamp # assume precision is correct if timestamp is int

if isinstance(timestamp, str):
timestamp = ciso8601.parse_datetime(timestamp)
timestamp = get_date_parse_function()(timestamp)

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

Expand Down
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@ six >= 1.10
python_dateutil >= 2.5.3
setuptools >= 21.0.0
urllib3 >= 1.15.1
ciso8601>=2.1.1
pytz>=2019.1
8 changes: 8 additions & 0 deletions scripts/ci-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,21 @@

set -e

ENABLED_CISO_8601="${ENABLED_CISO_8601:-true}"

#
# Install requirements
#
python --version
pip install -r requirements.txt --user
pip install -r extra-requirements.txt --user
pip install -r test-requirements.txt --user
if [ "$ENABLED_CISO_8601" = true ] ; then
echo "ciso8601 is enabled"
pip install -r ciso-requirements.txt --user
else
echo "ciso8601 is disabled"
fi
pip install pytest pytest-cov --user
pip install twine --user
python setup.py sdist bdist_wheel
Expand Down
7 changes: 5 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
with open('extra-requirements.txt', 'r') as f:
extra_requires = [x.strip() for x in f if x.strip()]

with open('ciso-requirements.txt', 'r') as f:
ciso_requires = [x.strip() for x in f if x.strip()]

with open('README.rst', 'r') as f:
readme = f.read()

Expand All @@ -32,13 +35,13 @@
keywords=["InfluxDB", "InfluxDB Python Client"],
tests_require=test_requires,
install_requires=requires,
extras_require={'extra': extra_requires},
extras_require={'extra': extra_requires, 'ciso': ciso_requires},
long_description_content_type="text/x-rst",
packages=find_packages(),
test_suite='tests',
python_requires='>=3.6',
include_package_data=True,
data_files=['requirements.txt', 'extra-requirements.txt', 'test-requirements.txt'],
data_files=['requirements.txt', 'extra-requirements.txt', 'test-requirements.txt', 'ciso-requirements.txt'],
classifiers = [
'Development Status :: 4 - Beta',
'Intended Audience :: Developers',
Expand Down