cloudtoolbox 0.5.0__tar.gz → 0.6.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (23) hide show
  1. {cloudtoolbox-0.5.0 → cloudtoolbox-0.6.0}/PKG-INFO +3 -2
  2. cloudtoolbox-0.6.0/cloud/google/pubsub.py +49 -0
  3. {cloudtoolbox-0.5.0 → cloudtoolbox-0.6.0}/cloudtoolbox.egg-info/PKG-INFO +3 -2
  4. {cloudtoolbox-0.5.0 → cloudtoolbox-0.6.0}/pyproject.toml +1 -1
  5. {cloudtoolbox-0.5.0 → cloudtoolbox-0.6.0}/tests/test_factory.py +13 -0
  6. cloudtoolbox-0.5.0/cloud/google/pubsub.py +0 -27
  7. {cloudtoolbox-0.5.0 → cloudtoolbox-0.6.0}/LICENSE +0 -0
  8. {cloudtoolbox-0.5.0 → cloudtoolbox-0.6.0}/README.md +0 -0
  9. {cloudtoolbox-0.5.0 → cloudtoolbox-0.6.0}/cloud/__init__.py +0 -0
  10. {cloudtoolbox-0.5.0 → cloudtoolbox-0.6.0}/cloud/amazon/__init__.py +0 -0
  11. {cloudtoolbox-0.5.0 → cloudtoolbox-0.6.0}/cloud/amazon/helpers.py +0 -0
  12. {cloudtoolbox-0.5.0 → cloudtoolbox-0.6.0}/cloud/amazon/s3.py +0 -0
  13. {cloudtoolbox-0.5.0 → cloudtoolbox-0.6.0}/cloud/amazon/sns.py +0 -0
  14. {cloudtoolbox-0.5.0 → cloudtoolbox-0.6.0}/cloud/amazon/sqs.py +0 -0
  15. {cloudtoolbox-0.5.0 → cloudtoolbox-0.6.0}/cloud/factory.py +0 -0
  16. {cloudtoolbox-0.5.0 → cloudtoolbox-0.6.0}/cloud/google/__init__.py +0 -0
  17. {cloudtoolbox-0.5.0 → cloudtoolbox-0.6.0}/cloud/google/storage.py +0 -0
  18. {cloudtoolbox-0.5.0 → cloudtoolbox-0.6.0}/cloud/protocols.py +0 -0
  19. {cloudtoolbox-0.5.0 → cloudtoolbox-0.6.0}/cloudtoolbox.egg-info/SOURCES.txt +0 -0
  20. {cloudtoolbox-0.5.0 → cloudtoolbox-0.6.0}/cloudtoolbox.egg-info/dependency_links.txt +0 -0
  21. {cloudtoolbox-0.5.0 → cloudtoolbox-0.6.0}/cloudtoolbox.egg-info/requires.txt +0 -0
  22. {cloudtoolbox-0.5.0 → cloudtoolbox-0.6.0}/cloudtoolbox.egg-info/top_level.txt +0 -0
  23. {cloudtoolbox-0.5.0 → cloudtoolbox-0.6.0}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.4
2
2
  Name: cloudtoolbox
3
- Version: 0.5.0
3
+ Version: 0.6.0
4
4
  Summary: Toolbox for the cloud.
5
5
  Author-email: Dotz Developers <devs-dotz@dotz.com>
6
6
  Project-URL: Repository, https://github.com/DotzInc/cloud-toolbox
@@ -28,6 +28,7 @@ Provides-Extra: all
28
28
  Requires-Dist: boto3; extra == "all"
29
29
  Requires-Dist: google-cloud-pubsub; extra == "all"
30
30
  Requires-Dist: google-cloud-storage; extra == "all"
31
+ Dynamic: license-file
31
32
 
32
33
  # Cloud Toolbox
33
34
 
@@ -0,0 +1,49 @@
1
+ import os
2
+ from threading import Lock
3
+ from typing import Any, Dict, Hashable, Mapping, Optional
4
+
5
+ from google.cloud import pubsub_v1
6
+
7
+
8
+ class Publisher:
9
+ _clients: Dict[Hashable, pubsub_v1.PublisherClient] = {}
10
+ _lock = Lock()
11
+
12
+ def __init__(self, *args: Any, **kwargs: Any) -> None:
13
+ self.client = self._shared_client(*args, **kwargs)
14
+
15
+ @classmethod
16
+ def _shared_client(cls, *args: Any, **kwargs: Any) -> pubsub_v1.PublisherClient:
17
+ try:
18
+ key = (os.getpid(), args, frozenset(kwargs.items()))
19
+ hash(key)
20
+ except TypeError:
21
+ return pubsub_v1.PublisherClient(*args, **kwargs)
22
+
23
+ client = cls._clients.get(key)
24
+ if client is None:
25
+ with cls._lock:
26
+ client = cls._clients.get(key)
27
+ if client is None:
28
+ client = pubsub_v1.PublisherClient(*args, **kwargs)
29
+ cls._clients[key] = client
30
+ return client
31
+
32
+ def publish(
33
+ self,
34
+ recipient: str,
35
+ message: str,
36
+ /,
37
+ *,
38
+ group: str = "",
39
+ attrs: Optional[Mapping[str, Any]] = None,
40
+ ) -> str:
41
+ kwargs = attrs or {}
42
+ future = self.client.publish(recipient, data=message.encode(), ordering_key=group, **kwargs)
43
+ return future.result()
44
+
45
+
46
+ class OrderedPublisher(Publisher):
47
+ def __init__(self, *args: Any, **kwargs: Any) -> None:
48
+ opts = pubsub_v1.types.PublisherOptions(enable_message_ordering=True)
49
+ super().__init__(*args, publisher_options=opts, **kwargs)
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.4
2
2
  Name: cloudtoolbox
3
- Version: 0.5.0
3
+ Version: 0.6.0
4
4
  Summary: Toolbox for the cloud.
5
5
  Author-email: Dotz Developers <devs-dotz@dotz.com>
6
6
  Project-URL: Repository, https://github.com/DotzInc/cloud-toolbox
@@ -28,6 +28,7 @@ Provides-Extra: all
28
28
  Requires-Dist: boto3; extra == "all"
29
29
  Requires-Dist: google-cloud-pubsub; extra == "all"
30
30
  Requires-Dist: google-cloud-storage; extra == "all"
31
+ Dynamic: license-file
31
32
 
32
33
  # Cloud Toolbox
33
34
 
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "cloudtoolbox"
7
- version = "0.5.0"
7
+ version = "0.6.0"
8
8
  description = "Toolbox for the cloud."
9
9
  readme = { file = "README.md", content-type = "text/markdown" }
10
10
  authors = [{ name = "Dotz Developers", email = "devs-dotz@dotz.com" }]
@@ -101,6 +101,19 @@ class TestStorageURLSigner(unittest.TestCase):
101
101
 
102
102
 
103
103
  class TestMessagePublisherFactory(unittest.TestCase):
104
+ def setUp(self):
105
+ pubsub.Publisher._clients.clear()
106
+
107
+ def tearDown(self):
108
+ pubsub.Publisher._clients.clear()
109
+
110
+ @mock.patch("google.cloud.pubsub_v1.PublisherClient")
111
+ def test_google_publisher_shares_client(self, client):
112
+ Publisher = factory.message_publisher(pubsub.Publisher)
113
+
114
+ self.assertIs(Publisher().client, Publisher().client)
115
+ client.assert_called_once_with()
116
+
104
117
  @mock.patch("google.cloud.pubsub_v1.PublisherClient")
105
118
  def test_google_publisher(self, _):
106
119
  Publisher = factory.message_publisher(pubsub.Publisher)
@@ -1,27 +0,0 @@
1
- from typing import Any, Mapping, Optional
2
-
3
- from google.cloud import pubsub_v1
4
-
5
-
6
- class Publisher:
7
- def __init__(self, *args: Any, **kwargs: Any) -> None:
8
- self.client = pubsub_v1.PublisherClient(*args, **kwargs)
9
-
10
- def publish(
11
- self,
12
- recipient: str,
13
- message: str,
14
- /,
15
- *,
16
- group: str = "",
17
- attrs: Optional[Mapping[str, Any]] = None,
18
- ) -> str:
19
- kwargs = attrs or {}
20
- future = self.client.publish(recipient, data=message.encode(), ordering_key=group, **kwargs)
21
- return future.result()
22
-
23
-
24
- class OrderedPublisher(Publisher):
25
- def __init__(self, *args: Any, **kwargs: Any) -> None:
26
- opts = pubsub_v1.types.PublisherOptions(enable_message_ordering=True)
27
- super().__init__(*args, publisher_options=opts, **kwargs)
File without changes
File without changes
File without changes