Skip to content

Commit b5c770b

Browse files
author
zhangshulin
committed
更新版本至 1.1.7,增强错误处理并优化导入检查逻辑
1 parent 61089e0 commit b5c770b

3 files changed

Lines changed: 13 additions & 5 deletions

File tree

docapi/main.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from docapi.docapi import DocAPI
1010

1111

12-
VERSION = '1.1.6'
12+
VERSION = '1.1.7'
1313

1414

1515
class Main:
@@ -116,7 +116,10 @@ def run():
116116
print(VERSION)
117117
sys.exit(0)
118118

119-
Fire(Main)
119+
try:
120+
Fire(Main)
121+
except Exception as e:
122+
print(f'Error: {e}')
120123

121124

122125
if __name__ == '__main__':

docapi/scanner/scanner_builder.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,15 @@ def build_scanner(app_path, static=False):
88
import_code = ''
99
for line in code.split('\n'):
1010
line = line.strip()
11-
if re.match(r'from .{1,20} import .*|import .*', line):
11+
if re.match(r'from .{1,100} import .*|import .*', line):
1212
import_code += line + '\n'
1313

14-
if import_code.count('flask') > import_code.count('django'):
14+
flask_import_count = import_code.count('flask')
15+
django_import_count = import_code.count('django')
16+
17+
if flask_import_count == 0 and django_import_count == 0:
18+
raise ValueError('This is not a Flask or Django project.')
19+
elif flask_import_count > django_import_count:
1520
if static:
1621
from docapi.scanner.flask_static_scanner import FlaskStaticScanner
1722
return FlaskStaticScanner()

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "docapi"
3-
version = "1.1.6"
3+
version = "1.1.7"
44
description = "DocAPI is a Python package that automatically generates API documentation using LLMs. It currently supports Flask and Django frameworks."
55
authors = ["zhangshulin <zhangslwork@yeah.net>"]
66
license = "Apache-2.0"

0 commit comments

Comments
 (0)