diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 82c66a3..42ddcae 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,24 +1,19 @@ # This workflow will install Python dependencies, run tests and lint with a single version of Python # For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python -name: Python application - +name: Build and test on: push: branches: [ "main", "dev-json" ] pull_request: branches: [ "main" ] merge_group: - -permissions: - contents: read - jobs: build: runs-on: ubuntu-latest strategy: matrix: - python-version: ["3.8", "3.9", "3.10", "3.11"] + python-version: ["3.9", "3.10", "3.11", "3.12"] steps: - uses: actions/checkout@v4 - name: Setup Python @@ -28,8 +23,11 @@ jobs: - name: Install dependencies run: | python -m pip install --upgrade pip + pip install --upgrade importlib-metadata pip install pytest - python -m install + - name: install xDEVS + run: | + python -m pip install . - name: Test with pytest run: | pytest diff --git a/xdevs/__init__.py b/xdevs/__init__.py index baf4dd9..04cb2d7 100644 --- a/xdevs/__init__.py +++ b/xdevs/__init__.py @@ -1,3 +1,4 @@ +from __future__ import annotations import functools import logging import math diff --git a/xdevs/factory.py b/xdevs/factory.py index 74671c1..49690c6 100644 --- a/xdevs/factory.py +++ b/xdevs/factory.py @@ -1,14 +1,22 @@ from __future__ import annotations import json -from importlib.metadata import entry_points +import sys +from importlib.metadata import entry_points, EntryPoint from typing import ClassVar from xdevs.abc import InputHandler, OutputHandler, Transducer from xdevs.models import Atomic, Component, Port, Coupled +def load_entry_points(group: str) -> list[EntryPoint]: + if sys.version_info < (3, 10): + return entry_points().get(group, []) + else: + return entry_points(group=group) + + class InputHandlers: _plugins: ClassVar[dict[str, type[InputHandler]]] = { - ep.name: ep.load() for ep in entry_points(group='xdevs.input_handlers') + ep.name: ep.load() for ep in load_entry_points('xdevs.input_handlers') } @staticmethod @@ -40,7 +48,7 @@ def create_input_handler(name: str, *args, **kwargs) -> InputHandler: class OutputHandlers: _plugins: ClassVar[dict[str, type[OutputHandler]]] = { - ep.name: ep.load() for ep in entry_points(group='xdevs.output_handlers') + ep.name: ep.load() for ep in load_entry_points('xdevs.output_handlers') } @staticmethod @@ -73,7 +81,7 @@ def create_output_handler(name: str, *args, **kwargs) -> OutputHandler: class Wrappers: _plugins: ClassVar[dict[str, type[Atomic]]] = { - ep.name: ep.load() for ep in entry_points(group='xdevs.wrappers') + ep.name: ep.load() for ep in load_entry_points('xdevs.wrappers') } @staticmethod @@ -91,7 +99,7 @@ def create_wrapper(name: str, *args, **kwargs) -> Atomic: class Transducers: _plugins: ClassVar[dict[str, type[Transducer]]] = { - ep.name: ep.load() for ep in entry_points(group='xdevs.transducers') + ep.name: ep.load() for ep in load_entry_points('xdevs.transducers') } @staticmethod @@ -110,7 +118,7 @@ def create_transducer(name: str, *args, **kwargs) -> Transducer: class Components: """This class creates components from unique identifiers called "component_id".""" _plugins: ClassVar[dict[str, type[Component]]] = { - ep.name: ep.load() for ep in entry_points(group='xdevs.components') + ep.name: ep.load() for ep in load_entry_points('xdevs.components') } @staticmethod diff --git a/xdevs/models.py b/xdevs/models.py index 692cbaa..b859e56 100644 --- a/xdevs/models.py +++ b/xdevs/models.py @@ -29,7 +29,8 @@ def __len__(self) -> int: return sum((len(port) for port in self._bag), len(self._values)) def __str__(self) -> str: - return f'{self.name}<{self.p_type.__name__ if self.p_type is not None else 'None'}>' + p_type = self.p_type.__name__ if self.p_type is not None else 'None' + return f'{self.name}<{p_type}>' def __repr__(self) -> str: return str(self) diff --git a/xdevs/plugins/input_handlers/bad_dependencies.py b/xdevs/plugins/input_handlers/bad_dependencies.py index 6c864c3..8c3c8f2 100644 --- a/xdevs/plugins/input_handlers/bad_dependencies.py +++ b/xdevs/plugins/input_handlers/bad_dependencies.py @@ -1,3 +1,4 @@ +from __future__ import annotations from abc import ABC from xdevs.abc.handler import InputHandler @@ -9,7 +10,8 @@ def __init__(self, **kwargs): :param str handler_type: transducer type. """ super().__init__(**kwargs) - raise ImportError(f'{kwargs.get('handler_type')} input handler specific dependencies are not imported') + handler_type = kwargs['handler_type'] + raise ImportError(f'{handler_type} input handler specific dependencies are not imported') def run(self): pass diff --git a/xdevs/plugins/input_handlers/csv.py b/xdevs/plugins/input_handlers/csv.py index 581614f..b69e24e 100644 --- a/xdevs/plugins/input_handlers/csv.py +++ b/xdevs/plugins/input_handlers/csv.py @@ -1,3 +1,4 @@ +from __future__ import annotations import csv import sys import time diff --git a/xdevs/plugins/input_handlers/function.py b/xdevs/plugins/input_handlers/function.py index 880b0d2..ac09420 100644 --- a/xdevs/plugins/input_handlers/function.py +++ b/xdevs/plugins/input_handlers/function.py @@ -1,3 +1,4 @@ +from __future__ import annotations from xdevs.abc.handler import InputHandler diff --git a/xdevs/plugins/input_handlers/mqtt.py b/xdevs/plugins/input_handlers/mqtt.py index 0cb0e2e..5917942 100644 --- a/xdevs/plugins/input_handlers/mqtt.py +++ b/xdevs/plugins/input_handlers/mqtt.py @@ -1,3 +1,4 @@ +from __future__ import annotations import queue import threading diff --git a/xdevs/plugins/output_handlers/bad_dependencies.py b/xdevs/plugins/output_handlers/bad_dependencies.py index b1fe605..201313d 100644 --- a/xdevs/plugins/output_handlers/bad_dependencies.py +++ b/xdevs/plugins/output_handlers/bad_dependencies.py @@ -1,3 +1,4 @@ +from __future__ import annotations from abc import ABC from xdevs.abc.handler import OutputHandler @@ -9,7 +10,8 @@ def __init__(self, **kwargs): :param str handler_type: transducer type. """ super().__init__(**kwargs) - raise ImportError(f'{kwargs['handler_type']} input handler specific dependencies are not imported') + handler_type = kwargs['handler_type'] + raise ImportError(f'{handler_type} input handler specific dependencies are not imported') def run(self): pass diff --git a/xdevs/plugins/output_handlers/csv.py b/xdevs/plugins/output_handlers/csv.py index 701b0ac..b77d365 100644 --- a/xdevs/plugins/output_handlers/csv.py +++ b/xdevs/plugins/output_handlers/csv.py @@ -1,3 +1,4 @@ +from __future__ import annotations import csv import time from xdevs.abc.handler import OutputHandler diff --git a/xdevs/plugins/output_handlers/mqtt.py b/xdevs/plugins/output_handlers/mqtt.py index a6d6040..70e115a 100644 --- a/xdevs/plugins/output_handlers/mqtt.py +++ b/xdevs/plugins/output_handlers/mqtt.py @@ -1,3 +1,4 @@ +from __future__ import annotations from typing import Callable, Any try: diff --git a/xdevs/plugins/output_handlers/tcp.py b/xdevs/plugins/output_handlers/tcp.py index 1b78f66..a26c019 100644 --- a/xdevs/plugins/output_handlers/tcp.py +++ b/xdevs/plugins/output_handlers/tcp.py @@ -1,3 +1,4 @@ +from __future__ import annotations import time from typing import Any, Callable diff --git a/xdevs/plugins/transducers/bad_dependencies.py b/xdevs/plugins/transducers/bad_dependencies.py index d03cbf2..432c757 100644 --- a/xdevs/plugins/transducers/bad_dependencies.py +++ b/xdevs/plugins/transducers/bad_dependencies.py @@ -1,3 +1,4 @@ +from __future__ import annotations from abc import ABC from xdevs.abc.transducer import Transducer @@ -9,7 +10,8 @@ def __init__(self, **kwargs): :param str transducer_type: transducer type. """ super().__init__(**kwargs) - raise ImportError(f'{kwargs.get('transducer_type')} transducer specific dependencies are not imported') + transducer_type = kwargs['transducer_type'] + raise ImportError(f'{transducer_type} transducer specific dependencies are not imported') def create_known_data_types_map(self): pass diff --git a/xdevs/plugins/wrappers/bad_dependencies.py b/xdevs/plugins/wrappers/bad_dependencies.py index d37c58e..116ad49 100644 --- a/xdevs/plugins/wrappers/bad_dependencies.py +++ b/xdevs/plugins/wrappers/bad_dependencies.py @@ -1,3 +1,4 @@ +from __future__ import annotations from abc import ABC from xdevs.models import Atomic @@ -9,7 +10,8 @@ def __init__(self, **kwargs): :param str wrapper_type: wrapper type. """ super().__init__(**kwargs) - raise ImportError(f'{kwargs['wrapper_type']} wrapper specific dependencies are not installed') + wrapper_type = kwargs['wrapper_type'] + raise ImportError(f'{wrapper_type} wrapper specific dependencies are not installed') def deltint(self): pass diff --git a/xdevs/plugins/wrappers/pypdevs.py b/xdevs/plugins/wrappers/pypdevs.py index 01eb3d2..789577f 100644 --- a/xdevs/plugins/wrappers/pypdevs.py +++ b/xdevs/plugins/wrappers/pypdevs.py @@ -1,3 +1,5 @@ +from __future__ import annotations + try: from pypdevs.DEVS import AtomicDEVS from pypdevs.minimal import AtomicDEVS as AtomicDEVSMin diff --git a/xdevs/sim.py b/xdevs/sim.py index 3e5fa77..36c7115 100644 --- a/xdevs/sim.py +++ b/xdevs/sim.py @@ -4,7 +4,6 @@ import itertools import pickle import logging -import warnings from abc import ABC, abstractmethod from collections import defaultdict