Skip to content

Commit

Permalink
setting up CI
Browse files Browse the repository at this point in the history
  • Loading branch information
romancardenas committed May 27, 2024
1 parent c1fd4f6 commit df3a8d3
Show file tree
Hide file tree
Showing 16 changed files with 43 additions and 20 deletions.
14 changes: 6 additions & 8 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -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.7", "3.8", "3.9", "3.10", "3.11", "3.12"]
steps:
- uses: actions/checkout@v4
- name: Setup Python
Expand All @@ -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
1 change: 1 addition & 0 deletions xdevs/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import annotations
import functools
import logging
import math
Expand Down
20 changes: 14 additions & 6 deletions xdevs/factory.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
3 changes: 2 additions & 1 deletion xdevs/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 3 additions & 1 deletion xdevs/plugins/input_handlers/bad_dependencies.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import annotations
from abc import ABC
from xdevs.abc.handler import InputHandler

Expand All @@ -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
1 change: 1 addition & 0 deletions xdevs/plugins/input_handlers/csv.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import annotations
import csv
import sys
import time
Expand Down
1 change: 1 addition & 0 deletions xdevs/plugins/input_handlers/function.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import annotations
from xdevs.abc.handler import InputHandler


Expand Down
1 change: 1 addition & 0 deletions xdevs/plugins/input_handlers/mqtt.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import annotations
import queue
import threading

Expand Down
4 changes: 3 additions & 1 deletion xdevs/plugins/output_handlers/bad_dependencies.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import annotations
from abc import ABC
from xdevs.abc.handler import OutputHandler

Expand All @@ -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
1 change: 1 addition & 0 deletions xdevs/plugins/output_handlers/csv.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import annotations
import csv
import time
from xdevs.abc.handler import OutputHandler
Expand Down
1 change: 1 addition & 0 deletions xdevs/plugins/output_handlers/mqtt.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import annotations
from typing import Callable, Any

try:
Expand Down
1 change: 1 addition & 0 deletions xdevs/plugins/output_handlers/tcp.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import annotations
import time
from typing import Any, Callable

Expand Down
4 changes: 3 additions & 1 deletion xdevs/plugins/transducers/bad_dependencies.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import annotations
from abc import ABC
from xdevs.abc.transducer import Transducer

Expand All @@ -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
Expand Down
4 changes: 3 additions & 1 deletion xdevs/plugins/wrappers/bad_dependencies.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import annotations
from abc import ABC
from xdevs.models import Atomic

Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions xdevs/plugins/wrappers/pypdevs.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

try:
from pypdevs.DEVS import AtomicDEVS
from pypdevs.minimal import AtomicDEVS as AtomicDEVSMin
Expand Down
1 change: 0 additions & 1 deletion xdevs/sim.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import itertools
import pickle
import logging
import warnings

from abc import ABC, abstractmethod
from collections import defaultdict
Expand Down

0 comments on commit df3a8d3

Please sign in to comment.