add python fastapi demo; .gitignore things
This commit is contained in:
parent
8497488cb3
commit
567a999fdc
5 changed files with 29 additions and 0 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -7,3 +7,5 @@ compile_commands.json
|
|||
**/*.swo
|
||||
**/*.swp
|
||||
.vscode/
|
||||
.venv
|
||||
*.pyc
|
||||
|
|
|
@ -13,6 +13,9 @@ add_library(mnode-proto proto/service.proto)
|
|||
target_link_libraries(mnode-proto PUBLIC protobuf::libprotobuf)
|
||||
target_include_directories(mnode-proto PUBLIC ${CMAKE_CURRENT_BINARY_DIR})
|
||||
protobuf_generate(TARGET mnode-proto)
|
||||
#protobuf_generate(TARGET mnode-proto-py LANGUAGE python PROTOS proto/service.proto)
|
||||
protobuf_generate_python(PROTO_PY proto/service.proto)
|
||||
add_custom_target(mnode-proto-py ALL DEPENDS ${PROTO_PY})
|
||||
|
||||
add_subdirectory(external)
|
||||
add_subdirectory(src)
|
||||
|
|
19
python/main.py
Normal file
19
python/main.py
Normal file
|
@ -0,0 +1,19 @@
|
|||
import sys, os
|
||||
sys.path.append(os.path.join(os.path.dirname(sys.path[0]), 'build'))
|
||||
import service_pb2 as pb
|
||||
|
||||
from typing import Union
|
||||
|
||||
from fastapi import FastAPI
|
||||
|
||||
app = FastAPI()
|
||||
|
||||
|
||||
@app.get("/")
|
||||
def read_root():
|
||||
return dir(pb)
|
||||
|
||||
|
||||
@app.get("/items/{item_id}")
|
||||
def read_item(item_id: int, q: Union[str, None] = None):
|
||||
return {"item_id": item_id, "q": q}
|
2
python/requirements.txt
Normal file
2
python/requirements.txt
Normal file
|
@ -0,0 +1,2 @@
|
|||
protobuf
|
||||
fastapi[standard]
|
|
@ -63,5 +63,8 @@ target_compile_options(mesy_nng_sub_consumer PRIVATE ${MVLC_NNG_NODE_WARN_FLAGS}
|
|||
add_executable(mnode-proto-test1 mnode_proto_test1.cc thread_name.cc)
|
||||
target_link_libraries(mnode-proto-test1 PRIVATE mnode-proto PRIVATE mesytec-mvlc PRIVATE nng)
|
||||
|
||||
#add_subdirectory(nng)
|
||||
#add_subdirectory(qt)
|
||||
|
||||
#unset(CMAKE_C_CLANG_TIDY)
|
||||
#unset(CMAKE_CXX_CLANG_TIDY)
|
||||
|
|
Loading…
Reference in a new issue