Repository: mercadona/rele
Pull request #91 (2019-08-27 06:57:02)

Remove drf as a dependency
### :tophat: What?

Remove DRF as a project dependency. This is a breaking change.

### :thinking: Why?

Make the project less dependent on django related projects.

### :link: Related issue

#90 



Patch:
diff --git a/Makefile b/Makefile
index 8bd9961..93ba98a 100644
--- a/Makefile
+++ b/Makefile
@@ -5,7 +5,7 @@
 help:
 	@grep '^[a-zA-Z]' $(MAKEFILE_LIST) | sort | awk -F ':.*?## ' 'NF==2 {printf "\033[36m  %-25s\033[0m %s\n", $$1, $$2}'
 
-clean: clean-build clean-pyc
+clean: clean-build clean-pyc clean-tests
 
 clean-build: ## remove build artifacts
 	rm -fr build/
@@ -17,6 +17,10 @@ clean-pyc: ## remove Python file artifacts
 	find . -name '*.pyo' -exec rm -f {} +
 	find . -name '*~' -exec rm -f {} +
 
+clean-tests: ## remove pytest artifacts
+	rm -fr .pytest_cache/
+	rm -fr htmlcov/
+
 lint: ## check style with flake8
 	black . --check --diff
 
diff --git a/rele/client.py b/rele/client.py
index fc82da3..af36101 100644
--- a/rele/client.py
+++ b/rele/client.py
@@ -12,10 +12,20 @@ from rele.middleware import run_middleware_hook
 logger = logging.getLogger(__name__)
 
 USE_EMULATOR = True if os.environ.get("PUBSUB_EMULATOR_HOST") else False
-DEFAULT_ENCODER_PATH = "rest_framework.utils.encoders.JSONEncoder"
+DEFAULT_ENCODER_PATH = "json.JSONEncoder"
 
 
 class Subscriber:
+    """The Subscriber Class.
+
+    For convenience, this class wraps the creation and consumption of a topic
+    subscription.
+
+    :param gc_project_id: string Google Cloud Project ID.
+    :param credentials: string Google Cloud Credentials.
+    :param default_ack_deadline: int Ack Deadline defined in settings
+    """
+
     def __init__(self, gc_project_id, credentials, default_ack_deadline):
         self._gc_project_id = gc_project_id
         self._ack_deadline = default_ack_deadline
@@ -25,6 +35,16 @@ class Subscriber:
             self._client = pubsub_v1.SubscriberClient(credentials=credentials)
 
     def create_subscription(self, subscription, topic):
+        """Handles creating the subscription when it does not exists.
+
+        This makes it easier to deploy a worker and forget about the
+        subscription side of things. The subscription must
+        have a topic to subscribe to. Which means that the topic must be
+        created manually before the worker is started.
+
+        :param subscription: str Subscription name
+        :param topic: str Topic name to subscribe
+        """
         subscription_path = self._client.subscription_path(
             self._gc_project_id, subscription
         )
@@ -38,6 +58,12 @@ class Subscriber:
             )
 
     def consume(self, subscription_name, callback):
+        """Begin listening to topic from the SubscriberClient.
+        
+        :param subscription_name: str Subscription name
+        :param callback: Function which act on a topic message
+        :return: `Future <https://googleapis.github.io/google-cloud-python/latest/pubsub/subscriber/api/futures.html>`_  # noqa
+        """
         subscription_path = self._client.subscription_path(
             self._gc_project_id, subscription_name
         )
diff --git a/requirements/base.txt b/requirements/base.txt
index e57bb2f..e4298b4 100644
--- a/requirements/base.txt
+++ b/requirements/base.txt
@@ -1,4 +1,3 @@
 django
-djangorestframework
 google-cloud-pubsub
 tabulate
diff --git a/setup.py b/setup.py
index 3e776e7..21a6b8c 100644
--- a/setup.py
+++ b/setup.py
@@ -39,12 +39,7 @@ setup(
     url="https://github.com/mercadona/rele",
     packages=find_packages(exclude=("tests",)),
     include_package_data=True,
-    install_requires=[
-        "django",
-        "djangorestframework",
-        "google-cloud-pubsub",
-        "tabulate",
-    ],
+    install_requires=["django", "google-cloud-pubsub", "tabulate"],
     license="Apache Software License 2.0",
     zip_safe=False,
     keywords="rele",


Test patch:
diff --git a/tests/test_config.py b/tests/test_config.py
index 623d85a..e7b551f 100644
--- a/tests/test_config.py
+++ b/tests/test_config.py
@@ -1,5 +1,6 @@
+import json
+
 import pytest
-from rest_framework.utils.encoders import JSONEncoder
 
 from rele.config import load_subscriptions_from_paths, Config
 from rele import sub
@@ -60,4 +61,4 @@ class TestConfig:
         assert config.gc_project_id is None
         assert config.credentials is None
         assert config.middleware == ["rele.contrib.LoggingMiddleware"]
-        assert config.encoder == JSONEncoder
+        assert config.encoder == json.JSONEncoder