Skip to content

Commit 707db57

Browse files
authored
Feature/formatting (#111)
* added formatting configurations * formatted *.py files using black & isort * added ignore-rev to ignore the formatting commit for better git blame
1 parent fabe9cc commit 707db57

File tree

9 files changed

+518
-265
lines changed

9 files changed

+518
-265
lines changed

.git-blame-ignore-revs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# formatted using black & isort
2+
b2692e213c7ef62882a1b9b7c95affff3246b036

.pre-commit-config.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
repos:
2+
- repo: https://github.com/psf/black
3+
rev: 23.1.0
4+
hooks:
5+
- id: black
6+
- repo: https://github.com/PyCQA/isort
7+
rev: 5.12.0
8+
hooks:
9+
- id: isort

Makefile

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
PRE_COMMIT = pre-commit
2+
PRE_COMMIT_RUN_ARGS = --all-files
3+
PRE_COMMIT_INSTALL_ARGS = --install-hooks
4+
5+
.PHONY: lint
6+
lint:
7+
$(PRE_COMMIT) run $(PRE_COMMIT_RUN_ARGS)
8+
9+
.PHONY: pre-commit-install
10+
pre-commit-install:
11+
$(PRE_COMMIT) install $(PRE_COMMIT_INSTALL_ARGS)

examples/consumer.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import asyncio
2-
from memphis import Memphis, MemphisError, MemphisConnectError, MemphisHeaderError
2+
3+
from memphis import Memphis, MemphisConnectError, MemphisError, MemphisHeaderError
34

45

56
async def main():
@@ -17,11 +18,18 @@ async def msg_handler(msgs, error, context):
1718

1819
try:
1920
memphis = Memphis()
20-
await memphis.connect(host="<memphis-host>", username="<application type username>", connection_token="<broker-token>")
21+
await memphis.connect(
22+
host="<memphis-host>",
23+
username="<application type username>",
24+
connection_token="<broker-token>",
25+
)
2126

2227
consumer = await memphis.consumer(
23-
station_name="<station-name>", consumer_name="<consumer-name>", consumer_group="")
24-
28+
station_name="<station-name>",
29+
consumer_name="<consumer-name>",
30+
consumer_group="",
31+
)
32+
2533
consumer.set_context({"key": "value"})
2634
consumer.consume(msg_handler)
2735
# Keep your main thread alive so the consumer will keep receiving data
@@ -33,5 +41,6 @@ async def msg_handler(msgs, error, context):
3341
finally:
3442
await memphis.close()
3543

36-
if __name__ == '__main__':
44+
45+
if __name__ == "__main__":
3746
asyncio.run(main())

examples/producer.py

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,46 @@
11
import asyncio
2-
from memphis import Memphis, Headers, MemphisError, MemphisConnectError, MemphisHeaderError, MemphisSchemaError
2+
3+
from memphis import (
4+
Headers,
5+
Memphis,
6+
MemphisConnectError,
7+
MemphisError,
8+
MemphisHeaderError,
9+
MemphisSchemaError,
10+
)
311

412

513
async def main():
614
try:
715
memphis = Memphis()
8-
await memphis.connect(host="<memphis-host>", username="<application type username>", connection_token="<broker-token>")
16+
await memphis.connect(
17+
host="<memphis-host>",
18+
username="<application type username>",
19+
connection_token="<broker-token>",
20+
)
921

1022
producer = await memphis.producer(
11-
station_name="<station-name>", producer_name="<producer-name>")
23+
station_name="<station-name>", producer_name="<producer-name>"
24+
)
1225
headers = Headers()
13-
headers.add("key", "value")
26+
headers.add("key", "value")
1427
for i in range(5):
15-
await producer.produce(bytearray('Message #'+str(i)+': Hello world', 'utf-8'), headers=headers) # you can send the message parameter as dict as well
28+
await producer.produce(
29+
bytearray("Message #" + str(i) + ": Hello world", "utf-8"),
30+
headers=headers,
31+
) # you can send the message parameter as dict as well
1632

17-
except (MemphisError, MemphisConnectError, MemphisHeaderError, MemphisSchemaError) as e:
33+
except (
34+
MemphisError,
35+
MemphisConnectError,
36+
MemphisHeaderError,
37+
MemphisSchemaError,
38+
) as e:
1839
print(e)
1940

2041
finally:
2142
await memphis.close()
2243

23-
if __name__ == '__main__':
44+
45+
if __name__ == "__main__":
2446
asyncio.run(main())

memphis/__init__.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,13 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
from memphis.memphis import Memphis, Headers, MemphisError, MemphisConnectError, MemphisSchemaError, MemphisHeaderError
1615
import memphis.retention_types
1716
import memphis.storage_types
17+
from memphis.memphis import (
18+
Headers,
19+
Memphis,
20+
MemphisConnectError,
21+
MemphisError,
22+
MemphisHeaderError,
23+
MemphisSchemaError,
24+
)

0 commit comments

Comments
 (0)