Skip to content
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
8 changes: 3 additions & 5 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""Setup module."""
#!/usr/bin/env python
# !/usr/bin/env python

from os import path
from setuptools import setup, find_packages
Expand All @@ -16,23 +16,21 @@
INSTALL_REQUIRES = [
'requests>=2.9.1',
'pyyaml>=5.1',
'future>=0.15.2',
'docopt>=0.6.2',
'enum34;python_version<"3.4"',
'futures>=3.0.5;python_version<"3"'
]

with open(path.join(path.abspath(path.dirname(__file__)), 'splitio', 'version.py')) as f:
exec(f.read()) # pylint: disable=exec-used

setup(
name='splitio_client',
version=__version__, # pylint: disable=undefined-variable
version=__version__, # pylint: disable=undefined-variable
description='Split.io Python Client',
author='Patricio Echague, Sebastian Arrubia',
author_email='pato@split.io, sebastian@split.io',
url='https://github.com/splitio/python-client',
download_url=('https://github.com/splitio/python-client/tarball/' + __version__), # pylint: disable=undefined-variable
download_url=('https://github.com/splitio/python-client/tarball/' + __version__), # pylint: disable=undefined-variable
license='Apache License 2.0',
install_requires=INSTALL_REQUIRES,
tests_require=TESTS_REQUIRES,
Expand Down
3 changes: 0 additions & 3 deletions splitio/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
from __future__ import absolute_import, division, print_function, \
unicode_literals

from splitio.client.factory import get_factory
from splitio.client.key import Key
from splitio.version import __version__
4 changes: 1 addition & 3 deletions splitio/api/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
import logging
import json

from future.utils import raise_from

from splitio.api import APIException, headers_from_metadata
from splitio.api.client import HttpClientException
from splitio.models.token import from_raw
Expand Down Expand Up @@ -53,4 +51,4 @@ def authenticate(self):
except HttpClientException as exc:
_LOGGER.error('Exception raised while authenticating')
_LOGGER.debug('Exception information: ', exc_info=True)
raise_from(APIException('Could not perform authentication.'), exc)
raise APIException('Could not perform authentication.') from exc
7 changes: 2 additions & 5 deletions splitio/api/client.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
"""Synchronous HTTP Client for split API."""
from __future__ import division

from collections import namedtuple

from future.utils import raise_from
import requests

HttpResponse = namedtuple('HttpResponse', ['status_code', 'body'])
Expand Down Expand Up @@ -107,7 +104,7 @@ def get(self, server, path, apikey, query=None, extra_headers=None): # pylint:
)
return HttpResponse(response.status_code, response.text)
except Exception as exc: # pylint: disable=broad-except
raise_from(HttpClientException('requests library is throwing exceptions'), exc)
raise HttpClientException('requests library is throwing exceptions') from exc

def post(self, server, path, apikey, body, query=None, extra_headers=None): # pylint: disable=too-many-arguments
"""
Expand Down Expand Up @@ -144,4 +141,4 @@ def post(self, server, path, apikey, body, query=None, extra_headers=None): # p
)
return HttpResponse(response.status_code, response.text)
except Exception as exc: # pylint: disable=broad-except
raise_from(HttpClientException('requests library is throwing exceptions'), exc)
raise HttpClientException('requests library is throwing exceptions') from exc
4 changes: 1 addition & 3 deletions splitio/api/events.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
"""Events API module."""
import logging

from future.utils import raise_from

from splitio.api import APIException, headers_from_metadata
from splitio.api.client import HttpClientException

Expand Down Expand Up @@ -75,4 +73,4 @@ def flush_events(self, events):
except HttpClientException as exc:
_LOGGER.error('Error posting events because an exception was raised by the HTTPClient')
_LOGGER.debug('Error: ', exc_info=True)
raise_from(APIException('Events not flushed properly.'), exc)
raise APIException('Events not flushed properly.') from exc
6 changes: 2 additions & 4 deletions splitio/api/impressions.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
import logging
from itertools import groupby

from future.utils import raise_from

from splitio.api import APIException, headers_from_metadata
from splitio.api.client import HttpClientException
from splitio.engine.impressions import ImpressionsMode
Expand Down Expand Up @@ -107,7 +105,7 @@ def flush_impressions(self, impressions):
'Error posting impressions because an exception was raised by the HTTPClient'
)
_LOGGER.debug('Error: ', exc_info=True)
raise_from(APIException('Impressions not flushed properly.'), exc)
raise APIException('Impressions not flushed properly.') from exc

def flush_counters(self, counters):
"""
Expand All @@ -133,4 +131,4 @@ def flush_counters(self, counters):
'HTTPClient'
)
_LOGGER.debug('Error: ', exc_info=True)
raise_from(APIException('Impressions not flushed properly.'), exc)
raise APIException('Impressions not flushed properly.') from exc
4 changes: 1 addition & 3 deletions splitio/api/segments.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
import json
import logging

from future.utils import raise_from

from splitio.api import APIException, headers_from_metadata
from splitio.api.client import HttpClientException

Expand Down Expand Up @@ -62,4 +60,4 @@ def fetch_segment(self, segment_name, change_number):
segment_name
)
_LOGGER.debug('Error: ', exc_info=True)
raise_from(APIException('Segments not fetched properly.'), exc)
raise APIException('Segments not fetched properly.') from exc
4 changes: 1 addition & 3 deletions splitio/api/splits.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
import logging
import json

from future.utils import raise_from

from splitio.api import APIException, headers_from_metadata
from splitio.api.client import HttpClientException

Expand Down Expand Up @@ -55,4 +53,4 @@ def fetch_splits(self, change_number):
except HttpClientException as exc:
_LOGGER.error('Error fetching splits because an exception was raised by the HTTPClient')
_LOGGER.debug('Error: ', exc_info=True)
raise_from(APIException('Splits not fetched correctly.'), exc)
raise APIException('Splits not fetched correctly.') from exc
8 changes: 3 additions & 5 deletions splitio/api/telemetry.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
"""Telemetry API Module."""
import logging

from future.utils import raise_from

from splitio.api import APIException, headers_from_metadata
from splitio.api.client import HttpClientException

Expand Down Expand Up @@ -64,7 +62,7 @@ def flush_latencies(self, latencies):
'Error posting latencies because an exception was raised by the HTTPClient'
)
_LOGGER.debug('Error: ', exc_info=True)
raise_from(APIException('Latencies not flushed correctly.'), exc)
raise APIException('Latencies not flushed correctly.') from exc

@staticmethod
def _build_gauges(gauges):
Expand Down Expand Up @@ -102,7 +100,7 @@ def flush_gauges(self, gauges):
'Error posting gauges because an exception was raised by the HTTPClient'
)
_LOGGER.debug('Error: ', exc_info=True)
raise_from(APIException('Gauges not flushed correctly.'), exc)
raise APIException('Gauges not flushed correctly.') from exc

@staticmethod
def _build_counters(counters):
Expand Down Expand Up @@ -140,4 +138,4 @@ def flush_counters(self, counters):
'Error posting counters because an exception was raised by the HTTPClient'
)
_LOGGER.debug('Error: ', exc_info=True)
raise_from(APIException('Counters not flushed correctly.'), exc)
raise APIException('Counters not flushed correctly.') from exc
3 changes: 0 additions & 3 deletions splitio/client/client.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
"""A module for Split.io SDK API clients."""
from __future__ import absolute_import, division, print_function, \
unicode_literals

import logging
import time
from splitio.engine.evaluator import Evaluator, CONTROL
Expand Down
2 changes: 0 additions & 2 deletions splitio/client/config.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
"""Default settings for the Split.IO SDK Python client."""
from __future__ import absolute_import, division, print_function, unicode_literals

import os.path
import logging

Expand Down
3 changes: 0 additions & 3 deletions splitio/client/factory.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
"""A module for Split.io Factories."""
from __future__ import absolute_import, division, print_function, unicode_literals


import logging
import threading
from collections import Counter
Expand Down
3 changes: 0 additions & 3 deletions splitio/client/input_validator.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
"""Input validation module."""
from __future__ import absolute_import, division, print_function, \
unicode_literals

from numbers import Number
import logging
import re
Expand Down
2 changes: 0 additions & 2 deletions splitio/client/key.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
"""A module for Split.io SDK API clients."""
from __future__ import absolute_import, division, print_function, \
unicode_literals


class Key(object):
Expand Down
12 changes: 4 additions & 8 deletions splitio/client/listener.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,14 @@

import abc

from future.utils import raise_from


class ImpressionListenerException(Exception):
"""Custom Exception for Impression Listener."""

pass


class ImpressionListenerWrapper(object): #pylint: disable=too-few-public-methods
class ImpressionListenerWrapper(object): # pylint: disable=too-few-public-methods
"""
Impression listener safe-execution wrapper.

Expand Down Expand Up @@ -49,11 +47,9 @@ def log_impression(self, impression, attributes=None):
data['instance-id'] = self._metadata.instance_name
try:
self.impression_listener.log_impression(data)
except Exception as exc: #pylint: disable=broad-except
raise_from(
ImpressionListenerException('Error in log_impression user\'s method is throwing exceptions'),
exc
)
except Exception as exc: # pylint: disable=broad-except
raise ImpressionListenerException('Error in log_impression user\'s method is throwing exceptions') from exc


class ImpressionListener(object, metaclass=abc.ABCMeta):
"""Impression listener interface."""
Expand Down
8 changes: 0 additions & 8 deletions splitio/client/localhost.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,8 @@
"""Localhost client mocked components."""

import itertools
import logging
import re

from future.utils import raise_from
import yaml

from splitio.models import splits
from splitio.storage import ImpressionStorage, EventStorage, TelemetryStorage
from splitio.tasks import BaseSynchronizationTask
from splitio.tasks.util import asynctask

_LEGACY_COMMENT_LINE_RE = re.compile(r'^#.*$')
_LEGACY_DEFINITION_LINE_RE = re.compile(r'^(?<![^#])(?P<feature>[\w_-]+)\s+(?P<treatment>[\w_-]+)$')
Expand Down
2 changes: 0 additions & 2 deletions splitio/client/manager.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
"""A module for Split.io Managers."""
from __future__ import absolute_import, division, print_function, unicode_literals

import logging

from . import input_validator
Expand Down
12 changes: 5 additions & 7 deletions splitio/engine/hashfns/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
as well as the optional import (if installed) of a C compiled murmur hash
function with python bindings.
"""
from __future__ import absolute_import, division, print_function, \
unicode_literals

from splitio.models.splits import HashAlgorithm
from splitio.engine.hashfns import legacy

Expand All @@ -23,17 +20,18 @@ def _murmur_hash128(key, seed):

except ImportError:
# Fallback to interpreted python hash algoritm (slower)
from splitio.engine.hashfns import murmur3py #pylint: disable=ungrouped-imports
_murmur_hash = murmur3py.murmur32_py #pylint: disable=invalid-name
_murmur_hash128 = lambda k, s: murmur3py.hash128_x64(k, s)[0] #pylint: disable=invalid-name
from splitio.engine.hashfns import murmur3py # pylint: disable=ungrouped-imports
_murmur_hash = murmur3py.murmur32_py # pylint: disable=invalid-name
_murmur_hash128 = lambda k, s: murmur3py.hash128_x64(k, s)[0] # pylint: disable=invalid-name


_HASH_ALGORITHMS = {
HashAlgorithm.LEGACY: legacy.legacy_hash,
HashAlgorithm.MURMUR: _murmur_hash
}

murmur_128 = _murmur_hash128 #pylint: disable=invalid-name
murmur_128 = _murmur_hash128 # pylint: disable=invalid-name


def get_hash_fn(algo):
"""
Expand Down
2 changes: 0 additions & 2 deletions splitio/engine/hashfns/legacy.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
"""Legacy hash function module."""
from __future__ import absolute_import, division, print_function, \
unicode_literals


def as_int32(value):
Expand Down
Loading