Skip to content

Commit

Permalink
fix: typo and remove sentry from dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
ryshu committed Mar 2, 2023
1 parent c8bb3ca commit 8bc2d58
Show file tree
Hide file tree
Showing 14 changed files with 230 additions and 173 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Novu Client (Python)

[![PyPI](https://img.shields.io/pypi/v/novu-python?color=blue)](https://pypi.org/project/novu-python/)
![Tests Status](https://github.com/ryshu/novu-python/actions/workflows/.github/workflows/tests.yml/badge.svg)
[![codecov](https://codecov.io/gh/ryshu/novu-python/branch/main/graph/badge.svg?token=RON7F8QTZX)](https://codecov.io/gh/ryshu/novu-python)
![Tests Status](https://github.com/SpikeeLabs/novu-python/actions/workflows/.github/workflows/tests.yml/badge.svg)
[![codecov](https://codecov.io/gh/SpikeeLabs/novu-python/branch/main/graph/badge.svg?token=RON7F8QTZX)](https://codecov.io/gh/SpikeeLabs/novu-python)
[![pre-commit](https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit&logoColor=white)](https://github.com/pre-commit/pre-commit)
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
[![Checked with mypy](http://www.mypy-lang.org/static/mypy_badge.svg)](http://mypy-lang.org/)
Expand Down
1 change: 1 addition & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
intersphinx_mapping = {
"python": ("https://docs.python.org/dev/", None),
"sphinx": ("https://www.sphinx-doc.org/en/stable/", None),
"requests": ("https://requests.readthedocs.io/en/latest/", None),
}

source_suffix = [".rst", ".md"]
5 changes: 2 additions & 3 deletions novu/api/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
from typing import Optional

import requests
import sentry_sdk

from novu.config import NovuConfig
from novu.helpers import SentryProxy

LOGGER = logging.getLogger(__name__)

Expand Down Expand Up @@ -67,8 +67,7 @@ def handle_request(
if not res.ok:
try:
detail = res.json()
# FIXME: For some reason, coverage doesn't see this line as covered.
sentry_sdk.set_extra("error_details", detail) # pragma: no cover
SentryProxy().set_extra("error_details", detail)
except JSONDecodeError:
pass
res.raise_for_status()
Expand Down
2 changes: 1 addition & 1 deletion novu/api/change.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def list(self, page: Optional[int] = None, limit: Optional[int] = None) -> Pagin
if limit:
payload["limit"] = limit

return PaginatedChangeDto.from_camel_case(self.handle_request("GET", f"{self._change_url}", payload=payload))
return PaginatedChangeDto.from_camel_case(self.handle_request("GET", self._change_url, payload=payload))

def count(self) -> int:
"""Get the number of changes
Expand Down
2 changes: 1 addition & 1 deletion novu/api/integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def create(self, integration: IntegrationDto, check: bool = True) -> Integration
payload = integration.to_camel_case()
payload["check"] = check if check is not None else True

return IntegrationDto.from_camel_case(self.handle_request("POST", f"{self._integration_url}", payload)["data"])
return IntegrationDto.from_camel_case(self.handle_request("POST", self._integration_url, payload)["data"])

def status(self, provider_id: ProviderIdEnum) -> bool:
"""Get webhook support status for a given provider
Expand Down
6 changes: 2 additions & 4 deletions novu/api/layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def list(self, page: Optional[int] = None, limit: Optional[int] = None) -> Pagin
if limit:
payload["pageSize"] = limit

return PaginatedLayoutDto.from_camel_case(self.handle_request("GET", f"{self._layout_url}", payload=payload))
return PaginatedLayoutDto.from_camel_case(self.handle_request("GET", self._layout_url, payload=payload))

def create(self, layout: LayoutDto) -> LayoutDto:
"""Create a layout and return his identifier
Expand All @@ -43,9 +43,7 @@ def create(self, layout: LayoutDto) -> LayoutDto:
Returns:
The created layout identifier
"""
return LayoutDto.from_camel_case(
self.handle_request("POST", f"{self._layout_url}", layout.to_camel_case())["data"]
)
return LayoutDto.from_camel_case(self.handle_request("POST", self._layout_url, layout.to_camel_case())["data"])

def get(self, layout_id: str) -> LayoutDto:
"""Get a layout using ID
Expand Down
4 changes: 2 additions & 2 deletions novu/api/topic.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def list(
if key:
payload["key"] = key

return PaginatedTopicDto.from_camel_case(self.handle_request("GET", f"{self._topic_url}", payload=payload))
return PaginatedTopicDto.from_camel_case(self.handle_request("GET", self._topic_url, payload=payload))

def create(self, key: str, name: str) -> TopicDto:
"""Create a topic
Expand All @@ -50,7 +50,7 @@ def create(self, key: str, name: str) -> TopicDto:
Created topic (without name ?)
"""
return TopicDto.from_camel_case(
self.handle_request("POST", f"{self._topic_url}", TopicDto(key, name).to_camel_case())["data"]
self.handle_request("POST", self._topic_url, TopicDto(key, name).to_camel_case())["data"]
)

def get(self, key: str) -> TopicDto:
Expand Down
20 changes: 10 additions & 10 deletions novu/dto/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,11 @@ class DtoDescriptor(Generic[_C_co]):
on Novu API response.
Example:
>> @dataclasses.dataclass
.. class SubscriberPreferenceDto(CamelCaseDto["SubscriberPreferenceDto"]):
.. template: DtoDescriptor[SubscriberPreferenceTemplateDto] = (
.. DtoDescriptor[SubscriberPreferenceTemplateDto](item_cls=SubscriberPreferenceTemplateDto)
.. )
>>> @dataclasses.dataclass
... class SubscriberPreferenceDto(CamelCaseDto["SubscriberPreferenceDto"]):
... template: DtoDescriptor[SubscriberPreferenceTemplateDto] = (
... DtoDescriptor[SubscriberPreferenceTemplateDto](item_cls=SubscriberPreferenceTemplateDto)
... )
"""

def __init__(self, item_cls: Type[CamelCaseDto]):
Expand All @@ -125,11 +125,11 @@ class DtoIterableDescriptor(Generic[_C_co]):
:meth:`~novu.dto.base.CamelCaseDto.from_camel_case` calls on Novu API response.
Example:
>> @dataclasses.dataclass
.. class PaginatedTopicDto(CamelCaseDto["PaginatedTopicDto"]):
.. data: DtoIterableDescriptor[TopicDto] = DtoIterableDescriptor[TopicDto](
.. default_factory=list, item_cls=TopicDto
.. )
>>> @dataclasses.dataclass
... class PaginatedTopicDto(CamelCaseDto["PaginatedTopicDto"]):
... data: DtoIterableDescriptor[TopicDto] = DtoIterableDescriptor[TopicDto](
... default_factory=list, item_cls=TopicDto
... )
"""

def __init__(self, default_factory, item_cls: Type[_C_co]):
Expand Down
24 changes: 23 additions & 1 deletion novu/helpers.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""This module is used to gather helpers reused through the package."""
import importlib
from typing import Dict


Expand All @@ -7,7 +8,6 @@ class Singleton(type):
Example:
>>> from novu.helpers import Singleton
...
>>> class MySingleton(metaclass=Singleton)
... pass
"""
Expand All @@ -18,3 +18,25 @@ def __call__(cls, *args, **kwargs):
if cls not in cls._instances:
cls._instances[cls] = super().__call__(*args, **kwargs)
return cls._instances[cls]


class SentryProxy(metaclass=Singleton):
"""Simple singleton to proxy all methods of Sentry SDK
This class allows, in the application, to make sentry optional, in terms of installation, without effort.
"""

def __init__(self) -> None:
self.import_module()

def import_module(self):
"""Method to try to load the sentry_sdk module or set it to None"""
try:
self.sentry_sdk = importlib.import_module("sentry_sdk")
except ModuleNotFoundError:
self.sentry_sdk = None

def __getattr__(self, attr):
if self.sentry_sdk:
return getattr(self.sentry_sdk, attr, None)
return lambda *args, **kwargs: None
Loading

0 comments on commit 8bc2d58

Please sign in to comment.