Skip to content

Commit 034a57a

Browse files
Th3Un1q3marwin-rothdependabot[bot]mikhail.gubenko
authored
RC (#266)
* feat: minimal python version warning (#260) * [Automated] Version Bump from 0.4.0 to 0.4.1 * Add check for minimal python version and e2e testing * refactor: add linter to the CI (#261) * Add lint check to CI * Modify lint check and perform format * Apply ruff format and modify readme and bump-version.yml * build(deps): bump the python group across 1 directory with 3 updates Bumps the python group with 3 updates in the / directory: [requests](https://github.com/psf/requests), [pydantic](https://github.com/pydantic/pydantic) and [ruff](https://github.com/astral-sh/ruff). Updates `requests` from 2.29.0 to 2.32.3 - [Release notes](https://github.com/psf/requests/releases) - [Changelog](https://github.com/psf/requests/blob/main/HISTORY.md) - [Commits](psf/requests@v2.29.0...v2.32.3) Updates `pydantic` from 1.10.19 to 2.10.1 - [Release notes](https://github.com/pydantic/pydantic/releases) - [Changelog](https://github.com/pydantic/pydantic/blob/main/HISTORY.md) - [Commits](pydantic/pydantic@v1.10.19...v2.10.1) Updates `ruff` from 0.7.3 to 0.8.0 - [Release notes](https://github.com/astral-sh/ruff/releases) - [Changelog](https://github.com/astral-sh/ruff/blob/main/CHANGELOG.md) - [Commits](astral-sh/ruff@0.7.3...0.8.0) --- updated-dependencies: - dependency-name: requests dependency-type: direct:production update-type: version-update:semver-minor dependency-group: python - dependency-name: pydantic dependency-type: direct:production update-type: version-update:semver-major dependency-group: python - dependency-name: ruff dependency-type: direct:development update-type: version-update:semver-minor dependency-group: python ... Signed-off-by: dependabot[bot] <[email protected]> * refactor: add lint format check to CI (#267) * Add lint check to CI * Modify lint check and perform format * Apply ruff format and modify readme and bump-version.yml * Add ruff format check to CI * Add ruff format check to CI * Revert version change of pydantic and requests * fix: fix url lib and bump requests * fix: format remarks --------- Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: marwin-roth <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: mikhail.gubenko <[email protected]>
1 parent 156b692 commit 034a57a

34 files changed

+1847
-1340
lines changed

.github/workflows/bump-version.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ jobs:
4747
4848
cat > emnify/version.py << EOT
4949
# THIS FILE IS GENERATED AUTOMATICALLY, DON'T CHANGE ITS CONTENT!!
50-
EMNIFY_PACKAGE_VERSION='${{ steps.tag_version.outputs.new_version }}'
50+
EMNIFY_PACKAGE_VERSION="${{ steps.tag_version.outputs.new_version }}"
5151
EOT
5252
5353
- uses: stefanzweifel/git-auto-commit-action@v5

.github/workflows/lint-check.yml

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: Lint-Check
2+
on: [push]
3+
4+
jobs:
5+
lint:
6+
runs-on: ubuntu-latest
7+
steps:
8+
- name: Cancel Previous Runs
9+
uses: styfle/[email protected]
10+
with:
11+
access_token: ${{ github.token }}
12+
- uses: actions/checkout@v4
13+
14+
- name: Install dependencies
15+
run: pip install ruff
16+
17+
- name: Run check
18+
run: |
19+
ruff check
20+
ruff format --check

DEVELOPMENT.md

+28-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,11 @@ Run a command:
1414
# [...args] - command arguments
1515

1616
# Run unit tests
17-
docker run -t -v $(pwd):/sdk emnify/python-sdk pytest --cov=emnify --cov-fail-under=90
17+
docker run -ti -v $(pwd):/sdk emnify/python-sdk pytest --cov=emnify --cov-fail-under=90
18+
```
19+
For end-to-end testing, make use of the other Dockerfile provided (it uses our package from [PyPI](https://pypi.org/project/emnify-sdk/)):
20+
```shell
21+
docker build . -f Dockerfile.e2e -t emnify/python-sdk-e2e
1822
```
1923

2024
### Local debug example
@@ -26,6 +30,10 @@ Once your sandbox is set up, you can launch the file and view the results.
2630
```shell
2731
docker run -t -e EMNIFY_SDK_APPLICATION_TOKEN=<your_token_here> -e EMNIFY_SDK_API_ENDPOINT_URL=<your_debug_API_endpoint> -v $(pwd):/sdk emnify/python-sdk python docs/examples/local_debug.py
2832
```
33+
End-to-end:
34+
```shell
35+
docker run -t -e EMNIFY_SDK_APPLICATION_TOKEN=<your_token_here> -e EMNIFY_SDK_API_ENDPOINT_URL=<your_debug_API_endpoint> -v $(pwd):/sdk emnify/python-sdk-e2e python docs/examples/local_debug.py
36+
```
2937

3038
## Version Bump
3139

@@ -38,3 +46,22 @@ bump2version minor
3846
PR names must follow [angular convention](https://github.com/angular/angular/blob/main/CONTRIBUTING.md).
3947

4048
Squash changes while merging to `development` and do regular merge to `main`.
49+
50+
## Linting
51+
52+
We use `ruff` for lint and format checks. To run the lint check, execute the following command:
53+
```shell
54+
pipenv run ruff check
55+
```
56+
To fix the issues, run:
57+
```shell
58+
pipenv run ruff check --fix
59+
```
60+
To run formatting checks only, execute:
61+
```shell
62+
pipenv run ruff format --check
63+
```
64+
To fix the formatting issues, run:
65+
```shell
66+
pipenv run ruff format
67+
```

Dockerfile.dev

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ RUN pip install pipenv
44

55
WORKDIR /sdk
66

7-
COPY Pipfile Pipfile.lock ./
7+
COPY Pipfile ./
88

9-
RUN pipenv install --deploy --ignore-pipfile --dev
9+
RUN pipenv install --deploy --dev
1010

1111
COPY . .
1212

Dockerfile.e2e

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
FROM python:latest
2+
3+
RUN pip install emnify-sdk
4+
5+
WORKDIR /sdk
6+
7+
COPY . .
8+
9+
CMD ["echo", "\"Enter Command(Read DEVELOPMENT.md)\""]

Pipfile

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ name = "pypi"
66
[packages]
77
requests = ">=2.27.0,<2.33.0"
88
pydantic = ">=1.9.0,<2.0"
9+
urllib3 = ">=1.26.0,<1.27"
910

1011
[dev-packages]
1112
vcrpy = "*"
@@ -15,3 +16,4 @@ bump2version = "*"
1516
pytest-cov = "*"
1617
exceptiongroup = "*"
1718
tomli = "*"
19+
ruff = "*"

Pipfile.lock

+447-286
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/examples/device_lifecycle_management.py

+38-21
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
# To operate the emnify SDK, you need to generate an application token.
77
# Step-by-step guide: https://www.emnify.com/developer-blog/how-to-use-an-application-token-for-api-authentication
8-
emnify = EMnify(app_token='YOUR_TOKEN')
8+
emnify = EMnify(app_token="YOUR_TOKEN")
99

1010
# [endblock]
1111

@@ -14,7 +14,7 @@
1414
unassigned_sims = [i for i in emnify.sim.get_sim_list(without_device=True)]
1515
# If there aren't any unassigned SIMs, register a new one via batch code:
1616
if not unassigned_sims:
17-
registered_sim = emnify.sim.register_sim(bic='EXAMPLE_BIC_CODE') # Returns a list
17+
registered_sim = emnify.sim.register_sim(bic="EXAMPLE_BIC_CODE") # Returns a list
1818
sim = emnify.sim.retrieve_sim(registered_sim[0].id)
1919
else:
2020
sim = unassigned_sims[0] # Takes the first unassigned SIM
@@ -25,13 +25,13 @@
2525
service_profile = emnify.devices.service_profile_model(id=1)
2626
tariff_profile = emnify.devices.tariff_profile_model(id=1)
2727
device_status = emnify.devices.status_model(id=0)
28-
name = 'new_device'
28+
name = "new_device"
2929
device_model = emnify.devices.device_create_model(
3030
tariff_profile=tariff_profile,
3131
status=device_status,
3232
service_profile=service_profile,
3333
sim=sim,
34-
name=name
34+
name=name,
3535
)
3636

3737
# After creating a model, the SDK returns the device ID.
@@ -53,11 +53,13 @@
5353
# Get device details
5454
device = emnify.devices.retrieve_device(device_id=device_id)
5555

56-
tags = 'arduino, meter, temp' # Example tags
57-
name = 'new name' # Example name
56+
tags = "arduino, meter, temp" # Example tags
57+
name = "new name" # Example name
5858

5959
# Adjust the device configuration
60-
update_device_fields = emnify.devices.device_update_model(name='new name', tags='arduino')
60+
update_device_fields = emnify.devices.device_update_model(
61+
name="new name", tags="arduino"
62+
)
6163
emnify.devices.update_device(device_id=device.id, device=update_device_fields)
6264

6365
# Get updated device details
@@ -73,9 +75,15 @@
7375

7476
# Add three operators to the blacklist:
7577
device_id = 0 # Your device ID
76-
emnify.devices.add_device_blacklist_operator(operator_id=all_operators[0].id, device_id=device_id)
77-
emnify.devices.add_device_blacklist_operator(operator_id=all_operators[1].id, device_id=device_id)
78-
emnify.devices.add_device_blacklist_operator(operator_id=all_operators[2].id, device_id=device_id)
78+
emnify.devices.add_device_blacklist_operator(
79+
operator_id=all_operators[0].id, device_id=device_id
80+
)
81+
emnify.devices.add_device_blacklist_operator(
82+
operator_id=all_operators[1].id, device_id=device_id
83+
)
84+
emnify.devices.add_device_blacklist_operator(
85+
operator_id=all_operators[2].id, device_id=device_id
86+
)
7987

8088
# Get all blacklist operators of the device by device ID:
8189
device_blacklist = emnify.devices.get_device_operator_blacklist(device_id=device_id)
@@ -88,16 +96,22 @@
8896
operator_id = operator.id
8997

9098
# Removes the last operator from the blacklist
91-
emnify.devices.delete_device_blacklist_operator(device_id=device_id, operator_id=operator_id)
99+
emnify.devices.delete_device_blacklist_operator(
100+
device_id=device_id, operator_id=operator_id
101+
)
92102

93103
# [endblock]
94104

95105
# === Example: Disable a device ===
96106

97107
# Get a list of all devices with SIM cards and the "Enabled" device status
98-
device_filter = emnify.devices.get_device_filter_model(status=emnify_constants.DeviceStatuses.ENABLED_ID.value)
108+
device_filter = emnify.devices.get_device_filter_model(
109+
status=emnify_constants.DeviceStatuses.ENABLED_ID.value
110+
)
99111
all_devices_with_sim = [
100-
device for device in emnify.devices.get_devices_list(filter_model=device_filter) if device.sim
112+
device
113+
for device in emnify.devices.get_devices_list(filter_model=device_filter)
114+
if device.sim
101115
]
102116

103117
device = all_devices_with_sim[0]
@@ -107,7 +121,7 @@
107121

108122
disabled_device = emnify.devices.retrieve_device(device_id=device.id)
109123
device_status = disabled_device.status.description # Device status is "Disabled"
110-
sim_status = disabled_device.sim.status.description # SIM status is "Suspended"
124+
sim_status = disabled_device.sim.status.description # SIM status is "Suspended"
111125

112126
# [endblock]
113127

@@ -117,10 +131,11 @@
117131
old_devices_list = [device for device in emnify.devices.get_devices_list()]
118132

119133
device_to_delete = list(
120-
filter(
121-
lambda device: device.sim and device.status.id == emnify_constants.DeviceStatuses.ENABLED_ID,
122-
old_devices_list
123-
)
134+
filter(
135+
lambda device: device.sim
136+
and device.status.id == emnify_constants.DeviceStatuses.ENABLED_ID,
137+
old_devices_list,
138+
)
124139
)[0]
125140

126141
# Choose a device to delete with an assigned SIM and the "Enabled" device status
@@ -142,13 +157,13 @@
142157

143158
# === Example: Manage device connectivity ===
144159

145-
# There are many reasons why connection issues arise.
160+
# There are many reasons why connection issues arise.
146161
# For example:
147162
# - The device executes the wrong procedures due to a bad firmware update.
148163
# - The device executes network registration too frequently, so the network no longer allows it to register.
149164
# - You changed a policy due to a blocked device.
150165

151-
# To reset device connectivity, use the following methods:
166+
# To reset device connectivity, use the following methods:
152167
# - Reset the device's connectivity
153168
device_id = 0
154169
emnify.devices.reset_connectivity_data(device_id=device_id)
@@ -157,6 +172,8 @@
157172

158173
# Use the following method to check the connectivity:
159174
connectivity = emnify.devices.get_device_connectivity_status(device_id=device_id)
160-
print(connectivity.status.description) # Status is either "Attached", "Online", "Offline", or "Blocked"
175+
print(
176+
connectivity.status.description
177+
) # Status is either "Attached", "Online", "Offline", or "Blocked"
161178

162179
# [endblock]

docs/examples/devices.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
# Initiate instance
55

6-
emnify_client = EMnify('YOUR APP TOKEN')
6+
emnify_client = EMnify("YOUR APP TOKEN")
77
"""
88
=== Get all devices ===
99
"""
@@ -15,8 +15,8 @@
1515
tariff_profile = emnify_client.devices.tariff_profile_model(id=1)
1616
device_status = emnify_client.devices.status_model(id=0)
1717
device_model = emnify_client.devices.device_create_model(
18-
tariff_profile=tariff_profile, status=device_status, service_profile=service_profile
19-
)
18+
tariff_profile=tariff_profile, status=device_status, service_profile=service_profile
19+
)
2020
# All required models can be retrieved through manager`s properties
2121

2222
device_id = emnify_client.devices.create_device(device_model)

docs/examples/filtering_and_sorting.py

+3-6
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
21
from emnify import EMnify
32
from emnify import constants as emnify_constants
43

54
# To operate the emnify SDK, you need to generate an application token.
65
# Step-by-step guide: https://www.emnify.com/developer-blog/how-to-use-an-application-token-for-api-authentication
7-
emnify_client = EMnify(app_token='YOUR_TOKEN')
6+
emnify_client = EMnify(app_token="YOUR_TOKEN")
87

98
# Some methods that return multiple objects allow sorting and filtering.
109
# API reference: https://emnify.github.io/emnify-sdk-python/autoapi/index.html
@@ -32,7 +31,7 @@
3231
sim_filter = emnify_client.sim.get_sim_filter_model(
3332
customer_org=1,
3433
status=emnify_constants.SimStatusesID.ACTIVATED_ID.value,
35-
production_date='2019-01-25'
34+
production_date="2019-01-25",
3635
)
3736

3837
# The list SIM cards request also has a separate filter, passed as an argument.
@@ -49,9 +48,7 @@
4948
sort_parameter = emnify_client.devices.get_device_sort_enum.LAST_UPDATED.value
5049

5150
# After choosing a filtering parameter, pass it as an argument to sort_enum:
52-
sorted_devices = emnify_client.devices.get_devices_list(
53-
sort_enum=sort_parameter
54-
)
51+
sorted_devices = emnify_client.devices.get_devices_list(sort_enum=sort_parameter)
5552

5653
# Now, you have a list of devices with the most recently updated at the top.
5754
for latest_device in sorted_devices:

docs/examples/first_operation.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from emnify import EMnify
55

66
# Get the token from environment variable
7-
TOKEN = os.environ.get('EMNIFY_APPLICATION_TOKEN')
7+
TOKEN = os.environ.get("EMNIFY_APPLICATION_TOKEN")
88

99
# Initiate SDK instance using application token
1010
emnify = EMnify(TOKEN)

docs/examples/mass_sim_activation.py

+11-10
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,22 @@
66

77
# To operate the emnify SDK, you need to generate an application token.
88
# Step-by-step guide: https://www.emnify.com/developer-blog/how-to-use-an-application-token-for-api-authentication
9-
token = input('token: ')
9+
token = input("token: ")
1010
# Authorize the client to perform operations:
1111
emnify_client = EMnify(token)
1212

1313
# Before going online, you need a device and a SIM card.
1414
# This example assumes you have a batch of SIM cards for your devices.
15-
sim_batch_BIC2 = input('BIC2: ')
15+
sim_batch_BIC2 = input("BIC2: ")
1616

1717
# emnify allows you to control your service and coverage policies.
18-
# You can find those IDs on the Portal: https://portal.emnify.com/device-policies
19-
service_profile_id = input('Service Profile ID: ')
20-
tariff_profile_id = input('Tariff Profile ID: ')
18+
# You can find those IDs on the Portal: https://portal.emnify.com/device-policies
19+
service_profile_id = input("Service Profile ID: ")
20+
tariff_profile_id = input("Tariff Profile ID: ")
2121
# Then, you need service and coverage profiles to create devices later:
22-
service_profile = emnify_client.devices.service_profile_model(id=int(service_profile_id))
22+
service_profile = emnify_client.devices.service_profile_model(
23+
id=int(service_profile_id)
24+
)
2325
tariff_profile = emnify_client.devices.tariff_profile_model(id=int(tariff_profile_id))
2426

2527
try:
@@ -30,7 +32,7 @@
3032
# All added SIMs are now registered with "Issued" status.
3133
except EMnifyBaseException as e:
3234
# If an error appears during SIM registration,
33-
# use EMnifyBaseException for general exceptions
35+
# use EMnifyBaseException for general exceptions
3436
# or inherited classes for specific ones.
3537
raise AssertionError(f"error during sim batch BIC2 activation{e}")
3638

@@ -52,7 +54,7 @@
5254
status=device_status,
5355
service_profile=service_profile,
5456
sim=sim,
55-
name=device_name
57+
name=device_name,
5658
)
5759
# See the API Reference to learn other device parameters:
5860
# https://emnify.github.io/emnify-sdk-python/autoapi/index.html
@@ -82,8 +84,7 @@
8284
SENDER = "city_scooters_admin"
8385

8486
activation_sms = emnify_client.devices.sms_create_model(
85-
payload=ACTIVATION_CODE,
86-
source_adress=SENDER
87+
payload=ACTIVATION_CODE, source_adress=SENDER
8788
)
8889

8990
# Finally, send the configuration SMS to your device:

docs/sphinx/conf.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
extensions = ['autoapi.extension']
2-
html_title = 'emnify Python SDK'
1+
extensions = ["autoapi.extension"]
2+
html_title = "emnify Python SDK"
33
html_theme = "furo"
44
copyright = "2023 emnify GmbH. All rights reserved."
55
project = "emnify Python SDK"
66

7-
html_baseurl = '/autoapi/'
8-
html_logo = '../logo.svg'
9-
html_favicon = '../favicon.ico'
10-
autoapi_type = 'python'
11-
autoapi_dirs = ['../../emnify']
7+
html_baseurl = "/autoapi/"
8+
html_logo = "../logo.svg"
9+
html_favicon = "../favicon.ico"
10+
autoapi_type = "python"
11+
autoapi_dirs = ["../../emnify"]

0 commit comments

Comments
 (0)