fred-framework 1.0.0__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.
Files changed (35) hide show
  1. fred_framework-1.0.0/LICENSE +21 -0
  2. fred_framework-1.0.0/MANIFEST.in +4 -0
  3. fred_framework-1.0.0/PKG-INFO +200 -0
  4. fred_framework-1.0.0/README.md +151 -0
  5. fred_framework-1.0.0/pyproject.toml +63 -0
  6. fred_framework-1.0.0/requirements.txt +39 -0
  7. fred_framework-1.0.0/setup.cfg +4 -0
  8. fred_framework-1.0.0/setup.py +120 -0
  9. fred_framework-1.0.0/src/fred/__init__.py +96 -0
  10. fred_framework-1.0.0/src/fred/common/AliyunSms.py +66 -0
  11. fred_framework-1.0.0/src/fred/common/Blueprints.py +67 -0
  12. fred_framework-1.0.0/src/fred/common/Email.py +23 -0
  13. fred_framework-1.0.0/src/fred/common/Extensions.py +229 -0
  14. fred_framework-1.0.0/src/fred/common/HandleExcetion.py +204 -0
  15. fred_framework-1.0.0/src/fred/common/ImageVerification.py +83 -0
  16. fred_framework-1.0.0/src/fred/common/IoTDBClient.py +718 -0
  17. fred_framework-1.0.0/src/fred/common/PageSchema.py +65 -0
  18. fred_framework-1.0.0/src/fred/common/Response.py +208 -0
  19. fred_framework-1.0.0/src/fred/common/Route.py +129 -0
  20. fred_framework-1.0.0/src/fred/common/SchedulerLog.py +241 -0
  21. fred_framework-1.0.0/src/fred/common/Sqlacodegen.py +106 -0
  22. fred_framework-1.0.0/src/fred/common/Swagger.py +77 -0
  23. fred_framework-1.0.0/src/fred/common/SystemLog.py +81 -0
  24. fred_framework-1.0.0/src/fred/common/Utils.py +773 -0
  25. fred_framework-1.0.0/src/fred/common/WechatLogin.py +97 -0
  26. fred_framework-1.0.0/src/fred/common/__init__.py +3 -0
  27. fred_framework-1.0.0/src/fred/common/font/simfang.ttf +0 -0
  28. fred_framework-1.0.0/src/fred/common/font/simhei.ttf +0 -0
  29. fred_framework-1.0.0/src/fred/common/font/simsun.ttc +0 -0
  30. fred_framework-1.0.0/src/fred/config/Config.py +97 -0
  31. fred_framework-1.0.0/src/fred/config/Logger.py +34 -0
  32. fred_framework-1.0.0/src/fred/config/__init__.py +3 -0
  33. fred_framework-1.0.0/src/fred/install_hook.py +257 -0
  34. fred_framework-1.0.0/src/fred/model/__init__.py +3 -0
  35. fred_framework-1.0.0/src/fred/model/model.py +239 -0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Your Name
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.
@@ -0,0 +1,4 @@
1
+ include README.md
2
+ include LICENSE
3
+ include requirements.txt
4
+ recursive-include fred/common/font *
@@ -0,0 +1,200 @@
1
+ Metadata-Version: 2.4
2
+ Name: fred-framework
3
+ Version: 1.0.0
4
+ Summary: A Flask-based web framework with built-in utilities and extensions
5
+ Home-page: https://github.com/yourusername/fred-framework
6
+ Author: Your Name
7
+ Author-email: Your Name <your.email@example.com>
8
+ License: MIT
9
+ Project-URL: Homepage, https://github.com/yourusername/fred-framework
10
+ Project-URL: Repository, https://github.com/yourusername/fred-framework
11
+ Project-URL: Documentation, https://github.com/yourusername/fred-framework#readme
12
+ Classifier: Development Status :: 3 - Alpha
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: License :: OSI Approved :: MIT License
15
+ Classifier: Operating System :: OS Independent
16
+ Classifier: Programming Language :: Python :: 3
17
+ Classifier: Programming Language :: Python :: 3.8
18
+ Classifier: Programming Language :: Python :: 3.9
19
+ Classifier: Programming Language :: Python :: 3.10
20
+ Classifier: Programming Language :: Python :: 3.11
21
+ Requires-Python: >=3.8
22
+ Description-Content-Type: text/markdown
23
+ License-File: LICENSE
24
+ Requires-Dist: flask>=3.1.2
25
+ Requires-Dist: flask_cors>=6.0.1
26
+ Requires-Dist: flask_jwt_extended>=4.7.1
27
+ Requires-Dist: Pillow>=11.3.0
28
+ Requires-Dist: flask_smorest>=0.46.2
29
+ Requires-Dist: flask_swagger_ui>=5.21.0
30
+ Requires-Dist: cryptography>=44.0.3
31
+ Requires-Dist: requests>=2.32.5
32
+ Requires-Dist: flask_apscheduler>=1.13.1
33
+ Requires-Dist: flask_babelplus>=2.2.0
34
+ Requires-Dist: flask_sqlacodegen>=2.0.0
35
+ Requires-Dist: flask_sqlalchemy>=3.1.1
36
+ Requires-Dist: pymysql>=1.1.2
37
+ Requires-Dist: pytz>=2025.2
38
+ Requires-Dist: flask_mail>=0.10.0
39
+ Requires-Dist: redis>=7.0.0
40
+ Requires-Dist: apache-iotdb>=2.0.5
41
+ Provides-Extra: dev
42
+ Requires-Dist: pytest>=6.0; extra == "dev"
43
+ Requires-Dist: black; extra == "dev"
44
+ Requires-Dist: flake8; extra == "dev"
45
+ Dynamic: author
46
+ Dynamic: home-page
47
+ Dynamic: license-file
48
+ Dynamic: requires-python
49
+
50
+ # Fred Framework
51
+
52
+ Fred是一个基于Flask的Web框架,内置了常用的工具和扩展,帮助开发者快速构建Web应用程序。
53
+
54
+ ## 功能特性
55
+
56
+ - 基于Flask的轻量级Web框架
57
+ - 内置JWT认证支持
58
+ - 数据库ORM支持(SQLAlchemy)
59
+ - Redis集成
60
+ - 邮件发送功能
61
+ - 定时任务调度
62
+ - 国际化支持
63
+ - Swagger API文档
64
+ - 图片验证码生成
65
+ - 阿里云短信服务集成
66
+ - 微信登录集成
67
+ - 数据加密功能
68
+ - 日志系统
69
+
70
+ ## 安装
71
+
72
+ ```bash
73
+ pip install fred
74
+ ```
75
+
76
+ ## 快速开始
77
+
78
+ ```python
79
+ from fred import create_app
80
+
81
+ app = create_app()
82
+
83
+ if __name__ == "__main__":
84
+ app.run(debug=True)
85
+ ```
86
+
87
+ ## 配置
88
+
89
+ 在使用Fred框架前,请根据需要修改`config/Config.py`中的配置项。
90
+
91
+ ## 依赖
92
+
93
+ Fred框架依赖以下第三方库:
94
+
95
+ - Flask >= 3.1.2
96
+ - flask_cors >= 6.0.1
97
+ - flask_jwt_extended >= 4.7.1
98
+ - Pillow >= 11.3.0
99
+ - flask_smorest >= 0.46.2
100
+ - flask_swagger_ui >= 5.21.0
101
+ - cryptography >= 44.0.3
102
+ - requests >= 2.32.5
103
+ - flask_apscheduler >= 1.13.1
104
+ - flask_babelplus >= 2.2.0
105
+ - flask_sqlacodegen >= 2.0.0
106
+ - flask_sqlalchemy >= 3.1.1
107
+ - pymysql >= 1.1.2
108
+ - pytz >= 2025.2
109
+ - flask_mail >= 0.10.0
110
+ - redis >= 7.0.0
111
+
112
+ ## 打包和发布
113
+
114
+ ### 打包项目
115
+
116
+ 使用以下命令来打包项目:
117
+
118
+ ```bash
119
+ # 使用 setuptools 打包
120
+ python setup.py sdist bdist_wheel
121
+
122
+ # 或者使用 build 工具 (推荐)
123
+ pip install build
124
+ python -m build
125
+ ```
126
+
127
+ 打包后的文件将位于 `dist/` 目录下。
128
+
129
+ ### 发布到 PyPI
130
+
131
+ 1. 首先安装 `twine` 工具:
132
+ ```bash
133
+ pip install twine
134
+ ```
135
+
136
+ 2. 上传到 PyPI:
137
+ ```bash
138
+ # 上传到正式 PyPI (需要 PyPI 账户)
139
+ twine upload dist/*
140
+
141
+ # 或上传到测试 PyPI 进行测试
142
+ twine upload --repository testpypi dist/*
143
+ ```
144
+
145
+ ### 本地开发安装
146
+
147
+ 对于本地开发,可以使用以下命令以可编辑模式安装:
148
+
149
+ ```bash
150
+ pip install -e .
151
+ ```
152
+
153
+ 这将创建一个指向源代码的链接,使代码更改无需重新安装即可生效。
154
+
155
+ ## 打包和发布
156
+
157
+ ### 打包项目
158
+
159
+ 使用以下命令来打包项目:
160
+
161
+ ```bash
162
+ # 使用 setuptools 打包
163
+ python setup.py sdist bdist_wheel
164
+
165
+ # 或者使用 build 工具 (推荐)
166
+ pip install build
167
+ python -m build
168
+ ```
169
+
170
+ 打包后的文件将位于 `dist/` 目录下。
171
+
172
+ ### 发布到 PyPI
173
+
174
+ 1. 首先安装 `twine` 工具:
175
+ ```bash
176
+ pip install twine
177
+ ```
178
+
179
+ 2. 上传到 PyPI:
180
+ ```bash
181
+ # 上传到正式 PyPI (需要 PyPI 账户)
182
+ twine upload dist/*
183
+
184
+ # 或上传到测试 PyPI 进行测试
185
+ twine upload --repository testpypi dist/*
186
+ ```
187
+
188
+ ### 本地开发安装
189
+
190
+ 对于本地开发,可以使用以下命令以可编辑模式安装:
191
+
192
+ ```bash
193
+ pip install -e .
194
+ ```
195
+
196
+ 这将创建一个指向源代码的链接,使代码更改无需重新安装即可生效。
197
+
198
+ ## 许可证
199
+
200
+ MIT License
@@ -0,0 +1,151 @@
1
+ # Fred Framework
2
+
3
+ Fred是一个基于Flask的Web框架,内置了常用的工具和扩展,帮助开发者快速构建Web应用程序。
4
+
5
+ ## 功能特性
6
+
7
+ - 基于Flask的轻量级Web框架
8
+ - 内置JWT认证支持
9
+ - 数据库ORM支持(SQLAlchemy)
10
+ - Redis集成
11
+ - 邮件发送功能
12
+ - 定时任务调度
13
+ - 国际化支持
14
+ - Swagger API文档
15
+ - 图片验证码生成
16
+ - 阿里云短信服务集成
17
+ - 微信登录集成
18
+ - 数据加密功能
19
+ - 日志系统
20
+
21
+ ## 安装
22
+
23
+ ```bash
24
+ pip install fred
25
+ ```
26
+
27
+ ## 快速开始
28
+
29
+ ```python
30
+ from fred import create_app
31
+
32
+ app = create_app()
33
+
34
+ if __name__ == "__main__":
35
+ app.run(debug=True)
36
+ ```
37
+
38
+ ## 配置
39
+
40
+ 在使用Fred框架前,请根据需要修改`config/Config.py`中的配置项。
41
+
42
+ ## 依赖
43
+
44
+ Fred框架依赖以下第三方库:
45
+
46
+ - Flask >= 3.1.2
47
+ - flask_cors >= 6.0.1
48
+ - flask_jwt_extended >= 4.7.1
49
+ - Pillow >= 11.3.0
50
+ - flask_smorest >= 0.46.2
51
+ - flask_swagger_ui >= 5.21.0
52
+ - cryptography >= 44.0.3
53
+ - requests >= 2.32.5
54
+ - flask_apscheduler >= 1.13.1
55
+ - flask_babelplus >= 2.2.0
56
+ - flask_sqlacodegen >= 2.0.0
57
+ - flask_sqlalchemy >= 3.1.1
58
+ - pymysql >= 1.1.2
59
+ - pytz >= 2025.2
60
+ - flask_mail >= 0.10.0
61
+ - redis >= 7.0.0
62
+
63
+ ## 打包和发布
64
+
65
+ ### 打包项目
66
+
67
+ 使用以下命令来打包项目:
68
+
69
+ ```bash
70
+ # 使用 setuptools 打包
71
+ python setup.py sdist bdist_wheel
72
+
73
+ # 或者使用 build 工具 (推荐)
74
+ pip install build
75
+ python -m build
76
+ ```
77
+
78
+ 打包后的文件将位于 `dist/` 目录下。
79
+
80
+ ### 发布到 PyPI
81
+
82
+ 1. 首先安装 `twine` 工具:
83
+ ```bash
84
+ pip install twine
85
+ ```
86
+
87
+ 2. 上传到 PyPI:
88
+ ```bash
89
+ # 上传到正式 PyPI (需要 PyPI 账户)
90
+ twine upload dist/*
91
+
92
+ # 或上传到测试 PyPI 进行测试
93
+ twine upload --repository testpypi dist/*
94
+ ```
95
+
96
+ ### 本地开发安装
97
+
98
+ 对于本地开发,可以使用以下命令以可编辑模式安装:
99
+
100
+ ```bash
101
+ pip install -e .
102
+ ```
103
+
104
+ 这将创建一个指向源代码的链接,使代码更改无需重新安装即可生效。
105
+
106
+ ## 打包和发布
107
+
108
+ ### 打包项目
109
+
110
+ 使用以下命令来打包项目:
111
+
112
+ ```bash
113
+ # 使用 setuptools 打包
114
+ python setup.py sdist bdist_wheel
115
+
116
+ # 或者使用 build 工具 (推荐)
117
+ pip install build
118
+ python -m build
119
+ ```
120
+
121
+ 打包后的文件将位于 `dist/` 目录下。
122
+
123
+ ### 发布到 PyPI
124
+
125
+ 1. 首先安装 `twine` 工具:
126
+ ```bash
127
+ pip install twine
128
+ ```
129
+
130
+ 2. 上传到 PyPI:
131
+ ```bash
132
+ # 上传到正式 PyPI (需要 PyPI 账户)
133
+ twine upload dist/*
134
+
135
+ # 或上传到测试 PyPI 进行测试
136
+ twine upload --repository testpypi dist/*
137
+ ```
138
+
139
+ ### 本地开发安装
140
+
141
+ 对于本地开发,可以使用以下命令以可编辑模式安装:
142
+
143
+ ```bash
144
+ pip install -e .
145
+ ```
146
+
147
+ 这将创建一个指向源代码的链接,使代码更改无需重新安装即可生效。
148
+
149
+ ## 许可证
150
+
151
+ MIT License
@@ -0,0 +1,63 @@
1
+ [build-system]
2
+ requires = ["setuptools>=45", "wheel"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "fred-framework"
7
+ version = "1.0.0"
8
+ authors = [
9
+ {name = "Your Name", email = "your.email@example.com"},
10
+ ]
11
+ description = "A Flask-based web framework with built-in utilities and extensions"
12
+ readme = "README.md"
13
+ license = {text = "MIT"}
14
+ requires-python = ">=3.8"
15
+ classifiers = [
16
+ "Development Status :: 3 - Alpha",
17
+ "Intended Audience :: Developers",
18
+ "License :: OSI Approved :: MIT License",
19
+ "Operating System :: OS Independent",
20
+ "Programming Language :: Python :: 3",
21
+ "Programming Language :: Python :: 3.8",
22
+ "Programming Language :: Python :: 3.9",
23
+ "Programming Language :: Python :: 3.10",
24
+ "Programming Language :: Python :: 3.11",
25
+ ]
26
+ dependencies = [
27
+ "flask>=3.1.2",
28
+ "flask_cors>=6.0.1",
29
+ "flask_jwt_extended>=4.7.1",
30
+ "Pillow>=11.3.0",
31
+ "flask_smorest>=0.46.2",
32
+ "flask_swagger_ui>=5.21.0",
33
+ "cryptography>=44.0.3",
34
+ "requests>=2.32.5",
35
+ "flask_apscheduler>=1.13.1",
36
+ "flask_babelplus>=2.2.0",
37
+ "flask_sqlacodegen>=2.0.0",
38
+ "flask_sqlalchemy>=3.1.1",
39
+ "pymysql>=1.1.2",
40
+ "pytz>=2025.2",
41
+ "flask_mail>=0.10.0",
42
+ "redis>=7.0.0",
43
+ "apache-iotdb>=2.0.5",
44
+ ]
45
+
46
+ [project.optional-dependencies]
47
+ dev = ["pytest>=6.0", "black", "flake8"]
48
+
49
+ [project.urls]
50
+ Homepage = "https://github.com/yourusername/fred-framework"
51
+ Repository = "https://github.com/yourusername/fred-framework"
52
+ Documentation = "https://github.com/yourusername/fred-framework#readme"
53
+
54
+ [project.scripts]
55
+ fred-run = "fred:main"
56
+
57
+ [tool.setuptools.packages.find]
58
+ where = ["src"]
59
+ include = ["fred*"]
60
+ namespaces = false
61
+
62
+ [tool.setuptools.package-data]
63
+ fred = ["common/font/*"]
@@ -0,0 +1,39 @@
1
+ # Fred Framework Dependencies
2
+ #
3
+ # This file lists the dependencies required by the Fred Framework.
4
+ # These dependencies are also defined in setup.py and pyproject.toml.
5
+ # Use this file for development purposes or when installing with pip install -r requirements.txt
6
+
7
+ #-------------------以下是必须的包----------------
8
+ # Flask 是一个轻量级的 WSGI 网络应用框架,用于快速构建 Web 应用程序
9
+ flask>=3.1.2
10
+ # 解决跨域资源共享(CORS)问题,使得前端可以跨域请求后端API
11
+ flask_cors>=6.0.1
12
+ # 提供对 JSON Web Tokens (JWT) 的支持,用于实现用户认证和授权
13
+ flask_jwt_extended>=4.7.1
14
+ # Python Imaging Library (PIL) 的一个分支,提供了图像处理能力
15
+ Pillow>=11.3.0
16
+ # 为 Flask 提供 API 版本控制、分组和 OpenAPI 文档生成功能
17
+ flask_smorest>=0.46.2
18
+ # swagger_ui
19
+ flask_swagger_ui>=5.21.0
20
+ # 提供了低级别的加密原语和高级别的加密库,用于数据安全
21
+ cryptography>=44.0.3
22
+ requests>=2.32.5
23
+ # 为 Flask 应用添加 APScheduler 定时任务功能,允许开发者设置周期性执行的任务
24
+ flask_apscheduler>=1.13.1
25
+ # 扩展 Flask 的国际化和本地化支持,方便多语言网站开发
26
+ flask_babelplus>=2.2.0
27
+ # 根据数据库结构生成 SQLAlchemy 模型代码,加速开发过程
28
+ flask_sqlacodegen>=2.0.0
29
+ # Flask 的 SQLAlchemy 扩展,简化了数据库操作
30
+ flask_sqlalchemy>=3.1.1
31
+ # MySQL 数据库的纯 Python 驱动,用于与 MySQL 数据库交互
32
+ pymysql>=1.1.2
33
+ # 提供世界时区定义、转换和 daylight savings 时间调整
34
+ pytz>=2025.2
35
+ # 为 Flask 应用添加邮件发送功能,简化电子邮件的发送过程
36
+ flask_mail>=0.10.0
37
+ # Flask 的 Redis 扩展,简化了与 Redis 数据库的连接和操作
38
+ redis>=7.0.0
39
+ #-------------------以下是可选包----------------
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,120 @@
1
+ from setuptools import setup, find_packages
2
+ from setuptools.command.install import install
3
+ from setuptools.command.egg_info import egg_info
4
+ import sys
5
+ import os
6
+ from pathlib import Path
7
+
8
+ # 读取README.md内容
9
+ with open("README.md", "r", encoding="utf-8") as fh:
10
+ long_description = fh.read()
11
+
12
+ # 读取requirements.txt内容
13
+ with open("requirements.txt", "r", encoding="utf-8") as fh:
14
+ requirements = [line.strip() for line in fh.readlines() if line.strip() and not line.startswith("#")]
15
+
16
+
17
+ class EggInfoCommand(egg_info):
18
+ """
19
+ 自定义 egg_info 命令,将 egg-info 目录生成到项目根目录而不是 src 目录
20
+ """
21
+ def initialize_options(self):
22
+ egg_info.initialize_options(self)
23
+ # 设置 egg_base 为项目根目录(setup.py 所在目录)
24
+ self.egg_base = os.path.dirname(os.path.abspath(__file__))
25
+
26
+
27
+ class PostInstallCommand(install):
28
+ """
29
+ 安装后执行的自定义命令
30
+ 在项目根目录创建必要的目录结构
31
+ """
32
+ def _find_project_root(self):
33
+ """
34
+ 查找项目根目录(包含 setup.py 或 run.py 的目录)
35
+ """
36
+ # 从当前工作目录开始查找
37
+ current = Path.cwd()
38
+
39
+ # 检查当前目录是否是项目根目录
40
+ if (current / 'setup.py').exists() or (current / 'run.py').exists():
41
+ return current
42
+
43
+ # 向上查找,最多查找 5 层
44
+ for _ in range(5):
45
+ if (current / 'setup.py').exists() or (current / 'run.py').exists():
46
+ return current
47
+ parent = current.parent
48
+ if parent == current: # 已到达根目录
49
+ break
50
+ current = parent
51
+
52
+ # 如果找不到,返回当前工作目录
53
+ return Path.cwd()
54
+
55
+ def run(self):
56
+ # 执行标准安装
57
+ install.run(self)
58
+
59
+ # 执行安装后操作
60
+ try:
61
+ # 导入安装钩子函数
62
+ from fred.install_hook import create_project_directories
63
+
64
+ # 查找项目根目录
65
+ project_root = self._find_project_root()
66
+
67
+ # 切换到项目根目录执行
68
+ original_cwd = os.getcwd()
69
+ try:
70
+ os.chdir(project_root)
71
+ print(f'\n正在项目根目录创建目录结构: {project_root}')
72
+ create_project_directories()
73
+ finally:
74
+ os.chdir(original_cwd)
75
+
76
+ except Exception as e:
77
+ # 安装后操作失败不应该影响安装本身
78
+ print(f'\n警告: 执行安装后操作时出错: {e}', file=sys.stderr)
79
+ print('提示: 你可以手动运行以下命令创建目录结构:', file=sys.stderr)
80
+ print(' python3 -c "from fred.install_hook import create_project_directories; create_project_directories()"', file=sys.stderr)
81
+
82
+
83
+ setup(
84
+ name="fred-framework",
85
+ version="1.0.0",
86
+ author="Your Name",
87
+ author_email="your.email@example.com",
88
+ description="A Flask-based web framework with built-in utilities and extensions",
89
+ long_description=long_description,
90
+ long_description_content_type="text/markdown",
91
+ url="https://github.com/yourusername/fred-framework", # 请替换为实际的仓库地址
92
+ packages=find_packages(where="src"),
93
+ package_dir={"": "src"},
94
+ classifiers=[
95
+ "Development Status :: 3 - Alpha",
96
+ "Intended Audience :: Developers",
97
+ "License :: OSI Approved :: MIT License",
98
+ "Operating System :: OS Independent",
99
+ "Programming Language :: Python :: 3",
100
+ "Programming Language :: Python :: 3.8",
101
+ "Programming Language :: Python :: 3.9",
102
+ "Programming Language :: Python :: 3.10",
103
+ "Programming Language :: Python :: 3.11",
104
+ ],
105
+ python_requires=">=3.8",
106
+ install_requires=requirements,
107
+ entry_points={
108
+ "console_scripts": [
109
+ "fred-run=fred:main",
110
+ ],
111
+ },
112
+ include_package_data=True,
113
+ package_data={
114
+ "fred": ["common/font/*"],
115
+ },
116
+ cmdclass={
117
+ 'egg_info': EggInfoCommand,
118
+ 'install': PostInstallCommand,
119
+ },
120
+ )
@@ -0,0 +1,96 @@
1
+ import importlib
2
+ import os
3
+ from pathlib import Path
4
+
5
+ from flask import Flask
6
+ from flask_cors import CORS
7
+
8
+ from fred.common.Blueprints import Blueprints
9
+ from fred.common.Extensions import Extensions
10
+ from fred.common.HandleExcetion import HandleException
11
+ from fred.common.Response import Response
12
+ from fred.common.Route import Route
13
+ from fred.common.Swagger import Swagger
14
+ from fred.common.Utils import Utils
15
+ from fred.config.Config import Config
16
+ from fred.config.Logger import Logger
17
+
18
+ # 用于标记是否已经尝试创建目录,避免重复执行
19
+ _initialized = False
20
+
21
+
22
+ def create_app():
23
+ """
24
+ 创建应用
25
+ """
26
+ # 在创建应用时自动创建项目目录结构(仅执行一次)
27
+ global _initialized
28
+ if not _initialized:
29
+ try:
30
+ from fred.install_hook import create_project_directories
31
+ # 获取项目根目录(当前工作目录)
32
+ project_root = Path.cwd()
33
+ # 检查是否是项目根目录(有 run.py 或 setup.py)
34
+ if (project_root / 'run.py').exists() or (project_root / 'setup.py').exists():
35
+ # 检查是否已经创建过(通过检查 config/Config.py 是否存在)
36
+ if not (project_root / 'config' / 'Config.py').exists():
37
+ create_project_directories()
38
+ except Exception:
39
+ # 安装钩子执行失败不应该影响应用创建
40
+ pass
41
+ finally:
42
+ _initialized = True
43
+
44
+ app = Flask(__name__)
45
+
46
+ app.config.from_object(Config)
47
+
48
+ app.config['SECRET_KEY'] = Utils.get_secret_key('session_secret_key')
49
+ if app.config['ENCRYPT_DATA']: # 如果启用数据加密才生成fernet_key
50
+ app.config['FERNET_KEY'] = Utils.get_secret_key('fernet_key')
51
+ try:
52
+ config_module = importlib.import_module('config.Config')
53
+ Custom_Config = getattr(config_module, 'Config')
54
+ config_msg = "加载自定义Config,自定义配置会覆盖默认配置"
55
+ app.config.from_object(Custom_Config)
56
+ except (ImportError, AttributeError) as e:
57
+ # 可以选择记录日志或者静默跳过
58
+ config_msg = "没有配置自定义Config"
59
+ # 配置app.logger
60
+ Logger.set_logger(app)
61
+
62
+ app.logger.debug(config_msg)
63
+ # 初始化组件
64
+ Extensions(app).initialize_extensions()
65
+
66
+ # 注册蓝图
67
+ Blueprints(app).register_blueprints()
68
+
69
+ # 设置默认路由 后端和swagger
70
+ Route(app).set_routes()
71
+
72
+ # 启用 swagger
73
+ Swagger(app)
74
+ # 全局异常处理
75
+ HandleException(app)
76
+ # 重新定义模板文件路径
77
+
78
+ # 自定义输出格式
79
+ Response().custom_response(app)
80
+
81
+ if app.debug:
82
+ CORS(app, supports_credentials=True)
83
+
84
+ return app
85
+
86
+
87
+ def main():
88
+ """
89
+ 主函数,用于启动应用
90
+ """
91
+ app = create_app()
92
+ app.run()
93
+
94
+
95
+ if __name__ == '__main__':
96
+ main()