Skip to content

Commit

Permalink
[internal] Fallback für fehlendes typing Modul in Micropython hinzuge…
Browse files Browse the repository at this point in the history
…fügt

Micropython bietet kein typing Modul (ist in Arbeit, siehe
micropython/micropython-lib#584). Stattdessen wird ein
Mock Type benutzt.

CUST-234
  • Loading branch information
jkatins committed May 31, 2023
1 parent ab21716 commit 8e405e2
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 2 deletions.
11 changes: 11 additions & 0 deletions bec2format/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
# Micropython does not provide a typing module, let's use a mock instead
try:
import typing
except ImportError:
import sys

from . import typing_mock

sys.modules["typing"] = typing_mock


from .bec2file import (
CONFIG_SECURITY_CODE_SIZE,
Bec2File,
Expand Down
16 changes: 16 additions & 0 deletions bec2format/typing_mock.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
class _TypeMock:
def __getitem__(self, item):
return self

def __or__(self, other):
return self

def __ror__(self, other):
return self


_typeMock = _TypeMock()


def __getattr__(name):
return _typeMock
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,10 @@
"bec2format/bec2format/hwcids.py",
"github:baltech-ag/bec2format/bec2format/hwcids.py"
],
[
"bec2format/bec2format/typing_mock.py",
"github:baltech-ag/bec2format/bec2format/typing_mock.py"
],
[
"bec2format/bec2format/__init__.py",
"github:baltech-ag/bec2format/bec2format/__init__.py"
Expand Down
3 changes: 2 additions & 1 deletion tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ def lint(ctx: Context, fix: bool = False) -> None:
sys.exit(1)


@task
@task()
def build_mip_package_json(ctx: Context) -> None:
"""builds the package.json for micropython's package manager mip"""
repo = "github:baltech-ag/bec2format"
project_name, project_version = (
ctx.run("poetry version", hide="out").stdout.strip().rsplit(" ", maxsplit=2)
Expand Down
3 changes: 2 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ description = Run invoke
deps =
invoke===2.0.0
poetry==1.4.2
commands_pre = python -m invoke install
commands_pre =
python -m invoke install
commands =
python -m invoke {posargs}

0 comments on commit 8e405e2

Please sign in to comment.