Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[flake8]
max-line-length = 120
extend-ignore = W191,E125,E128
exclude =
.git,
__pycache__,
__init__.py,
build,
dist
max-complexity = 5
doctests = True
165 changes: 165 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,169 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
.pybuilder/
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# poetry
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
#poetry.lock

# pdm
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
#pdm.lock
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
# in version control.
# https://pdm.fming.dev/#use-with-ide
.pdm.toml

# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
venv
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# pytype static type analyzer
.pytype/

# Cython debug symbols
cython_debug/
reports

# PyCharm
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
.idea/

run.py

.$**
**.bkp
.idea
dist
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2024 Ivan Ponomarev

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
11 changes: 11 additions & 0 deletions pytest-nocov.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

[pytest]
pythonpath = src
;addopts = -v --cov=src --cov-report=html:reports/html
testpaths =
tests

python_classes = Test*
python_files = Test*

;pytest_plugins = ["pytest-dictsdiff", ]
11 changes: 11 additions & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

[pytest]
pythonpath = src
addopts = -v --cov=src --cov-report=html:reports/html
testpaths =
tests

python_classes = Test*
python_files = Test*

;pytest_plugins = ["pytest-dictsdiff", ]
4 changes: 4 additions & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
-r requirements.txt
pytest
pytest-cov
flake8
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
simputils-config~=1.0
natsort~=8.4
Empty file added src/simputils/__init__.py
Empty file.
137 changes: 137 additions & 0 deletions src/simputils/events/SimpleEvent.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
from datetime import datetime, timezone
from typing import TYPE_CHECKING
from uuid import UUID, uuid1

if TYPE_CHECKING: # pragma: no cover
from simputils.events.types import EventHandlerType


class SimpleEvent:

_event_uid: UUID = None
_name: str = None

_obj_uid: UUID = None

_type: str | None = None
_tags: str | None = None
_data: dict | None = None

_result: dict | None = None

_created_at: datetime = None
_processed_at: datetime = None
_status: bool = None
_priority: int = None

_handler: "EventHandlerType" = None

@property
def handler(self) -> "EventHandlerType":
return self._handler

@property
def priority(self) -> int:
return self._priority

@property
def status(self) -> bool:
return self._status

@status.setter
def status(self, val: bool):
self._status = val

@property
def event_uid(self) -> UUID:
return self._event_uid

@property
def obj_uid(self) -> UUID:
return self._obj_uid

@property
def name(self) -> str:
return self._name

@property
def type(self) -> str:
return self._type

@property
def tags(self) -> str:
return self._tags

@property
def data(self) -> dict:
return self._data

@property
def created_at(self) -> datetime:
return self._created_at

@property
def processed_at(self) -> datetime:
return self._processed_at

@processed_at.setter
def processed_at(self, val: datetime):
self._processed_at = val

@property
def result(self) -> dict:
return self._result

def set_result(self, val: dict):
if self.processed_at is None:
self.processed_at = datetime.now(timezone.utc)
self._result = val

def __str__(self):
return (
f'<{self.__class__.__name__} '
f'name="{self.name}" '
f'type="{self.type}" '
f'tags="{self.tags}" '
f'data="{self.data}" '
f'status="{self.status}" '
f'result="{self.result}" '
f'created_at="{self.created_at}" '
f'processed_at="{self.processed_at}" '
f'handler="{self.handler.__name__}" '
f'obj_uid="{self.obj_uid}" '
f'event_uid="{self.event_uid}">'
)

def __repr__(self):
status = ""
processed_at = ""
result = ""
if self.status is not None:
status = f" of status \"{self.status}\""
if self.processed_at is not None:
processed_at = f" processed at \"{self.processed_at}\""
if self.result:
result = f" with result \"{self.result}\""
return f"Event \"{self.name}\"{status}{processed_at}{result}"

# noinspection PyShadowingBuiltins
def __init__(
self,
name: str,
event_uid: UUID,
handler: "EventHandlerType",
data: dict = None,
priority: int = 0,
type: str = None,
tags: str = None,
):
self._event_uid = event_uid
self._obj_uid = uuid1()
self._handler = handler
self._created_at = datetime.now(timezone.utc)
self._name = name
self._data = data
self._priority = priority
self._type = type
self._tags = tags
11 changes: 11 additions & 0 deletions src/simputils/events/SimpleEventManager.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from simputils.events.auxiliary.RawEventManager import RawEventManager
from simputils.events.auxiliary.SingletonMeta import SingletonMeta

# MARK Redo Singleton from decorator!


class SimpleEventManager(RawEventManager, metaclass=SingletonMeta):
"""
Singleton event-manager
"""
pass
Loading