Skip to content

Commit

Permalink
Merge pull request #8 from atumm-ra/refactor-bl
Browse files Browse the repository at this point in the history
Refactor bootloader
  • Loading branch information
omars44 authored Sep 7, 2023
2 parents c3bf24f + f1e3c00 commit 7b6f862
Show file tree
Hide file tree
Showing 24 changed files with 26 additions and 4 deletions.
Empty file modified .github/workflows/ci.yml
100644 → 100755
Empty file.
Empty file modified .github/workflows/release.yml
100644 → 100755
Empty file.
Empty file modified .gitignore
100644 → 100755
Empty file.
Empty file modified LICENSE
100644 → 100755
Empty file.
Empty file modified Makefile
100644 → 100755
Empty file.
Empty file modified README.md
100644 → 100755
Empty file.
Empty file modified buti/__init__.py
100644 → 100755
Empty file.
24 changes: 20 additions & 4 deletions buti/core.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,17 @@ class Bootloader:
see: examples/
"""

def __init__(self, buti_store: Optional[ButiStore] = None) -> None:
_components: Dict[str, BootableComponent] = {}

def __init__(
self,
components: Optional[List[BootableComponent]] = None,
buti_store: Optional[ButiStore] = None,
) -> None:
if components is None:
components = []
self.buti_store = buti_store if buti_store is not None else ButiStore()
self._components: Dict[str, BootableComponent] = {}
self.add_components(components)

def add_component(self, component: BootableComponent) -> None:
self._components[component.__class__.__name__] = component
Expand Down Expand Up @@ -105,9 +113,17 @@ class AsyncBootloader:
Same as Bootloader, see above
"""

def __init__(self, buti_store: Optional[ButiStore] = None) -> None:
_components: Dict[str, AsyncBootableComponent] = {}

def __init__(
self,
components: Optional[List[AsyncBootableComponent]] = None,
buti_store: Optional[ButiStore] = None,
) -> None:
if components is None:
components = []
self.buti_store = buti_store if buti_store is not None else ButiStore()
self._components: Dict[str, AsyncBootableComponent] = {}
self.add_components(components)

def add_component(self, component: AsyncBootableComponent) -> None:
self._components[component.__class__.__name__] = component
Expand Down
Empty file modified docs/images/buti-overview.png
100644 → 100755
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified examples/fastapi_beanie/.env.dist
100644 → 100755
Empty file.
Empty file modified examples/fastapi_beanie/components/__init__.py
100644 → 100755
Empty file.
Empty file modified examples/fastapi_beanie/components/beanie.py
100644 → 100755
Empty file.
Empty file modified examples/fastapi_beanie/components/config.py
100644 → 100755
Empty file.
Empty file modified examples/fastapi_beanie/components/fastapi.py
100644 → 100755
Empty file.
Empty file modified examples/fastapi_beanie/ids.py
100644 → 100755
Empty file.
Empty file modified examples/fastapi_beanie/main.py
100644 → 100755
Empty file.
Empty file modified pdm.lock
100644 → 100755
Empty file.
Empty file modified pyproject.toml
100644 → 100755
Empty file.
Empty file modified scripts/pre-commit
100644 → 100755
Empty file.
Empty file modified tests/__init__.py
100644 → 100755
Empty file.
Empty file modified tests/conftest.py
100644 → 100755
Empty file.
Empty file modified tests/test_async_bootloader.py
100644 → 100755
Empty file.
6 changes: 6 additions & 0 deletions tests/test_bootloader.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ def test_add_components(self):
self.assertTrue(self.bootloader.has_component(components[0]))
self.assertTrue(self.bootloader.has_component(components[1]))

def test_add_components_constructor(self):
components = [MockComponent1(), MockComponent2()]
bootloader = Bootloader(components)
self.assertTrue(bootloader.has_component(components[0]))
self.assertTrue(bootloader.has_component(components[1]))

def test_boot(self):
component = MockComponent1()
component.boot = Mock()
Expand Down
Empty file modified tests/test_store.py
100644 → 100755
Empty file.

0 comments on commit 7b6f862

Please sign in to comment.