improve project structure for api
This commit is contained in:
parent
1a0f3726d8
commit
7fa9867a38
7 changed files with 42 additions and 11 deletions
9
.envrc.dist
Normal file
9
.envrc.dist
Normal file
|
|
@ -0,0 +1,9 @@
|
||||||
|
# integrate this into your own .envrc file with `source_env .envrc.dist`
|
||||||
|
|
||||||
|
watch_file api/pyproject.toml \
|
||||||
|
api/uv.lock
|
||||||
|
|
||||||
|
export UV_PROJECT=$(realpath ./api)
|
||||||
|
uv venv --allow-existing
|
||||||
|
uv sync
|
||||||
|
|
||||||
5
.gitignore
vendored
Normal file
5
.gitignore
vendored
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
.envrc
|
||||||
|
.direnv/
|
||||||
|
|
||||||
|
**/__pycache__
|
||||||
|
api/dist
|
||||||
10
README.md
10
README.md
|
|
@ -9,3 +9,13 @@ Project structure:
|
||||||
├── api # Python application interacting with HomeMatic and providing the API.
|
├── api # Python application interacting with HomeMatic and providing the API.
|
||||||
└── app # Web UI
|
└── app # Web UI
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## API Development
|
||||||
|
|
||||||
|
Most things should automatically be set up with the included [direnv script](./.envrc.dist) but if you don't use that, take the following steps:
|
||||||
|
|
||||||
|
1. Go to the api/ directory
|
||||||
|
2. Run `uv venv` to create a python virtual environment
|
||||||
|
3. Install all dependencies of the dooris project into that virtual environment with `uv sync`
|
||||||
|
4. Run a development server `uv run uvicorn dooris_api:app --reload`
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,3 +8,12 @@ dependencies = [
|
||||||
"simple-openid-connect>=2.4.0",
|
"simple-openid-connect>=2.4.0",
|
||||||
"uvicorn>=0.46.0",
|
"uvicorn>=0.46.0",
|
||||||
]
|
]
|
||||||
|
classifiers = ["Private :: Do Not Upload"]
|
||||||
|
|
||||||
|
[project.scripts]
|
||||||
|
"dooris-api" = "dooris_api:main"
|
||||||
|
|
||||||
|
[build-system]
|
||||||
|
requires = ["flit_core >=3.11,<5"]
|
||||||
|
build-backend = "flit_core.buildapi"
|
||||||
|
|
||||||
|
|
|
||||||
8
api/src/dooris_api/__init__.py
Normal file
8
api/src/dooris_api/__init__.py
Normal file
|
|
@ -0,0 +1,8 @@
|
||||||
|
from dooris_api.app import app
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
import uvicorn
|
||||||
|
config = uvicorn.Config(app, port=8000, log_level="info")
|
||||||
|
server = uvicorn.Server(config)
|
||||||
|
server.run()
|
||||||
10
api/main.py → api/src/dooris_api/app.py
Executable file → Normal file
10
api/main.py → api/src/dooris_api/app.py
Executable file → Normal file
|
|
@ -53,13 +53,3 @@ async def login_callback(req: Request, resp: Response):
|
||||||
else:
|
else:
|
||||||
return {"authenticated": False}
|
return {"authenticated": False}
|
||||||
|
|
||||||
|
|
||||||
def main():
|
|
||||||
import uvicorn
|
|
||||||
config = uvicorn.Config(app, port=8000, log_level="info")
|
|
||||||
server = uvicorn.Server(config)
|
|
||||||
server.run()
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
main()
|
|
||||||
2
api/uv.lock
generated
2
api/uv.lock
generated
|
|
@ -233,7 +233,7 @@ wheels = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "dooris-api"
|
name = "dooris-api"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = { virtual = "." }
|
source = { editable = "." }
|
||||||
dependencies = [
|
dependencies = [
|
||||||
{ name = "fastapi" },
|
{ name = "fastapi" },
|
||||||
{ name = "simple-openid-connect" },
|
{ name = "simple-openid-connect" },
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue