Skip to content

Commit

Permalink
RC (#266)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
4 people authored Nov 26, 2024
1 parent 156b692 commit 034a57a
Show file tree
Hide file tree
Showing 34 changed files with 1,847 additions and 1,340 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/bump-version.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ jobs:
cat > emnify/version.py << EOT
# THIS FILE IS GENERATED AUTOMATICALLY, DON'T CHANGE ITS CONTENT!!
EMNIFY_PACKAGE_VERSION='${{ steps.tag_version.outputs.new_version }}'
EMNIFY_PACKAGE_VERSION="${{ steps.tag_version.outputs.new_version }}"
EOT
- uses: stefanzweifel/git-auto-commit-action@v5
Expand Down
20 changes: 20 additions & 0 deletions .github/workflows/lint-check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Lint-Check
on: [push]

jobs:
lint:
runs-on: ubuntu-latest
steps:
- name: Cancel Previous Runs
uses: styfle/[email protected]
with:
access_token: ${{ github.token }}
- uses: actions/checkout@v4

- name: Install dependencies
run: pip install ruff

- name: Run check
run: |
ruff check
ruff format --check
29 changes: 28 additions & 1 deletion DEVELOPMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ Run a command:
# [...args] - command arguments

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

### Local debug example
Expand All @@ -26,6 +30,10 @@ Once your sandbox is set up, you can launch the file and view the results.
```shell
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
```
End-to-end:
```shell
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
```

## Version Bump

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

Squash changes while merging to `development` and do regular merge to `main`.

## Linting

We use `ruff` for lint and format checks. To run the lint check, execute the following command:
```shell
pipenv run ruff check
```
To fix the issues, run:
```shell
pipenv run ruff check --fix
```
To run formatting checks only, execute:
```shell
pipenv run ruff format --check
```
To fix the formatting issues, run:
```shell
pipenv run ruff format
```
4 changes: 2 additions & 2 deletions Dockerfile.dev
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ RUN pip install pipenv

WORKDIR /sdk

COPY Pipfile Pipfile.lock ./
COPY Pipfile ./

RUN pipenv install --deploy --ignore-pipfile --dev
RUN pipenv install --deploy --dev

COPY . .

Expand Down
9 changes: 9 additions & 0 deletions Dockerfile.e2e
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM python:latest

RUN pip install emnify-sdk

WORKDIR /sdk

COPY . .

CMD ["echo", "\"Enter Command(Read DEVELOPMENT.md)\""]
2 changes: 2 additions & 0 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ name = "pypi"
[packages]
requests = ">=2.27.0,<2.33.0"
pydantic = ">=1.9.0,<2.0"
urllib3 = ">=1.26.0,<1.27"

[dev-packages]
vcrpy = "*"
Expand All @@ -15,3 +16,4 @@ bump2version = "*"
pytest-cov = "*"
exceptiongroup = "*"
tomli = "*"
ruff = "*"
733 changes: 447 additions & 286 deletions Pipfile.lock

Large diffs are not rendered by default.

59 changes: 38 additions & 21 deletions docs/examples/device_lifecycle_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

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

# [endblock]

Expand All @@ -14,7 +14,7 @@
unassigned_sims = [i for i in emnify.sim.get_sim_list(without_device=True)]
# If there aren't any unassigned SIMs, register a new one via batch code:
if not unassigned_sims:
registered_sim = emnify.sim.register_sim(bic='EXAMPLE_BIC_CODE') # Returns a list
registered_sim = emnify.sim.register_sim(bic="EXAMPLE_BIC_CODE") # Returns a list
sim = emnify.sim.retrieve_sim(registered_sim[0].id)
else:
sim = unassigned_sims[0] # Takes the first unassigned SIM
Expand All @@ -25,13 +25,13 @@
service_profile = emnify.devices.service_profile_model(id=1)
tariff_profile = emnify.devices.tariff_profile_model(id=1)
device_status = emnify.devices.status_model(id=0)
name = 'new_device'
name = "new_device"
device_model = emnify.devices.device_create_model(
tariff_profile=tariff_profile,
status=device_status,
service_profile=service_profile,
sim=sim,
name=name
name=name,
)

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

tags = 'arduino, meter, temp' # Example tags
name = 'new name' # Example name
tags = "arduino, meter, temp" # Example tags
name = "new name" # Example name

# Adjust the device configuration
update_device_fields = emnify.devices.device_update_model(name='new name', tags='arduino')
update_device_fields = emnify.devices.device_update_model(
name="new name", tags="arduino"
)
emnify.devices.update_device(device_id=device.id, device=update_device_fields)

# Get updated device details
Expand All @@ -73,9 +75,15 @@

# Add three operators to the blacklist:
device_id = 0 # Your device ID
emnify.devices.add_device_blacklist_operator(operator_id=all_operators[0].id, device_id=device_id)
emnify.devices.add_device_blacklist_operator(operator_id=all_operators[1].id, device_id=device_id)
emnify.devices.add_device_blacklist_operator(operator_id=all_operators[2].id, device_id=device_id)
emnify.devices.add_device_blacklist_operator(
operator_id=all_operators[0].id, device_id=device_id
)
emnify.devices.add_device_blacklist_operator(
operator_id=all_operators[1].id, device_id=device_id
)
emnify.devices.add_device_blacklist_operator(
operator_id=all_operators[2].id, device_id=device_id
)

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

# Removes the last operator from the blacklist
emnify.devices.delete_device_blacklist_operator(device_id=device_id, operator_id=operator_id)
emnify.devices.delete_device_blacklist_operator(
device_id=device_id, operator_id=operator_id
)

# [endblock]

# === Example: Disable a device ===

# Get a list of all devices with SIM cards and the "Enabled" device status
device_filter = emnify.devices.get_device_filter_model(status=emnify_constants.DeviceStatuses.ENABLED_ID.value)
device_filter = emnify.devices.get_device_filter_model(
status=emnify_constants.DeviceStatuses.ENABLED_ID.value
)
all_devices_with_sim = [
device for device in emnify.devices.get_devices_list(filter_model=device_filter) if device.sim
device
for device in emnify.devices.get_devices_list(filter_model=device_filter)
if device.sim
]

device = all_devices_with_sim[0]
Expand All @@ -107,7 +121,7 @@

disabled_device = emnify.devices.retrieve_device(device_id=device.id)
device_status = disabled_device.status.description # Device status is "Disabled"
sim_status = disabled_device.sim.status.description # SIM status is "Suspended"
sim_status = disabled_device.sim.status.description # SIM status is "Suspended"

# [endblock]

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

device_to_delete = list(
filter(
lambda device: device.sim and device.status.id == emnify_constants.DeviceStatuses.ENABLED_ID,
old_devices_list
)
filter(
lambda device: device.sim
and device.status.id == emnify_constants.DeviceStatuses.ENABLED_ID,
old_devices_list,
)
)[0]

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

# === Example: Manage device connectivity ===

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

# To reset device connectivity, use the following methods:
# To reset device connectivity, use the following methods:
# - Reset the device's connectivity
device_id = 0
emnify.devices.reset_connectivity_data(device_id=device_id)
Expand All @@ -157,6 +172,8 @@

# Use the following method to check the connectivity:
connectivity = emnify.devices.get_device_connectivity_status(device_id=device_id)
print(connectivity.status.description) # Status is either "Attached", "Online", "Offline", or "Blocked"
print(
connectivity.status.description
) # Status is either "Attached", "Online", "Offline", or "Blocked"

# [endblock]
6 changes: 3 additions & 3 deletions docs/examples/devices.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

# Initiate instance

emnify_client = EMnify('YOUR APP TOKEN')
emnify_client = EMnify("YOUR APP TOKEN")
"""
=== Get all devices ===
"""
Expand All @@ -15,8 +15,8 @@
tariff_profile = emnify_client.devices.tariff_profile_model(id=1)
device_status = emnify_client.devices.status_model(id=0)
device_model = emnify_client.devices.device_create_model(
tariff_profile=tariff_profile, status=device_status, service_profile=service_profile
)
tariff_profile=tariff_profile, status=device_status, service_profile=service_profile
)
# All required models can be retrieved through manager`s properties

device_id = emnify_client.devices.create_device(device_model)
9 changes: 3 additions & 6 deletions docs/examples/filtering_and_sorting.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@

from emnify import EMnify
from emnify import constants as emnify_constants

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

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

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

# After choosing a filtering parameter, pass it as an argument to sort_enum:
sorted_devices = emnify_client.devices.get_devices_list(
sort_enum=sort_parameter
)
sorted_devices = emnify_client.devices.get_devices_list(sort_enum=sort_parameter)

# Now, you have a list of devices with the most recently updated at the top.
for latest_device in sorted_devices:
Expand Down
2 changes: 1 addition & 1 deletion docs/examples/first_operation.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from emnify import EMnify

# Get the token from environment variable
TOKEN = os.environ.get('EMNIFY_APPLICATION_TOKEN')
TOKEN = os.environ.get("EMNIFY_APPLICATION_TOKEN")

# Initiate SDK instance using application token
emnify = EMnify(TOKEN)
Expand Down
21 changes: 11 additions & 10 deletions docs/examples/mass_sim_activation.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,22 @@

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

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

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

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

Expand All @@ -52,7 +54,7 @@
status=device_status,
service_profile=service_profile,
sim=sim,
name=device_name
name=device_name,
)
# See the API Reference to learn other device parameters:
# https://emnify.github.io/emnify-sdk-python/autoapi/index.html
Expand Down Expand Up @@ -82,8 +84,7 @@
SENDER = "city_scooters_admin"

activation_sms = emnify_client.devices.sms_create_model(
payload=ACTIVATION_CODE,
source_adress=SENDER
payload=ACTIVATION_CODE, source_adress=SENDER
)

# Finally, send the configuration SMS to your device:
Expand Down
14 changes: 7 additions & 7 deletions docs/sphinx/conf.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
extensions = ['autoapi.extension']
html_title = 'emnify Python SDK'
extensions = ["autoapi.extension"]
html_title = "emnify Python SDK"
html_theme = "furo"
copyright = "2023 emnify GmbH. All rights reserved."
project = "emnify Python SDK"

html_baseurl = '/autoapi/'
html_logo = '../logo.svg'
html_favicon = '../favicon.ico'
autoapi_type = 'python'
autoapi_dirs = ['../../emnify']
html_baseurl = "/autoapi/"
html_logo = "../logo.svg"
html_favicon = "../favicon.ico"
autoapi_type = "python"
autoapi_dirs = ["../../emnify"]
Loading

0 comments on commit 034a57a

Please sign in to comment.