Skip to content

Commit

Permalink
Remove superfluous checks
Browse files Browse the repository at this point in the history
Signed-off-by: Tim Paine <3105306+timkpaine@users.noreply.github.com>
  • Loading branch information
timkpaine committed May 24, 2024
1 parent a25d3e1 commit e9407ae
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 68 deletions.
4 changes: 0 additions & 4 deletions csp/adapters/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@
_SQLALCHEMY_2 = False

import sqlalchemy as db

_HAS_SQLALCHEMY = True
except (PackageNotFoundError, ValueError, TypeError, ImportError):
raise ModuleNotFoundError("csp's db adapter requires `sqlalchemy`")

Expand Down Expand Up @@ -198,8 +196,6 @@ def __init__(
:param log_query: set to True to see what query was generated to access the data
:param use_raw_user_query: Don't do any alteration to user query, assume it contains all the needed columns and sorting
"""
if not _HAS_SQLALCHEMY:
raise RuntimeError("Could not find SQLAlchemy installation")
self._connection = connection
self._table_name = table_name
self._schema_name = schema_name
Expand Down
40 changes: 16 additions & 24 deletions csp/adapters/kafka.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
from csp.impl.wiring import input_adapter_def, output_adapter_def, status_adapter_def

try:
_HAS_KAFKA_ADAPTER = True
from csp.lib import _kafkaadapterimpl
except ImportError:
raise ImportError("csp's kafka adapter requires the C++ csp extension to be built, but it could not be imported")
Expand Down Expand Up @@ -70,9 +69,6 @@ def __init__(
:param group_id_prefix - ( optional ) when not passing an explicit group_id, a prefix can be supplied that will be use to
prefix the UUID generated for the group_id
"""
if not _HAS_KAFKA_ADAPTER:
raise ModuleNotFoundError("`csp` build does not include kafka C++ adapter")

if group_id is not None and start_offset is not None:
raise ValueError("start_offset is not supported when consuming with group_id")

Expand Down Expand Up @@ -192,23 +188,19 @@ def _create(self, engine, memo):
return _kafkaadapterimpl._kafka_adapter_manager(engine, self._properties)


if _HAS_KAFKA_ADAPTER:
_kafka_input_adapter_def = input_adapter_def(
"kafka_input_adapter",
_kafkaadapterimpl._kafka_input_adapter,
ts["T"],
KafkaAdapterManager,
typ="T",
properties=dict,
)
_kafka_output_adapter_def = output_adapter_def(
"kafka_output_adapter",
_kafkaadapterimpl._kafka_output_adapter,
KafkaAdapterManager,
input=ts["T"],
typ="T",
properties=dict,
)
else:
_kafka_input_adapter_def = None
_kafka_output_adapter_def = None
_kafka_input_adapter_def = input_adapter_def(
"kafka_input_adapter",
_kafkaadapterimpl._kafka_input_adapter,
ts["T"],
KafkaAdapterManager,
typ="T",
properties=dict,
)
_kafka_output_adapter_def = output_adapter_def(
"kafka_output_adapter",
_kafkaadapterimpl._kafka_output_adapter,
KafkaAdapterManager,
input=ts["T"],
typ="T",
properties=dict,
)
10 changes: 3 additions & 7 deletions csp/adapters/parquet.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
from csp.impl.wiring.node import node

try:
_HAS_PARQUET_ADAPTER = True
from csp.lib import _parquetadapterimpl
except ImportError:
raise ImportError("csp's parquet adapter requires the C++ csp extension to be built, but it could not be imported")
Expand Down Expand Up @@ -293,9 +292,6 @@ def _create(self, engine, memo):
return _parquetadapterimpl._parquet_input_adapter_manager(engine, self._properties, self._filenames_gen)


if _HAS_PARQUET_ADAPTER:
_parquet_input_adapter_def = input_adapter_def(
"parquet_adapter", _parquetadapterimpl._parquet_input_adapter, ts["T"], ParquetReader, typ="T", properties=dict
)
else:
_parquet_input_adapter_def = None
_parquet_input_adapter_def = input_adapter_def(
"parquet_adapter", _parquetadapterimpl._parquet_input_adapter, ts["T"], ParquetReader, typ="T", properties=dict
)
4 changes: 0 additions & 4 deletions csp/adapters/slack.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
from slack_sdk.socket_mode.request import SocketModeRequest
from slack_sdk.socket_mode.response import SocketModeResponse
from slack_sdk.web import WebClient

_HAVE_SLACK_SDK = True
except ImportError:
raise ModuleNotFoundError("csp's slack adapter requires `slack-sdk`")

Expand Down Expand Up @@ -55,8 +53,6 @@ def mention_user(userid: str) -> str:

class SlackAdapterManager(AdapterManagerImpl):
def __init__(self, app_token: str, bot_token: str, ssl: Optional[SSLContext] = None):
if not _HAVE_SLACK_SDK:
raise RuntimeError("Could not find slack-sdk installation")
if not app_token.startswith("xapp-") or not bot_token.startswith("xoxb-"):
raise RuntimeError("Slack app token or bot token looks malformed")

Expand Down
49 changes: 20 additions & 29 deletions csp/adapters/websocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
from csp.impl.wiring.delayed_node import DelayedNodeWrapperDef

try:
_HAS_WS_ADAPTER = True
from csp.lib import _websocketadapterimpl
except ImportError:
raise ImportError(
Expand Down Expand Up @@ -406,9 +405,6 @@ def __init__(
headers: Dict[str, str] = None
headers to apply to the request during the handshake
"""
if not _HAS_WS_ADAPTER:
raise ModuleNotFoundError("`csp` build does not include websocket C++ adapter")

assert reconnect_interval >= timedelta(seconds=1)
self._properties = dict(
uri=uri,
Expand Down Expand Up @@ -455,30 +451,25 @@ def _create(self, engine, memo):
return _websocketadapterimpl._websocket_adapter_manager(engine, self._properties)


if _HAS_WS_ADAPTER:
_websocket_input_adapter_def = input_adapter_def(
"websocket_input_adapter",
_websocketadapterimpl._websocket_input_adapter,
ts["T"],
WebsocketAdapterManager,
typ="T",
properties=dict,
)
_websocket_input_adapter_def = input_adapter_def(
"websocket_input_adapter",
_websocketadapterimpl._websocket_input_adapter,
ts["T"],
WebsocketAdapterManager,
typ="T",
properties=dict,
)

_websocket_output_adapter_def = output_adapter_def(
"websocket_output_adapter",
_websocketadapterimpl._websocket_output_adapter,
WebsocketAdapterManager,
input=ts["T"],
)
_websocket_output_adapter_def = output_adapter_def(
"websocket_output_adapter",
_websocketadapterimpl._websocket_output_adapter,
WebsocketAdapterManager,
input=ts["T"],
)

_websocket_header_update_adapter_def = output_adapter_def(
"websocket_header_update_adapter",
_websocketadapterimpl._websocket_header_update_adapter,
WebsocketAdapterManager,
input=ts[List[WebsocketHeaderUpdate]],
)
else:
_websocket_input_adapter_def = None
_websocket_output_adapter_def = None
_websocket_header_update_adapter_def = None
_websocket_header_update_adapter_def = output_adapter_def(
"websocket_header_update_adapter",
_websocketadapterimpl._websocket_header_update_adapter,
WebsocketAdapterManager,
input=ts[List[WebsocketHeaderUpdate]],
)

0 comments on commit e9407ae

Please sign in to comment.