Skip to content

Commit

Permalink
Merge branch 'dev' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
cwichel committed Jan 29, 2022
2 parents 188d86d + f3e8123 commit dd03f38
Show file tree
Hide file tree
Showing 29 changed files with 424 additions and 117 deletions.
30 changes: 15 additions & 15 deletions docs/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,39 +1,39 @@
alabaster==0.7.12
astroid==2.9.0
astroid==2.9.3
atomicwrites==1.4.0
attrs==21.2.0
attrs==21.4.0
babel==2.9.1
certifi==2021.10.8
charset-normalizer==2.0.8
charset-normalizer==2.0.10
colorama==0.4.4
coverage==6.2
coverage==6.3
docutils==0.17.1
idna==3.3
imagesize==1.3.0
importlib-metadata==4.8.2
importlib-metadata==4.10.1
iniconfig==1.1.1
intelhex==2.3.0
isort==5.10.1
jinja2==3.0.3
lazy-object-proxy==1.6.0
lazy-object-proxy==1.7.1
markupsafe==2.0.1
mccabe==0.6.1
mypy-extensions==0.4.3
mypy==0.910
packaging==21.3
platformdirs==2.4.0
platformdirs==2.4.1
pluggy==1.0.0
py==1.11.0
pygments==2.10.0
pylint==2.12.1
pyparsing==3.0.6
pygments==2.11.2
pylint==2.12.2
pyparsing==3.0.7
pyserial==3.5
pytest==6.2.5
pytz==2021.3
requests==2.26.0
requests==2.27.1
snowballstemmer==2.2.0
sphinx-rtd-theme==1.0.0
sphinx==4.3.1
sphinx==4.4.0
sphinxcontrib-applehelp==1.0.2
sphinxcontrib-devhelp==1.0.2
sphinxcontrib-htmlhelp==2.0.0
Expand All @@ -42,7 +42,7 @@ sphinxcontrib-qthelp==1.0.3
sphinxcontrib-serializinghtml==1.1.5
toml==0.10.2
typed-ast==1.4.3
typing-extensions==4.0.0
urllib3==1.26.7
typing-extensions==4.0.1
urllib3==1.26.8
wrapt==1.13.3
zipp==3.6.0
zipp==3.7.0
13 changes: 12 additions & 1 deletion embutils/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,12 @@
__version__ = '0.7.4'
#!/usr/bin/python
# -*- coding: ascii -*-
"""
Embutils module.
:date: 2021
:author: Christian Wiche
:contact: [email protected]
:license: The MIT License (MIT)
"""
# -------------------------------------
__version__ = '0.7.5'
19 changes: 13 additions & 6 deletions embutils/repo/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
from .build import build_cubeide, build_iar
from .version import (
VersionHandler,
AbstractVersionUpdater, AbstractVersionExporter, AbstractVersionStorage,
GitBuildVersionUpdater, CCppVersionExporter, SimpleVersionStorage,
)
#!/usr/bin/python
# -*- coding: ascii -*-
"""
Embutils repository utilities.
:date: 2021
:author: Christian Wiche
:contact: [email protected]
:license: The MIT License (MIT)
"""
# -------------------------------------
from .build import *
from .version import *
12 changes: 11 additions & 1 deletion embutils/repo/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,14 @@
:contact: [email protected]
:license: The MIT License (MIT)
"""

# -------------------------------------
from ..utils.path import TPPath, Path
from ..utils.subprocess import execute


# -->> Tunables <<---------------------


# -->> Definitions <<------------------


Expand Down Expand Up @@ -76,3 +79,10 @@ def build_iar(config: str, project: TPPath,
res = execute(cmd=cmd, pipe=pipe, log=log)
if not pipe and res.returncode:
print(f"Command:\n{cmd}\nFailed with error:\n{res.stderr}")


# -->> Export <<-----------------------
__all__ = [
"build_cubeide",
"build_iar",
]
120 changes: 68 additions & 52 deletions embutils/repo/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
:contact: [email protected]
:license: The MIT License (MIT)
"""
# -------------------------------------

import abc
import datetime as dt
Expand All @@ -22,6 +23,9 @@
from ..utils.version import Version


# -->> Tunables <<---------------------


# -->> Definitions <<------------------
#: Source path
PATH_THIS = Path(os.path.abspath(os.path.dirname(__file__)))
Expand Down Expand Up @@ -149,6 +153,59 @@ def export(self, path: TPPath = os.getcwd(), author: str = "Unknown") -> None:
self.exporter.export(version=self, path=path, author=author)


class CCppVersionExporter(AbstractVersionExporter):
"""
C/C++ Version Exporter.
Implements the logic to export the version number to a C/C++ header file
"""
#: Item print size.
ITEMSIZE = 20
#: Default exported version filename.
FILENAME = "version.h"
#: Supported header file extensions.
SUFFIXES = [".h", ".hpp"]
#: C/C++ header template.
TEMPLATE = PATH_TMPL / "template_version_c.h"

def export(self, version: Version, path: TPPath, author: str = "Unknown") -> None:
"""
Exports the version number to a C/C++ header using a header template.
:param Version version: Version to be exported.
:param TPPath path: Target file path.
:param str author: Exported file owner.
"""
# Check file
path = Path.validate_file(path=path, none_ok=False, default=self.FILENAME)
if path.suffix.lower() not in self.SUFFIXES:
raise FileTypeError(f"Header path doesnt have the right suffix ({self.SUFFIXES}): {path}.")

# Generate header
with path.open(mode="w", encoding="utf-8") as file:
tmpl = self.TEMPLATE.open(mode="r", encoding="utf-8").read()
file.write(tmpl.format(
file=path.name, author=author,
guard=f"_{path.stem}_H_".upper(),
date=f"{dt.datetime.now().strftime('%m/%d/%Y %H:%M:%S')}",
major=self._format(item=version.major),
minor=self._format(item=version.minor),
build=self._format(item=version.build),
version=f"{version}"
))

def _format(self, item: int) -> str:
"""
Formats the version number item.
:param int item: Version item value.
:return: Item entry.
:rtype: str
"""
hexval = f"0x{item:0{closest_multi(ref=len(hex(item)[2:]), base=2)}X}U"
return f"{hexval:{self.ITEMSIZE}s} /* DEC: {str(item):<{self.ITEMSIZE}s} */"


class SimpleVersionStorage(AbstractVersionStorage):
"""
Simple Version Storage.
Expand Down Expand Up @@ -205,59 +262,18 @@ def update(self, version: Version, path: TPPath) -> None:
:param TPPath path: Path in which the repository is initialized.
"""
# Update the build number with the commit number
ret = execute(cmd="git rev-parse --short HEAD", cwd=f"{path}", pipe=False)
ret = execute(cmd="git rev-parse --short HEAD", cwd=path, pipe=False)
ret = (ret.stderr + ret.stdout).lower().strip()
version.build = self.NO_BUILD if ("not a git" in ret) else int(ret, 16)


class CCppVersionExporter(AbstractVersionExporter):
"""
C/C++ Version Exporter.
Implements the logic to export the version number to a C/C++ header file
"""
#: Item print size.
ITEMSIZE = 20
#: Default exported version filename.
FILENAME = "version.h"
#: Supported header file extensions.
SUFFIXES = [".h", ".hpp"]
#: C/C++ header template.
TEMPLATE = PATH_TMPL / "template_version_c.h"

def export(self, version: Version, path: TPPath, author: str = "Unknown") -> None:
"""
Exports the version number to a C/C++ header using a header template.
:param Version version: Version to be exported.
:param TPPath path: Target file path.
:param str author: Exported file owner.
"""
# Check file
path = Path.validate_file(path=path, none_ok=False, default=self.FILENAME)
if path.suffix.lower() not in self.SUFFIXES:
raise FileTypeError(f"Header path doesnt have the right suffix ({self.SUFFIXES}): {path}.")

# Generate header
with path.open(mode="w", encoding="utf-8") as file:
tmpl = self.TEMPLATE.open(mode="r", encoding="utf-8").read()
file.write(tmpl.format(
file=path.name, author=author,
guard=f"_{path.stem}_H_".upper(),
date=f"{dt.datetime.now().strftime('%m/%d/%Y %H:%M:%S')}",
major=self._format(item=version.major),
minor=self._format(item=version.minor),
build=self._format(item=version.build),
version=f"{version}"
))

def _format(self, item: int) -> str:
"""
Formats the version number item.
:param int item: Version item value.
:return: Item entry.
:rtype: str
"""
hexval = f"0x{item:0{closest_multi(ref=len(hex(item)[2:]), base=2)}X}U"
return f"{hexval:{self.ITEMSIZE}s} /* DEC: {str(item):<{self.ITEMSIZE}s} */"
# -->> Export <<-----------------------
__all__ = [
"AbstractVersionExporter",
"AbstractVersionStorage",
"AbstractVersionUpdater",
"VersionHandler",
"CCppVersionExporter",
"SimpleVersionStorage",
"GitBuildVersionUpdater",
]
17 changes: 14 additions & 3 deletions embutils/serial/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
from .device import Device, DeviceList, DeviceScanner
from .stream import Stream, AbstractSerializedStreamCodec
from .interface import Interface
#!/usr/bin/python
# -*- coding: ascii -*-
"""
Embutils serial utilities.
:date: 2021
:author: Christian Wiche
:contact: [email protected]
:license: The MIT License (MIT)
"""
# -------------------------------------
from .device import *
from .stream import *
from .interface import *
16 changes: 14 additions & 2 deletions embutils/serial/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
:contact: [email protected]
:license: The MIT License (MIT)
"""
# -------------------------------------

import threading as th
import typing as tp
Expand All @@ -22,6 +23,9 @@
from ..utils.time import Timer


# -->> Tunables <<---------------------


# -->> Definitions <<------------------


Expand Down Expand Up @@ -267,10 +271,10 @@ def filter(self, port: str = None, dev_id: int = None) -> "DeviceList":
"""
dev_list = self
# Filter by port
if isinstance(port, str):
if port is not None:
dev_list = DeviceList([dev for dev in dev_list if dev.port == port])
# Filter by ID
if isinstance(dev_id, int):
if dev_id is not None:
dev_list = DeviceList([dev for dev in dev_list if dev.id == dev_id])
return dev_list

Expand Down Expand Up @@ -444,3 +448,11 @@ def _scan(self) -> None:
name=f"{self.__class__.__name__}.on_scan_period",
task=self.on_scan_period.emit
))


# -->> Export <<-----------------------
__all__ = [
"Device",
"DeviceList",
"DeviceScanner",
]
11 changes: 11 additions & 0 deletions embutils/serial/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
:contact: [email protected]
:license: The MIT License (MIT)
"""
# -------------------------------------

import time
import typing as tp
Expand All @@ -20,6 +21,9 @@
from .stream import Stream


# -->> Tunables <<---------------------


# -->> Definitions <<------------------
#: CallBack definition. AbstractSerialized -> bool
CBSerialized2Bool = tp.Callable[[AbstractSerialized], bool]
Expand Down Expand Up @@ -195,3 +199,10 @@ def on_received(item: AbstractSerialized) -> None:
state = "Received" if recv else "Timeout"
SDK_LOG.debug(f"Item response: {state} after {tim.elapsed():.03f}[s]")
return recv


# -->> Export <<-----------------------
__all__ = [
"CBSerialized2Bool",
"Interface",
]
11 changes: 11 additions & 0 deletions embutils/serial/stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
:contact: [email protected]
:license: The MIT License (MIT)
"""
# -------------------------------------

import abc
import time
Expand All @@ -21,6 +22,9 @@
from .device import Device


# -->> Tunables <<---------------------


# -->> Definitions <<------------------


Expand Down Expand Up @@ -242,3 +246,10 @@ def _transfer_debug(item: AbstractSerialized, received: bool) -> None:
"""
action = "recv" if received else "sent"
SDK_LOG.debug(f"Item {action}: {item}")


# -->> Export <<-----------------------
__all__ = [
"AbstractSerializedStreamCodec",
"Stream",
]
Loading

0 comments on commit dd03f38

Please sign in to comment.