Skip to content

Commit 7180ec4

Browse files
committed
migrated package configurations to use hatch
1 parent 4d25dc9 commit 7180ec4

File tree

7 files changed

+96
-63
lines changed

7 files changed

+96
-63
lines changed

Jenkinsfile

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,29 +8,27 @@ node ("small-ec2-fleet") {
88
try{
99

1010
stage('Deploy to pypi') {
11-
sh 'python3 setup.py sdist'
12-
sh 'pip3 install twine'
11+
sh 'python3 -m pip install hatch twine'
12+
sh 'python3 -m hatch build'
1313
withCredentials([usernamePassword(credentialsId: 'python_sdk', usernameVariable: 'USR', passwordVariable: 'PSW')]) {
14-
sh '/home/ec2-user/.local/bin/twine upload -u $USR -p $PSW dist/*'
14+
sh 'python -m twine upload -u $USR -p $PSW dist/*'
1515
}
1616
}
1717

1818
stage('Checkout to version branch'){
1919
sh """
2020
sudo yum-config-manager --add-repo https://cli.github.com/packages/rpm/gh-cli.repo
2121
sudo yum install gh -y
22-
sed -i -r "s/version=\'[0-9].[0-9].[0-9]/version=\'\$(cat version.conf)/g" setup.py
23-
sed -i -r "s/v[0-9].[0-9].[0-9]/v\$(cat version.conf)/g" setup.py
2422
"""
2523
withCredentials([sshUserPrivateKey(keyFileVariable:'check',credentialsId: 'main-github')]) {
2624
sh """
2725
git reset --hard origin/latest
28-
GIT_SSH_COMMAND='ssh -i $check' git checkout -b \$(cat version.conf)
29-
GIT_SSH_COMMAND='ssh -i $check' git push --set-upstream origin \$(cat version.conf)
26+
GIT_SSH_COMMAND='ssh -i $check' git checkout -B \$(make version)
27+
GIT_SSH_COMMAND='ssh -i $check' git push --set-upstream origin \$(make version)
3028
"""
3129
}
3230
withCredentials([string(credentialsId: 'gh_token', variable: 'GH_TOKEN')]) {
33-
sh(script:"""gh release create \$(cat version.conf) --generate-notes""", returnStdout: true)
31+
sh(script:"""gh release create \$(make version) --generate-notes""", returnStdout: true)
3432
}
3533
}
3634

Makefile

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,22 @@
1-
PRE_COMMIT = pre-commit
1+
PYTHON = python
2+
PRE_COMMIT = $(PYTHON) -m pre_commit
23
PRE_COMMIT_RUN_ARGS = --all-files
34
PRE_COMMIT_INSTALL_ARGS = --install-hooks
45

6+
HATCH = $(PYTHON) -m hatch
7+
HATCH_VERSION =
58
.PHONY: lint
69
lint:
710
$(PRE_COMMIT) run $(PRE_COMMIT_RUN_ARGS)
811

912
.PHONY: pre-commit-install
1013
pre-commit-install:
11-
$(PRE_COMMIT) install $(PRE_COMMIT_INSTALL_ARGS)
14+
$(PRE_COMMIT) install $(PRE_COMMIT_INSTALL_ARGS)
15+
16+
.PHONY: version
17+
version:
18+
@$(HATCH) version
19+
20+
.PHONY: bump_version
21+
bump_version:
22+
$(HATCH) version $(HATCH_VERSION)

memphis/memphis.py

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -631,7 +631,6 @@ async def produce(
631631
except Exception as e:
632632
raise MemphisError(str(e)) from e
633633

634-
635634
async def fetch_messages(
636635
self,
637636
station_name: str,
@@ -643,8 +642,8 @@ async def fetch_messages(
643642
max_msg_deliveries: int = 10,
644643
generate_random_suffix: bool = False,
645644
start_consume_from_sequence: int = 1,
646-
last_messages: int = -1
647-
):
645+
last_messages: int = -1,
646+
):
648647
"""Consume a batch of messages.
649648
Args:.
650649
station_name (str): station name to consume messages from.
@@ -669,7 +668,18 @@ async def fetch_messages(
669668
if consumer_map_key in self.consumers_map:
670669
consumer = self.consumers_map[consumer_map_key]
671670
else:
672-
consumer = await self.consumer(station_name=station_name, consumer_name=consumer_name, consumer_group=consumer_group, batch_size=batch_size, batch_max_time_to_wait_ms=batch_max_time_to_wait_ms, max_ack_time_ms=max_ack_time_ms, max_msg_deliveries=max_msg_deliveries, generate_random_suffix=generate_random_suffix, start_consume_from_sequence=start_consume_from_sequence, last_messages=last_messages)
671+
consumer = await self.consumer(
672+
station_name=station_name,
673+
consumer_name=consumer_name,
674+
consumer_group=consumer_group,
675+
batch_size=batch_size,
676+
batch_max_time_to_wait_ms=batch_max_time_to_wait_ms,
677+
max_ack_time_ms=max_ack_time_ms,
678+
max_msg_deliveries=max_msg_deliveries,
679+
generate_random_suffix=generate_random_suffix,
680+
start_consume_from_sequence=start_consume_from_sequence,
681+
last_messages=last_messages,
682+
)
673683
messages = await consumer.fetch(batch_size)
674684
if messages == None:
675685
messages = []
@@ -1023,7 +1033,6 @@ def default_error_handler(e):
10231033
print("ping exception raised", e)
10241034

10251035

1026-
10271036
class Consumer:
10281037
def __init__(
10291038
self,
@@ -1061,7 +1070,6 @@ def __init__(
10611070
self.dls_callback_func = None
10621071
self.t_dls = asyncio.create_task(self.__consume_dls())
10631072

1064-
10651073
def set_context(self, context):
10661074
"""Set a context (dict) that will be passed to each message handler call."""
10671075
self.context = context
@@ -1112,10 +1120,12 @@ async def __consume_dls(self):
11121120
)
11131121
async for msg in self.consumer_dls.messages:
11141122
index_to_insert = self.dls_current_index
1115-
if index_to_insert>=10000:
1116-
index_to_insert%=10000
1117-
self.dls_messages.insert(index_to_insert, Message(msg, self.connection, self.consumer_group))
1118-
self.dls_current_index+=1
1123+
if index_to_insert >= 10000:
1124+
index_to_insert %= 10000
1125+
self.dls_messages.insert(
1126+
index_to_insert, Message(msg, self.connection, self.consumer_group)
1127+
)
1128+
self.dls_current_index += 1
11191129
if self.dls_callback_func != None:
11201130
await self.dls_callback_func(
11211131
[Message(msg, self.connection, self.consumer_group)],
@@ -1132,7 +1142,7 @@ async def fetch(self, batch_size: int = 10):
11321142
if self.connection.is_connection_active:
11331143
try:
11341144
self.batch_size = batch_size
1135-
if len(self.dls_messages)>0:
1145+
if len(self.dls_messages) > 0:
11361146
if len(self.dls_messages) <= batch_size:
11371147
messages = self.dls_messages
11381148
self.dls_messages = []
@@ -1151,7 +1161,7 @@ async def fetch(self, batch_size: int = 10):
11511161
subject = get_internal_name(self.station_name)
11521162
consumer_group = get_internal_name(self.consumer_group)
11531163
self.psub = await self.connection.broker_connection.pull_subscribe(
1154-
subject + ".final", durable=durableName
1164+
subject + ".final", durable=durableName
11551165
)
11561166
msgs = await self.psub.fetch(batch_size)
11571167
for msg in msgs:
@@ -1217,9 +1227,8 @@ async def ack(self):
12171227
await self.message.ack()
12181228
except Exception as e:
12191229
if (
1220-
"$memphis_pm_id"
1221-
in self.message.headers and "$memphis_pm_sequence"
1222-
in self.message.headers
1230+
"$memphis_pm_id" in self.message.headers
1231+
and "$memphis_pm_sequence" in self.message.headers
12231232
):
12241233
try:
12251234
msg = {

pyproject.toml

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,55 @@
1+
[build-system]
2+
requires = ["hatchling"]
3+
build-backend = "hatchling.build"
4+
5+
[project]
6+
name = "memphis-py"
7+
dynamic = ["version"]
8+
description = "A powerful messaging platform for modern developers"
9+
readme = "README.md"
10+
license = "Apache-2.0"
11+
authors = [
12+
{ name = "Memphis.dev", email = "team@memphis.dev" },
13+
]
14+
keywords = [
15+
"data",
16+
"devtool",
17+
"message broker",
18+
"streaming",
19+
]
20+
classifiers = [
21+
"Development Status :: 4 - Beta",
22+
"Intended Audience :: Developers",
23+
"License :: OSI Approved :: GNU General Public License (GPL)",
24+
"Programming Language :: Python :: 3.7",
25+
"Programming Language :: Python :: 3.8",
26+
"Programming Language :: Python :: 3.9",
27+
"Programming Language :: Python :: 3.10",
28+
"Programming Language :: Python :: 3.11",
29+
"Programming Language :: Python :: 3.12",
30+
"Topic :: Software Development",
31+
]
32+
dependencies = [
33+
"asyncio",
34+
"graphql-core",
35+
"jsonschema",
36+
"nats-py",
37+
"protobuf",
38+
]
39+
40+
[project.urls]
41+
Homepage = "https://github.com/memphisdev/memphis.py"
42+
43+
[tool.hatch.version]
44+
source = "regex"
45+
path = "version.conf"
46+
pattern = ''' *([ \'"])?v?(?P<version>.+?)\1'''
47+
# (?i)^(__version__|VERSION) *= *([\'"])v?(?P<version>.+?)\2
48+
[tool.hatch.build.targets.sdist]
49+
include = [
50+
"/memphis",
51+
]
52+
153
[tool.isort]
254
profile = "black"
355
known_third_party = ["memphis"]

setup.cfg

Lines changed: 0 additions & 2 deletions
This file was deleted.

setup.py

Lines changed: 0 additions & 35 deletions
This file was deleted.

version.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.3.2
1+
"0.3.2"

0 commit comments

Comments
 (0)