Skip to content

Commit

Permalink
fix parse pyi failed error in maixcam platform if no pyi file generated
Browse files Browse the repository at this point in the history
  • Loading branch information
Neutree committed May 7, 2024
1 parent fd285b3 commit 72006b3
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
3 changes: 3 additions & 0 deletions components/maix/gen_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ def update_py_def_from_stub_files(api_tree, stub):
maix_pyi_root = os.path.join(stub, "maix", "_maix")
for k, v in api_tree["members"]["maix"]["members"].items():
def parse_module(pyi_path, k, v):
if not os.path.exists(pyi_path):
print(f"[WARN] can not find {pyi_path}, you can build for linux platform first to generate this file")
return
items = parse_pyi(pyi_path)
for m_k, m_v in v["members"].items():
if m_v["type"] == "func":
Expand Down
11 changes: 8 additions & 3 deletions project.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def get_sdk_path():

# 1. get SDK absolute path from MAIXCDK_PATH env
try:
if os.environ[sdk_env_name] and os.path.exists(os.environ[sdk_env_name]):
if os.environ[sdk_env_name]:
sdk_path = os.environ[sdk_env_name]
except Exception:
pass
Expand All @@ -29,9 +29,14 @@ def get_sdk_path():
sdk_path = path

# 3. check if MaixCDK path valid
if not sdk_path or not os.path.exists(sdk_path):
if not sdk_path:
print("")
print("Error: can not find MaixCDK, please set MAIXCDK_PATH env to MaixCDK directory")
print("Error: can not find MaixCDK, please set MAIXCDK_PATH env to MaixCDK directory by `export MAIXCDK_PATH=xxxxx`")
print("")
sys.exit(1)
if not os.path.exists(sdk_path):
print("")
print(f"Error: MaixCDK set to {sdk_path}, but not exists!")
print("")
sys.exit(1)
return os.path.abspath(sdk_path)
Expand Down
5 changes: 4 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,10 @@ def get_python_version():

# generate api documentation
# COMMAND ${python} -u ${CMAKE_CURRENT_SOURCE_DIR}/gen_api.py -o ${maixpy_wrapper_src} --doc ${PROJECT_PATH}/docs/api --sdk_path ${SDK_PATH}
maixcdk_path = os.environ.get("MAIXCDK_PATH", None)
maixcdk_path = os.path.abspath(os.environ.get("MAIXCDK_PATH", None))
maixpy_path = os.path.abspath(os.getcwd())
if maixcdk_path.startswith(maixpy_path):
raise Exception("DO NOT put MaixCDK in MaixPy folder, please put MaixCDK in other place and set MAIXCDK_PATH environmenet variable by `export MAIXCDK_PATH=xxxxx`")
if not maixcdk_path:
raise Exception("No environment variable MAIXCDK_PATH, please set first by `export MAIXCDK_PATH=xxxxx`")
ret = os.system(f"python -u components/maix/gen_api.py --doc docs/api --sdk_path {maixcdk_path}")
Expand Down

0 comments on commit 72006b3

Please sign in to comment.