From 550c13ad0fa16cbffe8e16a90e4d7f5da08322da Mon Sep 17 00:00:00 2001 From: chrizog Date: Mon, 5 Feb 2024 19:27:54 +0100 Subject: [PATCH] Enabling package build and upload --- .gitignore | 2 ++ example_apps/send_events.py | 19 ++++++-------- example_apps/temperature_msg.py | 5 +--- pyproject.toml | 3 +++ setup.cfg | 25 +++++++++++++++++++ src/{ => someipy}/__init__.py | 0 src/{ => someipy}/_internal/__init__.py | 0 src/{ => someipy}/_internal/logging.py | 2 +- src/{ => someipy}/_internal/message_types.py | 0 .../_internal/service_discovery_abcs.py | 4 +-- .../_internal/session_handler.py | 0 src/{ => someipy}/_internal/simple_timer.py | 1 - src/{ => someipy}/_internal/someip_header.py | 0 .../_internal/someip_sd_builder.py | 0 .../_internal/someip_sd_extractors.py | 0 .../_internal/someip_sd_header.py | 4 +-- src/{ => someipy}/_internal/utils.py | 0 src/{ => someipy}/logging.py | 0 src/{ => someipy}/serialization.py | 0 src/{ => someipy}/server_service_instance.py | 16 ++++++------ src/{ => someipy}/service_discovery.py | 14 +++++------ tests/test_serialization.py | 5 +++- 22 files changed, 62 insertions(+), 38 deletions(-) create mode 100644 pyproject.toml create mode 100644 setup.cfg rename src/{ => someipy}/__init__.py (100%) rename src/{ => someipy}/_internal/__init__.py (100%) rename src/{ => someipy}/_internal/logging.py (91%) rename src/{ => someipy}/_internal/message_types.py (100%) rename src/{ => someipy}/_internal/service_discovery_abcs.py (91%) rename src/{ => someipy}/_internal/session_handler.py (100%) rename src/{ => someipy}/_internal/simple_timer.py (99%) rename src/{ => someipy}/_internal/someip_header.py (100%) rename src/{ => someipy}/_internal/someip_sd_builder.py (100%) rename src/{ => someipy}/_internal/someip_sd_extractors.py (100%) rename src/{ => someipy}/_internal/someip_sd_header.py (98%) rename src/{ => someipy}/_internal/utils.py (100%) rename src/{ => someipy}/logging.py (100%) rename src/{ => someipy}/serialization.py (100%) rename src/{ => someipy}/server_service_instance.py (94%) rename src/{ => someipy}/service_discovery.py (92%) diff --git a/.gitignore b/.gitignore index 0daa041..01aa025 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ .vscode/ +dist/ +someipy.egg-info/ __pycache__ \ No newline at end of file diff --git a/example_apps/send_events.py b/example_apps/send_events.py index c1e9c03..141a914 100644 --- a/example_apps/send_events.py +++ b/example_apps/send_events.py @@ -1,16 +1,11 @@ -import sys -sys.path.append("..") - import asyncio import ipaddress import logging -import src.service_discovery -import src._internal.someip_header -import src._internal.someip_sd_header -import src.server_service_instance -from src.logging import set_someipy_log_level -from src.serialization import Uint8, Uint64, Float32 +from someipy.service_discovery import construct_service_discovery +from someipy.server_service_instance import ServerServiceInstance +from someipy.logging import set_someipy_log_level +from someipy.serialization import Uint8, Uint64, Float32 from temperature_msg import TemparatureMsg SD_MULTICAST_GROUP = "224.224.224.245" @@ -28,7 +23,7 @@ async def main(): # Since the construction of the class ServiceDiscoveryProtocol is not trivial and would require an async __init__ function # use the construct_service_discovery function # The local interface IP address needs to be passed so that the src-address of all SD UDP packets is correctly set - service_discovery = await src.service_discovery.construct_service_discovery(SD_MULTICAST_GROUP, SD_PORT, INTERFACE_IP) + service_discovery = await construct_service_discovery(SD_MULTICAST_GROUP, SD_PORT, INTERFACE_IP) # 1. For sending events use a ServerServiceInstance # 2. Pass the service and instance ID, version and endpoint and TTL. The endpoint is needed again as the src-address @@ -36,7 +31,7 @@ async def main(): # 3. The ServiceDiscoveryProtocol object has to be passed as well, so the ServerServiceInstance can offer his service to # other ECUs # 4. cyclic_offer_delay_ms is the period of sending cyclic SD Offer service entries - service_instance_temperature = src.server_service_instance.ServerServiceInstance( + service_instance_temperature = ServerServiceInstance( service_id=1, instance_id=1000, major_version=1, @@ -52,7 +47,7 @@ async def main(): service_discovery.attach(service_instance_temperature) # For demonstration purposes we will construct a second ServerServiceInstance - service_instance_2 = src.server_service_instance.ServerServiceInstance( + service_instance_2 = ServerServiceInstance( service_id=2, instance_id=2000, major_version=1, diff --git a/example_apps/temperature_msg.py b/example_apps/temperature_msg.py index 27e4427..4002cb4 100644 --- a/example_apps/temperature_msg.py +++ b/example_apps/temperature_msg.py @@ -1,7 +1,4 @@ -import sys -sys.path.append("..") - -from src.serialization import * +from someipy.serialization import * # With someipy it's possible to either send and receive payloads unserialized simply as bytes-objects # You can also define the payloads structure directly as Python classes and serialize your Python object diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..f1bfca4 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ['setuptools>=42'] +build-backend = 'setuptools.build_meta' diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 0000000..fef5e8e --- /dev/null +++ b/setup.cfg @@ -0,0 +1,25 @@ +[metadata] +name = someipy +version = 0.0.0 +author = Christian H. +author_email = someipy.package@gmail.com +description = A Python package implementing the SOME/IP protocol +long_description = file: README.md +long_description_content_type = text/markdown +url = https://github.com/chrizog/someipy +project_urls = + Bug Tracker = https://github.com/chrizog/someipy/issues + Repository = https://github.com/chrizog/someipy +classifiers = + Intended Audience :: Developers + Operating System :: POSIX :: Linux + Programming Language :: Python :: 3.12 + +[options] +package_dir = + = src +packages = find: +python_requires = >=3.12 + +[options.packages.find] +where = src \ No newline at end of file diff --git a/src/__init__.py b/src/someipy/__init__.py similarity index 100% rename from src/__init__.py rename to src/someipy/__init__.py diff --git a/src/_internal/__init__.py b/src/someipy/_internal/__init__.py similarity index 100% rename from src/_internal/__init__.py rename to src/someipy/_internal/__init__.py diff --git a/src/_internal/logging.py b/src/someipy/_internal/logging.py similarity index 91% rename from src/_internal/logging.py rename to src/someipy/_internal/logging.py index 7f0217a..27f4a5f 100644 --- a/src/_internal/logging.py +++ b/src/someipy/_internal/logging.py @@ -1,5 +1,5 @@ import logging -from src.logging import get_someipy_log_level +from someipy.logging import get_someipy_log_level def get_logger(name: str) -> logging.Logger: logger = logging.getLogger("someipy." + name) diff --git a/src/_internal/message_types.py b/src/someipy/_internal/message_types.py similarity index 100% rename from src/_internal/message_types.py rename to src/someipy/_internal/message_types.py diff --git a/src/_internal/service_discovery_abcs.py b/src/someipy/_internal/service_discovery_abcs.py similarity index 91% rename from src/_internal/service_discovery_abcs.py rename to src/someipy/_internal/service_discovery_abcs.py index 68d5be8..23838f0 100644 --- a/src/_internal/service_discovery_abcs.py +++ b/src/someipy/_internal/service_discovery_abcs.py @@ -1,6 +1,6 @@ from abc import ABC, abstractmethod -from src._internal.someip_sd_header import * -from src._internal.session_handler import SessionHandler +from someipy._internal.someip_sd_header import * +from someipy._internal.session_handler import SessionHandler class ServiceDiscoveryObserver(ABC): diff --git a/src/_internal/session_handler.py b/src/someipy/_internal/session_handler.py similarity index 100% rename from src/_internal/session_handler.py rename to src/someipy/_internal/session_handler.py diff --git a/src/_internal/simple_timer.py b/src/someipy/_internal/simple_timer.py similarity index 99% rename from src/_internal/simple_timer.py rename to src/someipy/_internal/simple_timer.py index b3489c9..1dc68f5 100644 --- a/src/_internal/simple_timer.py +++ b/src/someipy/_internal/simple_timer.py @@ -2,7 +2,6 @@ import time - class SimplePeriodicTimer(): def __init__(self, period, callback): self._period = period diff --git a/src/_internal/someip_header.py b/src/someipy/_internal/someip_header.py similarity index 100% rename from src/_internal/someip_header.py rename to src/someipy/_internal/someip_header.py diff --git a/src/_internal/someip_sd_builder.py b/src/someipy/_internal/someip_sd_builder.py similarity index 100% rename from src/_internal/someip_sd_builder.py rename to src/someipy/_internal/someip_sd_builder.py diff --git a/src/_internal/someip_sd_extractors.py b/src/someipy/_internal/someip_sd_extractors.py similarity index 100% rename from src/_internal/someip_sd_extractors.py rename to src/someipy/_internal/someip_sd_extractors.py diff --git a/src/_internal/someip_sd_header.py b/src/someipy/_internal/someip_sd_header.py similarity index 98% rename from src/_internal/someip_sd_header.py rename to src/someipy/_internal/someip_sd_header.py index f914477..d263d14 100644 --- a/src/_internal/someip_sd_header.py +++ b/src/someipy/_internal/someip_sd_header.py @@ -4,8 +4,8 @@ from dataclasses import dataclass from typing import List, Tuple, TypeVar, Union -from src._internal.utils import set_bit_at_position, is_bit_set -from src._internal.someip_header import SomeIpHeader +from someipy._internal.utils import set_bit_at_position, is_bit_set +from someipy._internal.someip_header import SomeIpHeader # Constants for byte positions inside the SD header SD_POSITION_ENTRY_LENGTH = 20 diff --git a/src/_internal/utils.py b/src/someipy/_internal/utils.py similarity index 100% rename from src/_internal/utils.py rename to src/someipy/_internal/utils.py diff --git a/src/logging.py b/src/someipy/logging.py similarity index 100% rename from src/logging.py rename to src/someipy/logging.py diff --git a/src/serialization.py b/src/someipy/serialization.py similarity index 100% rename from src/serialization.py rename to src/someipy/serialization.py diff --git a/src/server_service_instance.py b/src/someipy/server_service_instance.py similarity index 94% rename from src/server_service_instance.py rename to src/someipy/server_service_instance.py index 505efd1..8d87303 100644 --- a/src/server_service_instance.py +++ b/src/someipy/server_service_instance.py @@ -1,23 +1,23 @@ from dataclasses import dataclass from typing import List -from src.service_discovery import * -from src._internal.message_types import MessageType -from src._internal.someip_sd_builder import * -from src._internal.someip_header import SomeIpHeader -from src._internal.someip_sd_header import ( +from someipy.service_discovery import * +from someipy._internal.message_types import MessageType +from someipy._internal.someip_sd_builder import * +from someipy._internal.someip_header import SomeIpHeader +from someipy._internal.someip_sd_header import ( SdService, TransportLayerProtocol, SdEventGroupEntry, ) -from src._internal.simple_timer import SimplePeriodicTimer -from src._internal.utils import ( +from someipy._internal.simple_timer import SimplePeriodicTimer +from someipy._internal.utils import ( create_udp_socket, endpoint_to_str_int_tuple, EndpointType, ) -from src._internal.logging import get_logger +from someipy._internal.logging import get_logger _logger = get_logger("server_service_instance") diff --git a/src/service_discovery.py b/src/someipy/service_discovery.py similarity index 92% rename from src/service_discovery.py rename to src/someipy/service_discovery.py index 6ce64a6..e18a8ca 100644 --- a/src/service_discovery.py +++ b/src/someipy/service_discovery.py @@ -2,17 +2,17 @@ import ipaddress from typing import Any, Union, Tuple, List -from src._internal.someip_header import SomeIpHeader -from src._internal.someip_sd_header import * -from src._internal.someip_sd_extractors import * -from src._internal.session_handler import SessionHandler -from src._internal.utils import ( +from someipy._internal.someip_header import SomeIpHeader +from someipy._internal.someip_sd_header import * +from someipy._internal.someip_sd_extractors import * +from someipy._internal.session_handler import SessionHandler +from someipy._internal.utils import ( create_rcv_multicast_socket, create_udp_socket, DatagramAdapter, ) -from src._internal.service_discovery_abcs import * -from src._internal.logging import get_logger +from someipy._internal.service_discovery_abcs import * +from someipy._internal.logging import get_logger _logger = get_logger("service_discovery") diff --git a/tests/test_serialization.py b/tests/test_serialization.py index e9063e7..138ec74 100644 --- a/tests/test_serialization.py +++ b/tests/test_serialization.py @@ -1,5 +1,8 @@ +import sys +sys.path.append("src") + import pytest -from src.serialization import * +from someipy.serialization import * def test_base_types_len():