Skip to content

Commit 9bae585

Browse files
authored
Merge pull request #4 from TaskarCenterAtUW/develop
v0.0.7 version to Master
2 parents 652e249 + ae74d5f commit 9bae585

74 files changed

Lines changed: 734 additions & 411 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/deploy_to_test.yml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ jobs:
2020
with:
2121
python-version: '3.10'
2222

23-
- name: Install Requirements
24-
run: pip install -r requirements.txt
23+
- name: Installing git
24+
run: pip install gitpython
2525

2626
- name: Generating version file
2727
run: python freeze_version.py
@@ -32,9 +32,9 @@ jobs:
3232
- name: Building Package
3333
run: python setup.py bdist_wheel
3434

35-
# - name: Publish package
36-
# uses: pypa/gh-action-pypi-publish@release/v1
37-
# with:
38-
# skip_existing: true
39-
# password: ${{ secrets.PYPI_API_TOKEN }}
40-
# repository_url: https://test.pypi.org/legacy/
35+
- name: Publish package
36+
uses: pypa/gh-action-pypi-publish@release/v1
37+
with:
38+
skip_existing: true
39+
password: ${{ secrets.PYPI_API_TOKEN }}
40+
repository_url: https://test.pypi.org/legacy/

.github/workflows/publish_to_pypi.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,6 @@ jobs:
4141
- name: Compare local and remote version with dpkg
4242
run: dpkg --compare-versions ${{env.localVersion}} "gt" ${{env.remoteVersion}}
4343

44-
- name: Install Requirements
45-
run: pip install -r requirements.txt
4644

4745
- name: Setup python wheel
4846
run: pip install wheel

CHANGELOG.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,30 @@
11
# Change log
22

3+
### 0.0.7
4+
- Fixed configuration issues
5+
- Fixed all the review comments
6+
- Refactor code
7+
- Removed unused code
8+
- Added local dev env using TDEI-local-server Package
9+
- Added local env support to -
10+
- Logger
11+
- Queue
12+
- Topic
13+
- Storage
14+
15+
### 0.0.6
16+
- Added get_remote_url function in FileEntity class which will return the uploaded file url
17+
18+
### 0.0.5
19+
- Fixed Storage Blob stream
20+
21+
### 0.0.4
22+
- Fixed threading
23+
24+
### 0.0.3
25+
- Removed blocking call from topic subscription
26+
- Added TODOs and FIXMEs
27+
328
### 0.0.2
429
- Added filtered exception handling
530
- Removed unused packages

README.md

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ All the cloud connections are initialized with `initialize` function of core whi
2424
Eg.
2525
```python
2626
from python_ms_core import Core
27-
Core.initialize()
27+
core = Core() or Core(config='Local')
2828
```
2929
The method analyzes the `.env` variables and does a health check on what components are available
3030

@@ -56,12 +56,13 @@ This file will have to be generated or shared offline as per the developer requi
5656
Offers helper classes to help log the information. It is also used to record the audit messages
5757
as well as the analytics information required.
5858

59-
Use `Core.get_logger()`
59+
Use `core.get_logger()`
6060
Eg.
6161
```python
6262
from python_ms_core import Core
6363

64-
logger = Core.get_logger()
64+
core = Core()
65+
logger = core.get_logger()
6566

6667
# Record a metric
6768
logger.record_metric(name='test', value='test') # Metric and value
@@ -74,7 +75,8 @@ Eg.
7475
```python
7576
from python_ms_core import Core
7677

77-
logger = Core.get_logger()
78+
core = Core()
79+
logger = core.get_logger()
7880

7981
# Record a metric
8082
logger.debug('Debug Message')
@@ -102,15 +104,12 @@ The configuration required by Queue and Topic is similar and will be handled via
102104

103105
Topic can be accessed by the core method `get_topic`. This method takes two parameters
104106
1. topic name (required)
105-
2. callback function where messages will be received
106107

107108
```python
108109
from python_ms_core import Core
109110

110-
def callback(instance):
111-
print(instance.get_messages())
112-
113-
topic = Core.get_topic(topic_name='topicName', callback=callback)
111+
core = Core()
112+
topic = core.get_topic(topic_name='topicName')
114113

115114
```
116115

@@ -121,7 +120,8 @@ Once the topic object is got, use `publish` method to publish the message to top
121120
from python_ms_core import Core
122121
from python_ms_core.core.queue.models.queue_message import QueueMessage
123122

124-
topic = Core.get_topic(topic_name='topicName')
123+
core = Core()
124+
topic = core.get_topic(topic_name='topicName')
125125
topic.publish(QueueMessage.data_from(
126126
{
127127
'message': 'Test message'
@@ -139,18 +139,26 @@ It takes one parameter
139139
```python
140140
from python_ms_core import Core
141141

142-
topic = Core.get_topic(topic_name='topicName')
143-
msg = topic.subscribe(subscription='subscriptionName')
144-
print(msg)
142+
core = Core()
143+
topic_object = topic = Core.get_topic(topic_name='topicName')
144+
145+
def process(message):
146+
print(f'Message Received: {message}')
147+
148+
try:
149+
topic_object.subscribe(subscription='subscriptionName')
150+
except Exception as e:
151+
print(e)
145152
```
146153

147154
### Storage
148155
For all the azure blobs and other storages, storage components will offer simple ways to upload/download and read the existing data.
149156
```python
150157
from python_ms_core import Core
151158

159+
core = Core()
152160
# Create storage client
153-
azure_client = Core.get_storage_client()
161+
azure_client = core.get_storage_client()
154162

155163
# Get a container in the storage client
156164
container = azure_client.get_container(container_name='tdei-storage-test')
@@ -168,7 +176,8 @@ File upload is done only through read stream.
168176
from python_ms_core import Core
169177
from io import BytesIO, StringIO
170178

171-
azure_client = Core.get_storage_client()
179+
core = Core()
180+
azure_client = core.get_storage_client()
172181
container = azure_client.get_container(container_name='tdei-storage-test')
173182
# Create an instance of `AzureFileEntity` with name and mime-type
174183
txt = 'foo\nbar\nbaz'

freeze_version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
build_date = date.today().strftime('%Y-%m-%d')
1313

14-
version = '0.0.2'
14+
version = '0.0.7'
1515

1616
with open(version_file_path, 'w+') as version_file:
1717
version_file.write("version = '{}'\n".format(version))

requirements.txt

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,20 @@ azure-common==1.1.28
22
azure-core==1.26.1
33
azure-servicebus==7.0.0
44
azure-storage-blob==12.14.1
5+
certifi==2022.12.7
6+
cffi==1.15.1
7+
charset-normalizer==2.1.1
8+
cryptography==39.0.0
9+
idna==3.4
10+
isodate==0.6.1
11+
msrest==0.7.1
12+
oauthlib==3.2.2
13+
pycparser==2.21
514
python-dotenv==0.21.0
615
requests==2.28.1
7-
GitPython==3.1.29
16+
requests-oauthlib==1.3.1
17+
six==1.16.0
18+
typing_extensions==4.4.0
19+
uamqp==1.6.3
20+
urllib3==1.26.14
21+
pika==1.3.1

src/example.py

Lines changed: 47 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,71 +1,79 @@
11
# Testing code
2-
32
import sys
3+
import os
4+
import time
45
import uuid
6+
import random
57
import datetime
68
from io import BytesIO, StringIO
7-
import time
89

910
from python_ms_core import Core
10-
from python_ms_core.core.queue.providers import azure_queue_config
1111
from python_ms_core.core.queue.models.queue_message import QueueMessage
1212

13-
Core.initialize()
13+
core = Core(config='Local')
1414
print('Hello')
1515

16-
topic = 'gtfs-flex-upload'
16+
topic = 'gtfspathways'
1717
subscription = 'upload-validation-processor-test'
1818
some_other_sub = 'usdufs'
1919

20-
topic_config = azure_queue_config.AzureQueueConfig()
2120

22-
azure_client = Core.get_storage_client()
21+
def publish_messages(topic_name):
22+
topic_object = core.get_topic(topic_name=topic_name)
23+
queue_message = QueueMessage.data_from({
24+
'message': str(uuid.uuid4().hex),
25+
'data': {'a': random.randint(0, 1000)}
26+
})
27+
topic_object.publish(data=queue_message)
28+
print('Message Published')
29+
30+
31+
def subscribe(topic_name, subscription_name):
32+
def process(message):
33+
print(f'Message Received: {message}')
34+
35+
topic_object = core.get_topic(topic_name=topic_name)
36+
try:
37+
topic_object.subscribe(subscription=subscription_name, callback=process)
38+
except Exception as e:
39+
print(e)
2340

24-
container = azure_client.get_container(container_name='tdei-storage-test')
41+
42+
subscribe(topic, subscription)
43+
44+
azure_client = core.get_storage_client()
45+
46+
container = azure_client.get_container(container_name='gtfspathways')
2547

2648
list_of_files = container.list_files()
27-
for single in list_of_files:
28-
print(single.name)
29-
firstFile = list_of_files[2]
30-
# print(firstFile.name+'<><>')
31-
file_content = firstFile.get_body_text()
49+
if len(list_of_files) > 0:
50+
for single in list_of_files:
51+
print(single.path)
52+
firstFile = list_of_files[0]
53+
# print(firstFile.name+'<><>')
54+
file_content = firstFile.get_body_text()
3255

3356
# Creating a text stream
3457
txt = 'foo\nbar\nbaz'
3558
file_like_io = StringIO(txt)
3659
basename = 'sample-file'
3760
suffix = datetime.datetime.now().strftime("%y%m%d_%H%M%S")
3861
filename = '_'.join([basename, suffix])
39-
test_file = container.create_file(f'{filename}.txt', 'text/plain')
62+
try:
63+
test_file = container.create_file(f'{filename}.txt')
64+
except Exception as e:
65+
print(e)
4066
print('Start uploading...')
4167
test_file.upload(file_like_io.read())
68+
print(test_file.get_remote_url())
4269
print('Uploaded Successfully')
4370

44-
logger = Core.get_logger()
45-
logger.record_metric(name='test', value='test')
46-
47-
logger = Core.get_logger(provider='Local')
71+
logger = core.get_logger()
4872
logger.record_metric(name='test', value='test')
4973

74+
publish_messages(topic)
75+
time.sleep(2)
5076

51-
def on_connect_callback(instance):
52-
print('Connected with result code {}'.format(instance.get_messages()))
53-
time.sleep(30)
54-
sys.exit()
55-
56-
57-
topicObject1 = Core.get_topic(topic_name=topic, callback=on_connect_callback)
58-
topicObject2 = Core.get_topic(topic_name='tipic')
59-
try:
60-
topicObject2.subscribe(subscription=subscription)
61-
except Exception as e:
62-
print(e)
63-
64-
queue_message = QueueMessage.data_from({
65-
'message': str(uuid.uuid4().hex),
66-
'data': {'a': 1}
67-
})
68-
69-
topicObject1.publish(data=queue_message)
70-
71-
topicObject1.subscribe(subscription=subscription)
77+
# logger = core.get_logger()
78+
# logger.record_metric(name='test', value='test')
79+
os._exit(os.EX_OK)

0 commit comments

Comments
 (0)