Skip to content

Commit

Permalink
remove all current deprecations (#139)
Browse files Browse the repository at this point in the history
* remove all currently deprecated classes, methods, arguments, and tests
* also update semver usage to remove calls to deprecated functions and classes
  • Loading branch information
apache-hb authored Oct 27, 2020
1 parent 43b4c31 commit 58b5bc3
Show file tree
Hide file tree
Showing 16 changed files with 43 additions and 240 deletions.
38 changes: 3 additions & 35 deletions ldclient/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import threading
import traceback

from ldclient.config import Config as Config
from ldclient.config import Config, HTTPConfig
from ldclient.diagnostics import create_diagnostic_id, _DiagnosticAccumulator
from ldclient.event_processor import DefaultEventProcessor
from ldclient.feature_requester import FeatureRequesterImpl
Expand Down Expand Up @@ -69,24 +69,15 @@ class LDClient:
Client instances are thread-safe.
"""
def __init__(self, sdk_key: str=None, config: Config=None, start_wait: float=5):
def __init__(self, config: Config, start_wait: float=5):
"""Constructs a new LDClient instance.
:param sdk_key: the SDK key for your LaunchDarkly environment
:param config: optional custom configuration
:param start_wait: the number of seconds to wait for a successful connection to LaunchDarkly
"""
check_uwsgi()

if config is not None and config.sdk_key is not None and sdk_key is not None:
raise Exception("LaunchDarkly client init received both sdk_key and config with sdk_key. "
"Only one of either is expected")

if sdk_key is not None:
log.warning("Deprecated sdk_key argument was passed to init. Use config object instead.")
self._config = Config(sdk_key=sdk_key)
else:
self._config = config or Config.default()
self._config = config
self._config._validate()

self._event_processor = None
Expand Down Expand Up @@ -237,14 +228,6 @@ def flush(self):
return
return self._event_processor.flush()

def toggle(self, key, user, default):
"""Deprecated synonym for :func:`variation()`.
.. deprecated:: 2.0.0
"""
log.warning("Deprecated method: toggle() called. Use variation() instead.")
return self.variation(key, user, default)

def variation(self, key: str, user: dict, default: Any) -> Any:
"""Determines the variation of a feature flag for a user.
Expand Down Expand Up @@ -325,21 +308,6 @@ def _evaluate_internal(self, key, user, default, event_factory):
self._send_event(event_factory.new_default_event(flag, user, default, reason))
return EvaluationDetail(default, None, reason)

def all_flags(self, user: dict) -> Optional[dict]:
"""Returns all feature flag values for the given user.
This method is deprecated - please use :func:`all_flags_state()` instead. Current versions of the
client-side SDK will not generate analytics events correctly if you pass the result of ``all_flags``.
:param user: the end user requesting the feature flags
:return: a dictionary of feature flag keys to values; returns None if the client is offline,
has not been initialized, or the user is None or has no key
"""
state = self.all_flags_state(user)
if not state.valid:
return None
return state.to_values_map()

def all_flags_state(self, user: dict, **kwargs) -> FeatureFlagsState:
"""Returns an object that encapsulates the state of all feature flags for a given user,
including the flag values and also metadata that can be used on the front end. See the
Expand Down
52 changes: 2 additions & 50 deletions ldclient/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@ class HTTPConfig:
This class groups together HTTP/HTTPS-related configuration properties that rarely need to be changed.
If you need to set these, construct an `HTTPConfig` instance and pass it as the `http` parameter when
you construct the main :class:`Config` for the SDK client.
For some of these properties, :class:`Config` also has properties with the same names; the latter are
deprecated and will be removed in the future, and if you specify an `HTTPConfig` instance then the
corresponding `Config` properties will be ignored.
"""
def __init__(self,
connect_timeout: float=10,
Expand Down Expand Up @@ -89,18 +85,15 @@ def __init__(self,
sdk_key: Optional[str]=None,
base_uri: str='https://app.launchdarkly.com',
events_uri: str='https://events.launchdarkly.com',
connect_timeout=10, # deprecated
read_timeout=15, # deprecated
events_max_pending: int=10000,
flush_interval: float=5,
stream_uri: str='https://stream.launchdarkly.com',
stream: bool=True,
initial_reconnect_delay: float=1,
verify_ssl=True, # deprecated
defaults: dict={},
send_events: Optional[bool]=None,
events_enabled: bool=True,
update_processor_class: Callable[[str, 'Config', FeatureStore], UpdateProcessor]=None,
update_processor_class: Optional[Callable[[str, 'Config', FeatureStore], UpdateProcessor]]=None,
poll_interval: float=30,
use_ldd: bool=False,
feature_store: Optional[FeatureStore]=None,
Expand All @@ -112,22 +105,17 @@ def __init__(self,
user_keys_capacity: int=1000,
user_keys_flush_interval: float=300,
inline_users_in_events: bool=False,
http_proxy=None, # deprecated
diagnostic_opt_out: bool=False,
diagnostic_recording_interval: int=900,
wrapper_name: Optional[str]=None,
wrapper_version: Optional[str]=None,
http: Optional[HTTPConfig]=None):
http: HTTPConfig=HTTPConfig()):
"""
:param sdk_key: The SDK key for your LaunchDarkly account.
:param base_uri: The base URL for the LaunchDarkly server. Most users should use the default
value.
:param events_uri: The URL for the LaunchDarkly events server. Most users should use the
default value.
:param connect_timeout: Deprecated; use `http` instead and specify the `connect_timeout` as
part of :class:`HTTPConfig`.
:param read_timeout: Deprecated; use `http` instead and specify the `read_timeout` as
part of :class:`HTTPConfig`.
:param events_max_pending: The capacity of the events buffer. The client buffers up to this many
events in memory before flushing. If the capacity is exceeded before the buffer is flushed, events
will be discarded.
Expand All @@ -141,8 +129,6 @@ def __init__(self,
connection. The streaming service uses a backoff algorithm (with jitter) every time the connection needs
to be reestablished. The delay for the first reconnection will start near this value, and then
increase exponentially for any subsequent connection failures.
:param verify_ssl: Deprecated; use `http` instead and specify `disable_ssl_verification` as
part of :class:`HTTPConfig` if you want to turn off SSL verification (not recommended).
:param send_events: Whether or not to send events back to LaunchDarkly. This differs from
`offline` in that it affects only the sending of client-side events, not streaming or polling for
events from the server. By default, events will be sent.
Expand Down Expand Up @@ -171,8 +157,6 @@ def __init__(self,
:param event_processor_class: A factory for an EventProcessor implementation taking the config
:param update_processor_class: A factory for an UpdateProcessor implementation taking the sdk key,
config, and FeatureStore implementation
:param http_proxy: Deprecated; use `http` instead and specify the `http_proxy` as part of
:class:`HTTPConfig`.
:param diagnostic_opt_out: Unless this field is set to True, the client will send
some diagnostics data to the LaunchDarkly servers in order to assist in the development of future SDK
improvements. These diagnostics consist of an initial payload containing some details of SDK in use,
Expand Down Expand Up @@ -203,11 +187,8 @@ def __init__(self,
self.__feature_store = InMemoryFeatureStore() if not feature_store else feature_store
self.__event_processor_class = event_processor_class
self.__feature_requester_class = feature_requester_class
self.__connect_timeout = connect_timeout
self.__read_timeout = read_timeout
self.__events_max_pending = events_max_pending
self.__flush_interval = flush_interval
self.__verify_ssl = verify_ssl
self.__defaults = defaults
if offline is True:
send_events = False
Expand All @@ -218,7 +199,6 @@ def __init__(self,
self.__user_keys_capacity = user_keys_capacity
self.__user_keys_flush_interval = user_keys_flush_interval
self.__inline_users_in_events = inline_users_in_events
self.__http_proxy = http_proxy
self.__diagnostic_opt_out = diagnostic_opt_out
self.__diagnostic_recording_interval = max(diagnostic_recording_interval, 60)
self.__wrapper_name = wrapper_name
Expand All @@ -239,14 +219,11 @@ def copy_with_new_sdk_key(self, new_sdk_key: str) -> 'Config':
return Config(sdk_key=new_sdk_key,
base_uri=self.__base_uri,
events_uri=self.__events_uri,
connect_timeout=self.__connect_timeout,
read_timeout=self.__read_timeout,
events_max_pending=self.__events_max_pending,
flush_interval=self.__flush_interval,
stream_uri=self.__stream_uri,
stream=self.__stream,
initial_reconnect_delay=self.__initial_reconnect_delay,
verify_ssl=self.__verify_ssl,
defaults=self.__defaults,
send_events=self.__send_events,
update_processor_class=self.__update_processor_class,
Expand Down Expand Up @@ -335,14 +312,6 @@ def event_processor_class(self) -> Optional[Callable[['Config'], EventProcessor]
def feature_requester_class(self) -> Callable:
return self.__feature_requester_class

@property
def connect_timeout(self) -> float:
return self.__connect_timeout

@property
def read_timeout(self) -> float:
return self.__read_timeout

@property
def events_enabled(self) -> bool:
return self.__send_events
Expand All @@ -359,10 +328,6 @@ def events_max_pending(self) -> int:
def flush_interval(self) -> float:
return self.__flush_interval

@property
def verify_ssl(self) -> bool:
return self.__verify_ssl

@property
def private_attribute_names(self) -> list:
return list(self.__private_attribute_names)
Expand All @@ -387,10 +352,6 @@ def user_keys_flush_interval(self) -> float:
def inline_users_in_events(self) -> bool:
return self.__inline_users_in_events

@property
def http_proxy(self):
return self.__http_proxy

@property
def diagnostic_opt_out(self) -> bool:
return self.__diagnostic_opt_out
Expand All @@ -409,15 +370,6 @@ def wrapper_version(self) -> Optional[str]:

@property
def http(self) -> HTTPConfig:
if self.__http is None:
return HTTPConfig(
connect_timeout=self.__connect_timeout,
read_timeout=self.__read_timeout,
http_proxy=self.__http_proxy,
ca_certs=None,
cert_file=None,
disable_ssl_verification=not self.__verify_ssl
)
return self.__http

def _validate(self):
Expand Down
6 changes: 3 additions & 3 deletions ldclient/diagnostics.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,10 @@ def _create_diagnostic_config_object(config):
'customEventsURI': config.events_uri != default_config.events_uri,
'customStreamURI': config.stream_base_uri != default_config.stream_base_uri,
'eventsCapacity': config.events_max_pending,
'connectTimeoutMillis': config.connect_timeout * 1000,
'socketTimeoutMillis': config.read_timeout * 1000,
'connectTimeoutMillis': config.http.connect_timeout * 1000,
'socketTimeoutMillis': config.http.read_timeout * 1000,
'eventsFlushIntervalMillis': config.flush_interval * 1000,
'usingProxy': config.http_proxy is not None,
'usingProxy': config.http.http_proxy is not None,
'streamingDisabled': not config.stream,
'usingRelayDaemon': config.use_ldd,
'allAttributesPrivate': config.all_attributes_private,
Expand Down
2 changes: 1 addition & 1 deletion ldclient/event_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ def _post_events_with_retry(
uri,
headers=hdrs,
body=body,
timeout=urllib3.Timeout(connect=config.connect_timeout, read=config.read_timeout),
timeout=urllib3.Timeout(connect=config.http.connect_timeout, read=config.http.read_timeout),
retries=0
)
if r.status < 300:
Expand Down
2 changes: 1 addition & 1 deletion ldclient/feature_requester.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def get_all_data(self):
hdrs['If-None-Match'] = cache_entry.etag
r = self._http.request('GET', uri,
headers=hdrs,
timeout=urllib3.Timeout(connect=self._config.connect_timeout, read=self._config.read_timeout),
timeout=urllib3.Timeout(connect=self._config.http.connect_timeout, read=self._config.http.read_timeout),
retries=1)
throw_if_unsuccessful_response(r)
if r.status == 304 and cache_entry is not None:
Expand Down
25 changes: 0 additions & 25 deletions ldclient/file_data_source.py

This file was deleted.

31 changes: 0 additions & 31 deletions ldclient/memoized_value.py

This file was deleted.

14 changes: 7 additions & 7 deletions ldclient/operators.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import logging
import re
import semver
from semver import VersionInfo
import sys
from datetime import tzinfo, timedelta, datetime
from collections import defaultdict
Expand Down Expand Up @@ -67,17 +67,17 @@ def _time_operator(u, c, fn):

def _parse_semver(input):
try:
semver.VersionInfo.parse(input)
VersionInfo.parse(input)
return input
except ValueError as e:
try:
input = _add_zero_version_component(input)
semver.VersionInfo.parse(input)
VersionInfo.parse(input)
return input
except ValueError as e:
try:
input = _add_zero_version_component(input)
semver.VersionInfo.parse(input)
VersionInfo.parse(input)
return input
except ValueError as e:
return None
Expand Down Expand Up @@ -143,15 +143,15 @@ def _after(u, c):


def _semver_equal(u, c):
return _semver_operator(u, c, lambda u, c: semver.compare(u, c) == 0)
return _semver_operator(u, c, lambda u, c: VersionInfo.parse(u).compare(c) == 0)


def _semver_less_than(u, c):
return _semver_operator(u, c, lambda u, c: semver.compare(u, c) < 0)
return _semver_operator(u, c, lambda u, c: VersionInfo.parse(u).compare(c) < 0)


def _semver_greater_than(u, c):
return _semver_operator(u, c, lambda u, c: semver.compare(u, c) > 0)
return _semver_operator(u, c, lambda u, c: VersionInfo.parse(u).compare(c) > 0)


_ZERO = timedelta(0)
Expand Down
Loading

0 comments on commit 58b5bc3

Please sign in to comment.