From 54d4909bbfd2b746cd6ef5e4a3bf31ff6c9fc384 Mon Sep 17 00:00:00 2001 From: doyle Date: Mon, 14 Sep 2020 12:25:30 -0700 Subject: [PATCH 1/6] Allow skipping DataFrameClient import Importing the DataFrameClient can take quite a while, especially when the source files aren't yet loaded into the page cache. This patch adds an environment variable, INFLUXDB_NO_DATAFRAME_CLIENT, to allow users of this package to skip this import in cases where they don't need it. --- docs/source/api-documentation.rst | 4 ++++ examples/tutorial.py | 2 ++ influxdb/__init__.py | 8 ++++++-- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/docs/source/api-documentation.rst b/docs/source/api-documentation.rst index d00600e6..673bf76d 100644 --- a/docs/source/api-documentation.rst +++ b/docs/source/api-documentation.rst @@ -10,6 +10,10 @@ To connect to a InfluxDB, you must create a connects to InfluxDB on ``localhost`` with the default ports. The below instantiation statements are all equivalent:: + # Set INFLUXDB_NO_DATAFRAME_CLIENT to skip the expensive DataFrameClient + # import in cases where you only need the basic InfluxDBClient. + os.environ["INFLUXDB_NO_DATAFRAME_CLIENT"] = "1" + from influxdb import InfluxDBClient # using Http diff --git a/examples/tutorial.py b/examples/tutorial.py index 4083bfc5..26b51a6c 100644 --- a/examples/tutorial.py +++ b/examples/tutorial.py @@ -3,6 +3,8 @@ import argparse +import os +os.environ["INFLUXDB_NO_DATAFRAME_CLIENT"] = "1" from influxdb import InfluxDBClient diff --git a/influxdb/__init__.py b/influxdb/__init__.py index 33b7df4f..81eddce2 100644 --- a/influxdb/__init__.py +++ b/influxdb/__init__.py @@ -6,16 +6,20 @@ from __future__ import print_function from __future__ import unicode_literals +import os + from .client import InfluxDBClient -from .dataframe_client import DataFrameClient from .helper import SeriesHelper __all__ = [ 'InfluxDBClient', - 'DataFrameClient', 'SeriesHelper', ] +if "INFLUXDB_NO_DATAFRAME_CLIENT" not in os.environ: + from .dataframe_client import DataFrameClient + __all__.append( "DataFrameClient" ) + __version__ = '5.0.0' From d156b2c9894c72465d6187c5138dfe728091be35 Mon Sep 17 00:00:00 2001 From: doyle Date: Mon, 14 Sep 2020 12:25:30 -0700 Subject: [PATCH 2/6] Allow skipping DataFrameClient import Importing the DataFrameClient can take quite a while, especially when the source files aren't yet loaded into the page cache. This patch adds an environment variable, INFLUXDB_NO_DATAFRAME_CLIENT, to allow users of this package to skip this import in cases where they don't need it. --- influxdb/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/influxdb/__init__.py b/influxdb/__init__.py index 81eddce2..e0070faa 100644 --- a/influxdb/__init__.py +++ b/influxdb/__init__.py @@ -17,7 +17,7 @@ 'SeriesHelper', ] -if "INFLUXDB_NO_DATAFRAME_CLIENT" not in os.environ: +if os.environ.get("INFLUXDB_NO_DATAFRAME_CLIENT", "0").lower() not in ("0", "false"): from .dataframe_client import DataFrameClient __all__.append( "DataFrameClient" ) From 5677f847f3bf5d1a7008c9a633d9e382ee35a15d Mon Sep 17 00:00:00 2001 From: doyle Date: Mon, 14 Sep 2020 12:25:30 -0700 Subject: [PATCH 3/6] Allow skipping DataFrameClient import Importing the DataFrameClient can take quite a while, especially when the source files aren't yet loaded into the page cache. This patch adds an environment variable, INFLUXDB_NO_DATAFRAME_CLIENT, to allow users of this package to skip this import in cases where they don't need it. --- influxdb/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/influxdb/__init__.py b/influxdb/__init__.py index e0070faa..db106398 100644 --- a/influxdb/__init__.py +++ b/influxdb/__init__.py @@ -17,7 +17,7 @@ 'SeriesHelper', ] -if os.environ.get("INFLUXDB_NO_DATAFRAME_CLIENT", "0").lower() not in ("0", "false"): +if os.environ.get("INFLUXDB_NO_DATAFRAME_CLIENT", "0").lower() not in ("1", "true"): from .dataframe_client import DataFrameClient __all__.append( "DataFrameClient" ) From 0f607bd83fcde6a2b413b40ceda0beef9db7865b Mon Sep 17 00:00:00 2001 From: Jonathan Doyle Date: Tue, 29 Sep 2020 11:13:58 -0700 Subject: [PATCH 4/6] Fix flake regressions --- influxdb/__init__.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/influxdb/__init__.py b/influxdb/__init__.py index db106398..da1ddb56 100644 --- a/influxdb/__init__.py +++ b/influxdb/__init__.py @@ -17,9 +17,10 @@ 'SeriesHelper', ] -if os.environ.get("INFLUXDB_NO_DATAFRAME_CLIENT", "0").lower() not in ("1", "true"): - from .dataframe_client import DataFrameClient - __all__.append( "DataFrameClient" ) +NO_DATAFRAME_CLIENT = os.environ.get("INFLUXDB_NO_DATAFRAME_CLIENT", "0") +if NO_DATAFRAME_CLIENT.lower() not in ("1", "true"): + from .dataframe_client import DataFrameClient # noqa: F401 unused import + __all__.append("DataFrameClient") __version__ = '5.0.0' From 5ea056614dbeb7610f704f36ed562f0874cd4b83 Mon Sep 17 00:00:00 2001 From: Jonathan Doyle Date: Tue, 29 Sep 2020 11:56:55 -0700 Subject: [PATCH 5/6] Fix mismatched indent --- influxdb/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/influxdb/__init__.py b/influxdb/__init__.py index da1ddb56..4074c4ed 100644 --- a/influxdb/__init__.py +++ b/influxdb/__init__.py @@ -20,7 +20,7 @@ NO_DATAFRAME_CLIENT = os.environ.get("INFLUXDB_NO_DATAFRAME_CLIENT", "0") if NO_DATAFRAME_CLIENT.lower() not in ("1", "true"): from .dataframe_client import DataFrameClient # noqa: F401 unused import - __all__.append("DataFrameClient") + __all__.append("DataFrameClient") __version__ = '5.0.0' From f167b5ed43c838a080a9e3013fe113f8f545a72a Mon Sep 17 00:00:00 2001 From: Jonathan Doyle Date: Tue, 29 Sep 2020 14:00:17 -0700 Subject: [PATCH 6/6] Add extra space before inline comment --- influxdb/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/influxdb/__init__.py b/influxdb/__init__.py index 4074c4ed..da844b7b 100644 --- a/influxdb/__init__.py +++ b/influxdb/__init__.py @@ -19,7 +19,7 @@ NO_DATAFRAME_CLIENT = os.environ.get("INFLUXDB_NO_DATAFRAME_CLIENT", "0") if NO_DATAFRAME_CLIENT.lower() not in ("1", "true"): - from .dataframe_client import DataFrameClient # noqa: F401 unused import + from .dataframe_client import DataFrameClient # noqa: F401 unused import __all__.append("DataFrameClient")