Skip to content

Commit

Permalink
Merge pull request #3 from ContinuumIO/new_intake
Browse files Browse the repository at this point in the history
updates for intake 0.2
  • Loading branch information
martindurant committed Jul 23, 2018
2 parents 282eca4 + 8653fa8 commit 6f2d28f
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 46 deletions.
2 changes: 1 addition & 1 deletion conda/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ requirements:
- python
- jinja2
run:
- intake
- intake>=0.2
- python
- requests

Expand Down
4 changes: 0 additions & 4 deletions docs/source/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@ API Reference
=============

.. autosummary::
intake_splunk.Plugin
intake_splunk.core.SplunkSource

.. autoclass:: intake_splunk.Plugin
:members:

.. autoclass:: intake_splunk.core.SplunkSource
:members:
5 changes: 3 additions & 2 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,10 @@
# built documents.
#
# The short X.Y version.
version = u'0.0.2'
import intake_splunk
version = intake_splunk.__version__
# The full version, including alpha/beta/rc tags.
release = u'0.0.2'
release = intake_splunk.__version__

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand Down
3 changes: 3 additions & 0 deletions docs/source/index.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
Welcome to intake-splunk's documentation!
================================================

This package accesses tabular data in Splunk, and can be used by Intake to
load that into pandas dataframes.

.. toctree::
:maxdepth: 2
:caption: Contents:
Expand Down
8 changes: 1 addition & 7 deletions docs/source/quickstart.rst
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,7 @@ Three parameters are of interest when defining a data source:
Creating Catalog Entries
~~~~~~~~~~~~~~~~~~~~~~~~

To include in a catalog, the plugin must be listed in the plugins of the catalog::

plugins:
source:
- module: intake_splunk

and entries must specify ``driver: splunk``.
To use, catalog entries must specify ``driver: splunk``.



Expand Down
26 changes: 1 addition & 25 deletions intake_splunk/__init__.py
Original file line number Diff line number Diff line change
@@ -1,29 +1,5 @@
from intake.source import base
from ._version import get_versions
__version__ = get_versions()['version']
del get_versions


class Plugin(base.Plugin):
"""Plugin for Splunk reader"""

def __init__(self):
super(Plugin, self).__init__(name='splunk',
version=__version__,
container='dataframe',
partition_access=True)

def open(self, query, url, auth, chunksize=5000, **kwargs):
"""
Create SplunkSource instance
Parameters
----------
query, url, auth, chunksize
See ``SplunkSource``.
"""
from intake_splunk.core import SplunkSource
base_kwargs, source_kwargs = self.separate_base_kwargs(kwargs)
return SplunkSource(query, url, auth,
metadata=base_kwargs['metadata'],
**source_kwargs)
from .core import SplunkSource
19 changes: 12 additions & 7 deletions intake_splunk/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

# because Splunk connections are against a self-signed cert, all connections
# would raise a warning
from . import __version__
warnings.filterwarnings('ignore', module='urllib3.connectionpool')


Expand All @@ -28,24 +29,28 @@ class SplunkSource(base.DataSource):
"""
container = 'dataframe'
version = __version__
name = 'splunk'
partition_access = True

def __init__(self, query, url, auth, chunksize=5000,
metadata=None):
self.splunk = SplunkConnect(url)
if isinstance(auth, (tuple, list)):
self.splunk.auth(*auth)
else:
self.splunk.auth_head(key=auth)
self.url = url
self.auth = auth
self.query = query
self.chunksize = chunksize
self._df = None
super(SplunkSource, self).__init__(container=self.container,
metadata=metadata)
super(SplunkSource, self).__init__(metadata=metadata)

def _get_schema(self):
if self._df is None:
# this waits until query is ready, but Splunk has results_preview
# end-point which can be fetched while query is running
self.splunk = SplunkConnect(self.url)
if isinstance(self.auth, (tuple, list)):
self.splunk.auth(*self.auth)
else:
self.splunk.auth_head(key=self.auth)
self._df = self.splunk.read_dask(self.query, self.chunksize)
self.npartitions = self._df.npartitions
return base.Schema(datashape=None,
Expand Down

0 comments on commit 6f2d28f

Please sign in to comment.