Skip to content

Commit

Permalink
Feature/validate and fix toml (#46)
Browse files Browse the repository at this point in the history
* Draft.

* Update CI/CD workflows and project metadata

Updated the Python versions under test in the CI/CD workflows to include Python 3.12. Also, made changes in the pyproject.toml and setup.py files, reflecting the updated metadata, including authors, readme, classifiers, etc. The setuptools calls in setup.py were significantly simplified.

* Replace README.adoc with README.md

Removed the adoc formatted README file and replaced it with a markdown version (README.md). The new README file maintains the original content but uses markdown language, which is more widely supported and easier to read.

* Refactor agrirouter to src in all imports

Removed agrirouter module and replaced it with the src module in import statements across the codebase. This change was made to better align the module names with its functions, and improve readability and organization of code structure. The change also covers respective adaptations in the file system and addition of new '__init__.py' files for the package structure. Ensured that all existing references to the old 'agrirouter' name are updated to 'src'.

* Wrap setup call in main function in setup.py

The setup function in setup.py now only runs if the script is run directly. This modification prevents unnecessary operations from taking place when the module is imported, improving efficiency and avoiding potential issues.

* Remove unnecessary imports from __init__.py

Unnecessary imports were removed from __init__.py, greatly cleaining it up. This change makes the code cleaner, improves understandability, and potentially increases the execution efficiency.

* Correct invalid test in test_validate_toml.py

The removed line of code did not contribute to the testing process of validating the toml file. The adjustment corrects the test logic, making the test case more effective and meaningful. Now, the test will run as intended.1

* Add missing dependencies in requirements.txt

Two new dependencies, google and toml, were added to the project's requirements.txt. This ensures that all needed packages for the application to work properly will be installed.

* Update continuous-integration.yml for wheel build

Added a new step in the continuous-integration.yml file for a dry run of the wheel build. This change ensures that the wheel build is functioning as expected before each deployment, reducing potential failure points.

* Update Python versions and script versions in workflows

The Python version and action scripts in the GitHub workflows have been updated. The supported Python version constraints have also been adjusted in pyproject.toml to reflect these changes and ensure compatibility in all contexts.

* Add dry run build to linting workflow

A dry run build step to wheel package creation has been added to the GitHub linting workflow. With this change, along with the flake8 linting, a source distribution and wheel distribution will be created natively in Python, ensuring code quality and functionality before deployment.

* Add wheel and setuptools to CI workflows

The continuous integration and linting workflows have been updated to include the installation of 'wheel' and 'setuptools'. These packages are essential for the creation of a Python wheel distribution, enabling a dry run build which ensures code quality and functionality before the actual deployment.

* Fix typo in pip install command in CI workflows

The pip install command for 'wheel' and 'setuptools' in both continuous integration and linting workflows contained a typo. This typo has been corrected to ensure that the necessary packages are installed correctly. These packages are critical for creating Python wheel distributions and for running quality assurance checks before deployment.

* Remove setup.py and unnecessary pip install commands

Removed setup.py and unnecessary pip installs for flake8, pytest, wheel, and setuptools from CI workflow files. Dependencies are now managed using the requirements.txt file. The 'build' package was added to the requirements.txt to help create Python distributions.

* Update Python package build method in CI workflows

The package building command in CI workflows has been updated from using setup.py to the 'build' package. This change has been made in both 'continuous-integration.yml' and 'linting-for-all-versions.yml' files. This change simplifies managing dependencies via the requirements.txt file.

* Update Python versions for linting workflow

Removed Python version "3.7" from the linting GitHub actions configuration. Now, the linting will only run for Python versions "3.8", "3.9", "3.10", and "3.11".
  • Loading branch information
saschadoemer authored Apr 10, 2024
1 parent dbd9d53 commit 8394153
Show file tree
Hide file tree
Showing 134 changed files with 860 additions and 882 deletions.
8 changes: 5 additions & 3 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,21 @@ jobs:
python-version: [ "3.11" ]

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install flake8 pytest
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Lint with flake8
run: |
flake8 .
- name: Test with pytest
run: |
pytest
- name: Dry run building the wheel
run: |
python -m build --sdist --wheel
10 changes: 6 additions & 4 deletions .github/workflows/linting-for-all-versions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,21 @@ jobs:
max-parallel: 1
fail-fast: false
matrix:
python-version: [ "3.7", "3.8", "3.9", "3.10", "3.11" ]
python-version: [ "3.8", "3.9", "3.10", "3.11" ]

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install flake8 pytest
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Lint with flake8
run: |
flake8 .
- name: Dry run building the wheel
run: |
python -m build --sdist --wheel
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ venv
.pytest_cache
/paho/
/paho_mqtt-1.6.1.dist-info/
/paho/
/paho_mqtt-1.6.1.dist-info/
agrirouter.egg-info/
build/
dist/
62 changes: 0 additions & 62 deletions README.adoc

This file was deleted.

65 changes: 65 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
![agrirouter logo](./assets/images/agrirouter.svg)

# About the project

The agrirouter is a universal data exchange platform for farmers and
agricultural contractors that makes it possible to connect machinery
and agricultural software, regardless of vendor or manufacturer.
Agrirouter does not save data; it transfers data. As a universal data
exchange platform, agrirouter fills a gap on the way to Farming 4.0.
Its underlying concept unites cross-vendor and discrimination-free
data transfer. You retain full control over your data. Even data
exchange with service providers (e.g. agricultural contractors) and
other partners is uncomplicated: Data are very rapidly transferred via
the online connection, and if you wish, is intelligently connected to
other datasets.

# The current project you’re looking at

This project contains the SDK for the communication with the agrirouter.
Everything you need for the onboard process, secure communication and
much more.

# Installation

Create your virtual environment using any kind of `conda` setup you
would like to have. The SDK is tested with Python 3.8, 3.9, 3.10 and
3.11.

``` bash
conda create -n agrirouter-sdk-python python=3.8
conda create -n agrirouter-sdk-python python=3.9
conda create -n agrirouter-sdk-python python=3.10
conda create -n agrirouter-sdk-python python=3.11
```

Create one of the environments and activate it:

``` bash
conda activate agrirouter-sdk-python
```

After the activation you are ready to install the requirements for the
SDK:

``` bash
pip install -r requirements.txt
```

You are able to select the virtual environment when working with the
IDE.

# Running unit tests

`$ pytest`

# External resources

Here are some external resources for the development:

- [My Agrirouter Website](https://my-agrirouter.com)

- [Integration
Guide](https://github.com/DKE-Data/agrirouter-interface-documentation)

- [EFDI Protobuf Definition](https://www.aef-online.org)
14 changes: 0 additions & 14 deletions agrirouter/__init__.py

This file was deleted.

47 changes: 0 additions & 47 deletions agrirouter/utils/type_url.py

This file was deleted.

4 changes: 2 additions & 2 deletions conftest.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import pytest

from agrirouter.api.enums import Environments
from src.api.enums import Environments
from tests.common.constants import PUBLIC_KEY, PRIVATE_KEY, AUTH_RESULT_URL


@pytest.fixture(scope="session")
def authorization():
from agrirouter.auth.auth import Authorization
from src.auth.auth import Authorization

auth_client = Authorization(Environments.QA.value, public_key=PUBLIC_KEY, private_key=PRIVATE_KEY)
auth_response = auth_client.extract_auth_response(AUTH_RESULT_URL)
Expand Down
28 changes: 14 additions & 14 deletions example_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

from google.protobuf.timestamp_pb2 import Timestamp

from agrirouter.generated.messaging.request.payload.account.endpoints_pb2 import ListEndpointsQuery
from agrirouter.generated.messaging.request.payload.feed.feed_requests_pb2 import ValidityPeriod
from agrirouter.onboarding.response import OnboardResponse
from src.generated.messaging.request.payload.account.endpoints_pb2 import ListEndpointsQuery
from src.generated.messaging.request.payload.feed.feed_requests_pb2 import ValidityPeriod
from src.onboarding.response import OnboardResponse

public_key = """-----BEGIN PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAzGt41/+kSOTlO1sJvLIN
Expand Down Expand Up @@ -64,15 +64,15 @@
}
}

import agrirouter as ar
from agrirouter.onboarding.enums import Gateways
from agrirouter.messaging.enums import CapabilityType
from agrirouter.generated.messaging.request.payload.endpoint.subscription_pb2 import Subscription
from agrirouter.generated.messaging.request.payload.endpoint.capabilities_pb2 import CapabilitySpecification
from agrirouter.messaging.services.commons import HttpMessagingService, MqttMessagingService
from agrirouter import ListEndpointsParameters, ListEndpointsService, SubscriptionService, SubscriptionParameters, \
import src as ar
from src.onboarding.enums import Gateways
from src.messaging.enums import CapabilityType
from src.generated.messaging.request.payload.endpoint.subscription_pb2 import Subscription
from src.generated.messaging.request.payload.endpoint.capabilities_pb2 import CapabilitySpecification
from src.messaging.services.commons import HttpMessagingService, MqttMessagingService
from src import ListEndpointsParameters, ListEndpointsService, SubscriptionService, SubscriptionParameters, \
QueryHeaderService, QueryHeaderParameters, CapabilitiesService, CapabilitiesParameters
from agrirouter.utils.uuid_util import new_uuid
from src.utils.uuid_util import new_uuid

application_id = "8c947a45-c57d-42d2-affc-206e21d63a50" # # store here your application id. You can find it in AR UI
certification_version_id = "edd5d6b7-45bb-4471-898e-ff9c2a7bf56f" # # store here your certification version id. You can find it in AR UI
Expand Down Expand Up @@ -298,9 +298,9 @@ def example_query_header_message_mqtt(onboarding_response_data, on_msg_callback)
def on_message_callback(client, userdata, msg):
# Define here the way receiving messages will be processed

from agrirouter.messaging.decode import decode_response
from agrirouter.messaging.decode import decode_details
from agrirouter.messaging.messages import OutboxMessage
from src.messaging.decode import decode_response
from src.messaging.decode import decode_details
from src.messaging.messages import OutboxMessage

outbox_message = OutboxMessage()
outbox_message.json_deserialize(msg.payload.decode().replace("'", '"'))
Expand Down
28 changes: 22 additions & 6 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,15 +1,31 @@
[project]
name = "agrirouter"
description = "agrirouter SDK"
version = "1.0.0b1"
dynamic = ["dependencies"]
version = "2.0.0"
description = "Python SDK for the agrirouter API. This project contains the API for the communication with the agrirouter. Everything you need for the onboarding process, secure communication and much more."
authors = [
{ name = "Alexey Petrovsky", email = "[email protected]" },
{ name = "Oliver Rahner", email = "[email protected]" },
{ name = "Sascha Dömer", email = "[email protected]" },
]
readme = "README.md"
requires-python = ">=3.7, <=3.11"
urls = { "Source" = "https://github.com/DKE-Data/agrirouter-sdk-python" }
classifiers = [
"Intended Audience :: Developers",
"License :: Apache License 2.0",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Topic :: Software Development :: Libraries",
"Topic :: Software Development :: Libraries :: Python Modules"
]

[build-system]
requires = ["setuptools", "wheel"]
build-backend = "setuptools.build_meta"

[tool.setuptools]
packages = ["agrirouter"]

[tool.setuptools.dynamic]
dependencies = { file = ["requirements.txt"] }
3 changes: 3 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,6 @@ certifi~=2023.7.22
requests~=2.31.0
paho-mqtt~=1.5.1
protobuf~=3.18.0
google~=3.0.0
toml~=0.10.2
build~=1.1.1
Loading

0 comments on commit 8394153

Please sign in to comment.