engin 0.0.dev1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- engin-0.0.dev1/.github/workflows/publish.yaml +27 -0
- engin-0.0.dev1/.gitignore +165 -0
- engin-0.0.dev1/LICENSE +21 -0
- engin-0.0.dev1/PKG-INFO +6 -0
- engin-0.0.dev1/README.md +0 -0
- engin-0.0.dev1/examples/asgi/__init__.py +0 -0
- engin-0.0.dev1/examples/asgi/app.py +34 -0
- engin-0.0.dev1/examples/asgi/common/__init__.py +0 -0
- engin-0.0.dev1/examples/asgi/common/db/__init__.py +0 -0
- engin-0.0.dev1/examples/asgi/common/db/adapaters/__init__.py +0 -0
- engin-0.0.dev1/examples/asgi/common/db/adapaters/memory.py +17 -0
- engin-0.0.dev1/examples/asgi/common/db/block.py +9 -0
- engin-0.0.dev1/examples/asgi/common/db/ports.py +13 -0
- engin-0.0.dev1/examples/asgi/common/starlette/__init__.py +0 -0
- engin-0.0.dev1/examples/asgi/common/starlette/endpoint.py +47 -0
- engin-0.0.dev1/examples/asgi/features/__init__.py +0 -0
- engin-0.0.dev1/examples/asgi/features/cats/__init__.py +0 -0
- engin-0.0.dev1/examples/asgi/features/cats/api/__init__.py +0 -0
- engin-0.0.dev1/examples/asgi/features/cats/api/get.py +32 -0
- engin-0.0.dev1/examples/asgi/features/cats/api/post.py +26 -0
- engin-0.0.dev1/examples/asgi/features/cats/block.py +45 -0
- engin-0.0.dev1/examples/asgi/features/cats/domain.py +17 -0
- engin-0.0.dev1/examples/asgi/main.py +15 -0
- engin-0.0.dev1/examples/simple/__init__.py +0 -0
- engin-0.0.dev1/examples/simple/main.py +19 -0
- engin-0.0.dev1/pyproject.toml +38 -0
- engin-0.0.dev1/src/engin/__init__.py +21 -0
- engin-0.0.dev1/src/engin/_assembler.py +126 -0
- engin-0.0.dev1/src/engin/_block.py +36 -0
- engin-0.0.dev1/src/engin/_dependency.py +162 -0
- engin-0.0.dev1/src/engin/_engin.py +89 -0
- engin-0.0.dev1/src/engin/_exceptions.py +19 -0
- engin-0.0.dev1/src/engin/_lifecycle.py +21 -0
- engin-0.0.dev1/src/engin/_type_utils.py +65 -0
- engin-0.0.dev1/src/engin/extensions/__init__.py +0 -0
- engin-0.0.dev1/src/engin/extensions/asgi.py +55 -0
- engin-0.0.dev1/src/engin/py.typed +0 -0
- engin-0.0.dev1/tests/__init__.py +0 -0
- engin-0.0.dev1/tests/conftest.py +0 -0
- engin-0.0.dev1/tests/deps.py +37 -0
- engin-0.0.dev1/tests/test_assembler.py +27 -0
- engin-0.0.dev1/tests/test_dependencies.py +47 -0
- engin-0.0.dev1/tests/test_engin.py +75 -0
- engin-0.0.dev1/tests/test_modules.py +19 -0
- engin-0.0.dev1/tests/test_utils.py +62 -0
- engin-0.0.dev1/uv.lock +424 -0
@@ -0,0 +1,27 @@
|
|
1
|
+
name: Publish
|
2
|
+
|
3
|
+
on:
|
4
|
+
workflow_dispatch:
|
5
|
+
|
6
|
+
jobs:
|
7
|
+
publish-to-pypi:
|
8
|
+
name: python
|
9
|
+
runs-on: ubuntu-latest
|
10
|
+
|
11
|
+
permissions:
|
12
|
+
id-token: write
|
13
|
+
|
14
|
+
steps:
|
15
|
+
- uses: actions/checkout@v4
|
16
|
+
|
17
|
+
- name: Install uv
|
18
|
+
uses: astral-sh/setup-uv@v3
|
19
|
+
|
20
|
+
- name: Set up Python
|
21
|
+
run: uv python install
|
22
|
+
|
23
|
+
- name: Build the Project
|
24
|
+
run: uv build
|
25
|
+
|
26
|
+
- name: Publish
|
27
|
+
run: uv publish
|
@@ -0,0 +1,165 @@
|
|
1
|
+
# Byte-compiled / optimized / DLL files
|
2
|
+
__pycache__/
|
3
|
+
*.py[cod]
|
4
|
+
*$py.class
|
5
|
+
|
6
|
+
# C extensions
|
7
|
+
*.so
|
8
|
+
|
9
|
+
# Distribution / packaging
|
10
|
+
.Python
|
11
|
+
build/
|
12
|
+
develop-eggs/
|
13
|
+
dist/
|
14
|
+
downloads/
|
15
|
+
eggs/
|
16
|
+
.eggs/
|
17
|
+
lib/
|
18
|
+
lib64/
|
19
|
+
parts/
|
20
|
+
sdist/
|
21
|
+
var/
|
22
|
+
wheels/
|
23
|
+
share/python-wheels/
|
24
|
+
*.egg-info/
|
25
|
+
.installed.cfg
|
26
|
+
*.egg
|
27
|
+
MANIFEST
|
28
|
+
|
29
|
+
# PyInstaller
|
30
|
+
# Usually these files are written by a python script from a template
|
31
|
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
32
|
+
*.manifest
|
33
|
+
*.spec
|
34
|
+
|
35
|
+
# Installer logs
|
36
|
+
pip-log.txt
|
37
|
+
pip-delete-this-directory.txt
|
38
|
+
|
39
|
+
# Unit test / coverage reports
|
40
|
+
htmlcov/
|
41
|
+
.tox/
|
42
|
+
.nox/
|
43
|
+
.coverage
|
44
|
+
.coverage.*
|
45
|
+
.cache
|
46
|
+
nosetests.xml
|
47
|
+
coverage.xml
|
48
|
+
*.cover
|
49
|
+
*.py,cover
|
50
|
+
.hypothesis/
|
51
|
+
.pytest_cache/
|
52
|
+
cover/
|
53
|
+
|
54
|
+
# Translations
|
55
|
+
*.mo
|
56
|
+
*.pot
|
57
|
+
|
58
|
+
# Django stuff:
|
59
|
+
*.log
|
60
|
+
local_settings.py
|
61
|
+
db.sqlite3
|
62
|
+
db.sqlite3-journal
|
63
|
+
|
64
|
+
# Flask stuff:
|
65
|
+
instance/
|
66
|
+
.webassets-cache
|
67
|
+
|
68
|
+
# Scrapy stuff:
|
69
|
+
.scrapy
|
70
|
+
|
71
|
+
# Sphinx documentation
|
72
|
+
docs/_build/
|
73
|
+
|
74
|
+
# PyBuilder
|
75
|
+
.pybuilder/
|
76
|
+
target/
|
77
|
+
|
78
|
+
# Jupyter Notebook
|
79
|
+
.ipynb_checkpoints
|
80
|
+
|
81
|
+
# IPython
|
82
|
+
profile_default/
|
83
|
+
ipython_config.py
|
84
|
+
|
85
|
+
# pyenv
|
86
|
+
# For a library or package, you might want to ignore these files since the code is
|
87
|
+
# intended to run in multiple environments; otherwise, check them in:
|
88
|
+
# .python-version
|
89
|
+
|
90
|
+
# pipenv
|
91
|
+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
92
|
+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
93
|
+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
94
|
+
# install all needed dependencies.
|
95
|
+
#Pipfile.lock
|
96
|
+
|
97
|
+
# poetry
|
98
|
+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
|
99
|
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
100
|
+
# commonly ignored for libraries.
|
101
|
+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
|
102
|
+
#poetry.lock
|
103
|
+
|
104
|
+
# pdm
|
105
|
+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
|
106
|
+
#pdm.lock
|
107
|
+
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
|
108
|
+
# in version control.
|
109
|
+
# https://pdm.fming.dev/latest/usage/project/#working-with-version-control
|
110
|
+
.pdm.toml
|
111
|
+
.pdm-python
|
112
|
+
.pdm-build/
|
113
|
+
|
114
|
+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
|
115
|
+
__pypackages__/
|
116
|
+
|
117
|
+
# Celery stuff
|
118
|
+
celerybeat-schedule
|
119
|
+
celerybeat.pid
|
120
|
+
|
121
|
+
# SageMath parsed files
|
122
|
+
*.sage.py
|
123
|
+
|
124
|
+
# Environments
|
125
|
+
.env
|
126
|
+
.venv
|
127
|
+
env/
|
128
|
+
venv/
|
129
|
+
ENV/
|
130
|
+
env.bak/
|
131
|
+
venv.bak/
|
132
|
+
|
133
|
+
# Spyder project settings
|
134
|
+
.spyderproject
|
135
|
+
.spyproject
|
136
|
+
|
137
|
+
# Rope project settings
|
138
|
+
.ropeproject
|
139
|
+
|
140
|
+
# mkdocs documentation
|
141
|
+
/site
|
142
|
+
|
143
|
+
# mypy
|
144
|
+
.mypy_cache/
|
145
|
+
.dmypy.json
|
146
|
+
dmypy.json
|
147
|
+
|
148
|
+
# Pyre type checker
|
149
|
+
.pyre/
|
150
|
+
|
151
|
+
# pytype static type analyzer
|
152
|
+
.pytype/
|
153
|
+
|
154
|
+
# Cython debug symbols
|
155
|
+
cython_debug/
|
156
|
+
|
157
|
+
# Python local version specifier
|
158
|
+
.python-version
|
159
|
+
|
160
|
+
# PyCharm
|
161
|
+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
162
|
+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
163
|
+
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
164
|
+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
165
|
+
.idea/
|
engin-0.0.dev1/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2024 Tim OSullivan
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
engin-0.0.dev1/PKG-INFO
ADDED
engin-0.0.dev1/README.md
ADDED
File without changes
|
File without changes
|
@@ -0,0 +1,34 @@
|
|
1
|
+
from pydantic_settings import BaseSettings
|
2
|
+
from starlette.applications import Starlette
|
3
|
+
from starlette.endpoints import HTTPEndpoint
|
4
|
+
from starlette.requests import Request
|
5
|
+
from starlette.responses import JSONResponse, Response
|
6
|
+
from starlette.routing import Mount, Route
|
7
|
+
|
8
|
+
from engin import Block, invoke, provide
|
9
|
+
from engin.extensions.asgi import ASGIType
|
10
|
+
|
11
|
+
|
12
|
+
class AppConfig(BaseSettings):
|
13
|
+
debug: bool = False
|
14
|
+
|
15
|
+
|
16
|
+
class HealthCheckEndpoint(HTTPEndpoint):
|
17
|
+
async def get(self, _: Request) -> Response:
|
18
|
+
return JSONResponse({"ok": True})
|
19
|
+
|
20
|
+
|
21
|
+
class AppBlock(Block):
|
22
|
+
@provide
|
23
|
+
def app_factory(
|
24
|
+
self, routes: list[Route], mounts: list[Mount], app_config: AppConfig
|
25
|
+
) -> ASGIType:
|
26
|
+
return Starlette(routes=[*routes, *mounts], debug=app_config.debug)
|
27
|
+
|
28
|
+
@provide
|
29
|
+
def default_routes(self) -> list[Route]:
|
30
|
+
return [Route("/health", HealthCheckEndpoint)]
|
31
|
+
|
32
|
+
@provide
|
33
|
+
def default_config(self) -> AppConfig:
|
34
|
+
return AppConfig()
|
File without changes
|
File without changes
|
File without changes
|
@@ -0,0 +1,17 @@
|
|
1
|
+
from typing import Any
|
2
|
+
|
3
|
+
from examples.asgi.common.db.ports import DatabaseInterface
|
4
|
+
|
5
|
+
|
6
|
+
class InMemoryDatabase(DatabaseInterface):
|
7
|
+
def __init__(self) -> None:
|
8
|
+
self._data = {}
|
9
|
+
|
10
|
+
def get(self, key: str) -> Any:
|
11
|
+
return self._data.get(key)
|
12
|
+
|
13
|
+
def set(self, key: str, value: Any) -> Any:
|
14
|
+
self._data[key] = value
|
15
|
+
|
16
|
+
def list(self) -> Any:
|
17
|
+
return list(self._data.values())
|
@@ -0,0 +1,9 @@
|
|
1
|
+
from engin import Block, provide
|
2
|
+
from examples.asgi.common.db.adapaters.memory import InMemoryDatabase
|
3
|
+
from examples.asgi.common.db.ports import DatabaseInterface
|
4
|
+
|
5
|
+
|
6
|
+
class DatabaseBlock(Block):
|
7
|
+
@provide
|
8
|
+
def database(self) -> DatabaseInterface:
|
9
|
+
return InMemoryDatabase()
|
@@ -0,0 +1,13 @@
|
|
1
|
+
from abc import ABC, abstractmethod
|
2
|
+
from typing import Any
|
3
|
+
|
4
|
+
|
5
|
+
class DatabaseInterface(ABC):
|
6
|
+
@abstractmethod
|
7
|
+
def get(self, key: str) -> Any: ...
|
8
|
+
|
9
|
+
@abstractmethod
|
10
|
+
def list(self) -> Any: ...
|
11
|
+
|
12
|
+
@abstractmethod
|
13
|
+
def set(self, key: str, value: Any) -> Any: ...
|
File without changes
|
@@ -0,0 +1,47 @@
|
|
1
|
+
from abc import ABC, abstractmethod
|
2
|
+
from collections.abc import Iterable
|
3
|
+
from typing import ClassVar
|
4
|
+
|
5
|
+
from starlette.exceptions import HTTPException
|
6
|
+
from starlette.requests import Request
|
7
|
+
from starlette.responses import PlainTextResponse, Response
|
8
|
+
from starlette.types import Receive, Scope, Send
|
9
|
+
|
10
|
+
|
11
|
+
class Endpoint(ABC):
|
12
|
+
"""
|
13
|
+
Base class for implementing Starlette endpoints in a way that's compatible with DI, as
|
14
|
+
HTTPEndpoint does not allow you to control class initialisation.
|
15
|
+
"""
|
16
|
+
|
17
|
+
ALLOWED_METHODS: ClassVar[Iterable[str]] = (
|
18
|
+
"GET",
|
19
|
+
"HEAD",
|
20
|
+
"POST",
|
21
|
+
"PUT",
|
22
|
+
"PATCH",
|
23
|
+
"DELETE",
|
24
|
+
"OPTIONS",
|
25
|
+
)
|
26
|
+
|
27
|
+
@abstractmethod
|
28
|
+
async def exec(self, request: Request) -> Response: ...
|
29
|
+
|
30
|
+
async def __call__(self, scope: Scope, receive: Receive, send: Send) -> None:
|
31
|
+
request = Request(scope, receive=receive)
|
32
|
+
|
33
|
+
if request.method not in self.ALLOWED_METHODS:
|
34
|
+
response = await self.method_not_allowed(request)
|
35
|
+
else:
|
36
|
+
response = await self.exec(request)
|
37
|
+
|
38
|
+
await response(scope, receive, send)
|
39
|
+
|
40
|
+
async def method_not_allowed(self, request: Request) -> Response:
|
41
|
+
# If we're running inside a starlette application then raise an
|
42
|
+
# exception, so that the configurable exception handler can deal with
|
43
|
+
# returning the response. For plain ASGI apps, just return the response.
|
44
|
+
headers = {"Allow": ", ".join(self.ALLOWED_METHODS)}
|
45
|
+
if "app" in request.scope:
|
46
|
+
raise HTTPException(status_code=405, headers=headers)
|
47
|
+
return PlainTextResponse("Method Not Allowed", status_code=405, headers=headers)
|
File without changes
|
File without changes
|
File without changes
|
@@ -0,0 +1,32 @@
|
|
1
|
+
import json
|
2
|
+
|
3
|
+
from starlette.requests import Request
|
4
|
+
from starlette.responses import JSONResponse, Response
|
5
|
+
|
6
|
+
from examples.asgi.common.db.ports import DatabaseInterface
|
7
|
+
from examples.asgi.common.starlette.endpoint import Endpoint
|
8
|
+
from examples.asgi.features.cats.domain import Cat
|
9
|
+
|
10
|
+
|
11
|
+
class GetCatEndpoint(Endpoint):
|
12
|
+
ALLOWED_METHODS = ("GET",)
|
13
|
+
|
14
|
+
def __init__(self, db: DatabaseInterface) -> None:
|
15
|
+
self._db = db
|
16
|
+
|
17
|
+
async def exec(self, request: Request) -> Response:
|
18
|
+
name = request.path_params.get("name")
|
19
|
+
if name is None:
|
20
|
+
cat_dtos = self._db.list()
|
21
|
+
return JSONResponse(
|
22
|
+
content=[Cat.model_validate(cat_dto).model_dump() for cat_dto in cat_dtos]
|
23
|
+
)
|
24
|
+
|
25
|
+
cat_dto = self._db.get(name)
|
26
|
+
|
27
|
+
if cat_dto is None:
|
28
|
+
return Response(status_code=404)
|
29
|
+
|
30
|
+
cat = Cat.model_validate(cat_dto)
|
31
|
+
|
32
|
+
return JSONResponse(content=cat.model_dump_json())
|
@@ -0,0 +1,26 @@
|
|
1
|
+
from pydantic import ValidationError
|
2
|
+
from starlette.requests import Request
|
3
|
+
from starlette.responses import Response
|
4
|
+
|
5
|
+
from examples.asgi.common.db.ports import DatabaseInterface
|
6
|
+
from examples.asgi.common.starlette.endpoint import Endpoint
|
7
|
+
from examples.asgi.features.cats.domain import Cat
|
8
|
+
|
9
|
+
|
10
|
+
class PostCatEndpoint(Endpoint):
|
11
|
+
ALLOWED_METHODS = ("POST",)
|
12
|
+
|
13
|
+
def __init__(self, db: DatabaseInterface) -> None:
|
14
|
+
self._db = db
|
15
|
+
|
16
|
+
async def exec(self, request: Request) -> Response:
|
17
|
+
cat_dto = await request.json()
|
18
|
+
|
19
|
+
try:
|
20
|
+
cat = Cat.model_validate(cat_dto)
|
21
|
+
except ValidationError:
|
22
|
+
return Response(status_code=422)
|
23
|
+
|
24
|
+
self._db.set(cat.name, cat.model_dump())
|
25
|
+
|
26
|
+
return Response(status_code=204)
|
@@ -0,0 +1,45 @@
|
|
1
|
+
from starlette.routing import Mount, Route
|
2
|
+
|
3
|
+
from engin import Block, provide
|
4
|
+
from examples.asgi.common.db.ports import DatabaseInterface
|
5
|
+
from examples.asgi.features.cats.api.get import GetCatEndpoint
|
6
|
+
from examples.asgi.features.cats.api.post import PostCatEndpoint
|
7
|
+
|
8
|
+
|
9
|
+
class CatBlock(Block):
|
10
|
+
@provide
|
11
|
+
def get_cat_route(self, db: DatabaseInterface) -> GetCatEndpoint:
|
12
|
+
return GetCatEndpoint(db=db)
|
13
|
+
|
14
|
+
@provide
|
15
|
+
def post_cat_route(self, db: DatabaseInterface) -> PostCatEndpoint:
|
16
|
+
return PostCatEndpoint(db=db)
|
17
|
+
|
18
|
+
@provide
|
19
|
+
def mount(
|
20
|
+
self,
|
21
|
+
get_cat_endpoint: GetCatEndpoint,
|
22
|
+
post_cat_endpoint: PostCatEndpoint,
|
23
|
+
) -> list[Mount]:
|
24
|
+
return [
|
25
|
+
Mount(
|
26
|
+
"/cats",
|
27
|
+
routes=[
|
28
|
+
Route(
|
29
|
+
"/{name:str}",
|
30
|
+
get_cat_endpoint,
|
31
|
+
methods=get_cat_endpoint.ALLOWED_METHODS,
|
32
|
+
),
|
33
|
+
Route(
|
34
|
+
"/",
|
35
|
+
get_cat_endpoint,
|
36
|
+
methods=get_cat_endpoint.ALLOWED_METHODS,
|
37
|
+
),
|
38
|
+
Route(
|
39
|
+
"/",
|
40
|
+
post_cat_endpoint,
|
41
|
+
methods=post_cat_endpoint.ALLOWED_METHODS,
|
42
|
+
),
|
43
|
+
],
|
44
|
+
)
|
45
|
+
]
|
@@ -0,0 +1,17 @@
|
|
1
|
+
from enum import Enum
|
2
|
+
|
3
|
+
from pydantic import BaseModel, ConfigDict
|
4
|
+
|
5
|
+
|
6
|
+
class CatPersonality(Enum):
|
7
|
+
CUTE = "CUTE"
|
8
|
+
EVIL = "EVIL"
|
9
|
+
|
10
|
+
|
11
|
+
class Cat(BaseModel):
|
12
|
+
model_config = ConfigDict(use_enum_values=True)
|
13
|
+
|
14
|
+
name: str
|
15
|
+
breed: str
|
16
|
+
age: float
|
17
|
+
personality: CatPersonality
|
@@ -0,0 +1,15 @@
|
|
1
|
+
import logging
|
2
|
+
|
3
|
+
import uvicorn
|
4
|
+
|
5
|
+
from engin import Supply
|
6
|
+
from engin.extensions.asgi import ASGIEngin
|
7
|
+
from examples.asgi.app import AppBlock, AppConfig
|
8
|
+
from examples.asgi.common.db.block import DatabaseBlock
|
9
|
+
from examples.asgi.features.cats.block import CatBlock
|
10
|
+
|
11
|
+
logging.basicConfig(level=logging.DEBUG)
|
12
|
+
|
13
|
+
app = ASGIEngin(AppBlock(), DatabaseBlock(), CatBlock(), Supply(AppConfig(debug=True)))
|
14
|
+
|
15
|
+
uvicorn.run(app)
|
File without changes
|
@@ -0,0 +1,19 @@
|
|
1
|
+
import asyncio
|
2
|
+
|
3
|
+
from httpx import AsyncClient
|
4
|
+
|
5
|
+
from engin import Engin, Invoke, Provide
|
6
|
+
|
7
|
+
|
8
|
+
def new_httpx_client() -> AsyncClient:
|
9
|
+
return AsyncClient()
|
10
|
+
|
11
|
+
|
12
|
+
async def main(http_client: AsyncClient) -> None:
|
13
|
+
res = await http_client.get("https://httpbin.org/get")
|
14
|
+
print(res)
|
15
|
+
|
16
|
+
|
17
|
+
engin = Engin(Provide(new_httpx_client), Invoke(main))
|
18
|
+
|
19
|
+
asyncio.run(engin.run())
|
@@ -0,0 +1,38 @@
|
|
1
|
+
[project]
|
2
|
+
name = "engin"
|
3
|
+
version = "0.0.dev1"
|
4
|
+
description = "An async-first modular application framework"
|
5
|
+
readme = "README.md"
|
6
|
+
requires-python = ">=3.10"
|
7
|
+
dependencies = []
|
8
|
+
|
9
|
+
[build-system]
|
10
|
+
requires = ["hatchling"]
|
11
|
+
build-backend = "hatchling.build"
|
12
|
+
|
13
|
+
[tool.uv]
|
14
|
+
dev-dependencies = [
|
15
|
+
"httpx>=0.27.2",
|
16
|
+
"mypy>=1",
|
17
|
+
"pydantic-settings>=2.6.0",
|
18
|
+
"pydantic>=2.9.2",
|
19
|
+
"pytest-asyncio>=0.24.0",
|
20
|
+
"pytest>=8",
|
21
|
+
"ruff>=0",
|
22
|
+
"starlette>=0.39.2",
|
23
|
+
"uvicorn>=0.31.1",
|
24
|
+
]
|
25
|
+
|
26
|
+
[tool.ruff]
|
27
|
+
line-length = 95
|
28
|
+
target-version = "py310"
|
29
|
+
|
30
|
+
[tool.ruff.lint]
|
31
|
+
select = ["E", "F", "I", "RUF"]
|
32
|
+
ignore = []
|
33
|
+
|
34
|
+
[tool.pytest.ini_options]
|
35
|
+
log_cli = true
|
36
|
+
log_cli_level = "DEBUG"
|
37
|
+
asyncio_mode = "auto"
|
38
|
+
asyncio_default_fixture_loop_scope = "session"
|
@@ -0,0 +1,21 @@
|
|
1
|
+
from engin._assembler import Assembler
|
2
|
+
from engin._block import Block, invoke, provide
|
3
|
+
from engin._dependency import Entrypoint, Invoke, Provide, Supply
|
4
|
+
from engin._engin import Engin, Option
|
5
|
+
from engin._exceptions import AssemblyError
|
6
|
+
from engin._lifecycle import Lifecycle
|
7
|
+
|
8
|
+
__all__ = [
|
9
|
+
"Assembler",
|
10
|
+
"AssemblyError",
|
11
|
+
"Engin",
|
12
|
+
"Entrypoint",
|
13
|
+
"Invoke",
|
14
|
+
"Lifecycle",
|
15
|
+
"Block",
|
16
|
+
"Option",
|
17
|
+
"Provide",
|
18
|
+
"Supply",
|
19
|
+
"invoke",
|
20
|
+
"provide",
|
21
|
+
]
|