sanic-api 0.2.6__py3-none-any.whl → 0.2.8__py3-none-any.whl
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.
- sanic_api/config/setting.py +2 -2
- sanic_api/utils.py +2 -2
- {sanic_api-0.2.6.dist-info → sanic_api-0.2.8.dist-info}/METADATA +4 -5
- {sanic_api-0.2.6.dist-info → sanic_api-0.2.8.dist-info}/RECORD +6 -7
- sanic_api/config/base.py +0 -110
- {sanic_api-0.2.6.dist-info → sanic_api-0.2.8.dist-info}/WHEEL +0 -0
- {sanic_api-0.2.6.dist-info → sanic_api-0.2.8.dist-info}/licenses/LICENSE.txt +0 -0
sanic_api/config/setting.py
CHANGED
@@ -1,12 +1,12 @@
|
|
1
|
+
from hs_config import ConfigBase
|
1
2
|
from pydantic import Field
|
2
3
|
|
3
|
-
from sanic_api.config.base import SettingsBase
|
4
4
|
from sanic_api.config.sanic import SanicConfig
|
5
5
|
from sanic_api.config.sanic_api import SanicApiConfig
|
6
6
|
from sanic_api.enum import RunModeEnum
|
7
7
|
|
8
8
|
|
9
|
-
class DefaultSettings(
|
9
|
+
class DefaultSettings(ConfigBase):
|
10
10
|
"""
|
11
11
|
配置类
|
12
12
|
"""
|
sanic_api/utils.py
CHANGED
@@ -75,9 +75,9 @@ def auto_blueprint(sanic_app: Sanic, base_api_module_name: str) -> None:
|
|
75
75
|
|
76
76
|
# 遍历所有__init__.py文件,查找蓝图并创建对应的蓝图组
|
77
77
|
init_files: List[Path] = list(base_api_dir.glob("**/__init__.py"))
|
78
|
-
for
|
78
|
+
for file in reversed(init_files):
|
79
79
|
# 忽略__init__.py
|
80
|
-
init_file: Path =
|
80
|
+
init_file: Path = file.parent
|
81
81
|
# 获取该蓝图所在的模块路径和名称
|
82
82
|
module_path: str = init_file.relative_to(base_api_dir.parent).with_suffix("").as_posix()
|
83
83
|
module_name: str = module_path.replace("/", ".")
|
@@ -1,16 +1,15 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: sanic-api
|
3
|
-
Version: 0.2.
|
3
|
+
Version: 0.2.8
|
4
4
|
Summary: Sanic 框架实用API工具集,拥有自动生成文档、参数校验、配置的导入、日志功能的优化等功能,更好的助力接口的开发
|
5
5
|
License: MIT
|
6
6
|
Author-email: 昊色居士 <xhrtxh@gmail.com>
|
7
|
-
Requires-Python: >=3.8
|
7
|
+
Requires-Python: >=3.8,<3.12
|
8
|
+
Requires-Dist: hs-config>=0.1.0
|
8
9
|
Requires-Dist: loguru>=0.6.0
|
9
10
|
Requires-Dist: orjson>=3.8.6
|
10
|
-
Requires-Dist: pydantic[dotenv]>=1.10.2
|
11
11
|
Requires-Dist: pygments>=2.13.0
|
12
|
-
Requires-Dist: sanic
|
13
|
-
Requires-Dist: sanic>=22.3
|
12
|
+
Requires-Dist: sanic[ext]>=23.6.0
|
14
13
|
Requires-Dist: setuptools>=68.0.0
|
15
14
|
Requires-Dist: ujson>=5.7.0
|
16
15
|
Description-Content-Type: text/markdown
|
@@ -21,10 +21,9 @@ sanic_api/api/handle_exception.py,sha256=Opq18Y1loRfBKtr_UTAyLMLT-C4vORnHFRhHKFN
|
|
21
21
|
sanic_api/api/model.py,sha256=Sd9B1YHHHlmL11xvJuqbDoMvpL7h6qKj82qrAjhbZFk,1032
|
22
22
|
sanic_api/api/validators.py,sha256=TCb0eRfKfTt11HN-x6u7Ci2j6cpH6UKDKGceaKU2TxE,2078
|
23
23
|
sanic_api/config/__init__.py,sha256=O4wPd23Hbm4-i8q0z6k0_BvAPMkCByDByAvJITxYhSk,68
|
24
|
-
sanic_api/config/base.py,sha256=-rrOKptdbMYdFJeDmR3oCnF3Afqy69RsNSnkBgU-BBw,3229
|
25
24
|
sanic_api/config/sanic.py,sha256=BLKJgwsLVJvT1YlmW21FQXEwxSIHAhngu9Zwqe8Qh6M,636
|
26
25
|
sanic_api/config/sanic_api.py,sha256=jIgrlOizjh3eXxiUhQ9RFiG5noAuvjTju27a4mL-xgU,373
|
27
|
-
sanic_api/config/setting.py,sha256=
|
26
|
+
sanic_api/config/setting.py,sha256=oGvqkUhQVbPWhoPLPZ6uVOwwSpw8JWqJtzjvYa4YLFA,719
|
28
27
|
sanic_api/enum.py,sha256=bBbYeys4CHI22sD_My8EIewOOznXb0nQmuIPKzZn-EM,2040
|
29
28
|
sanic_api/logger/__init__.py,sha256=HPUhYmmzI-NHOo6uf8NGmMlSSN3gkGrmUN6TB5Qhxmc,33
|
30
29
|
sanic_api/logger/config.py,sha256=1eEEp3YpoTCywgOeE8OZp4X0ghF4E9W52FBEAlTCVfw,2511
|
@@ -32,8 +31,8 @@ sanic_api/logger/extend.py,sha256=rD7NxUFZE2esPUbpOlYul5ZNnDTjepPsu9iLgZ9JA00,19
|
|
32
31
|
sanic_api/logger/sanic_http.py,sha256=Nl1dM54XLTRO99rmzUbpR_vi-wSN_eK_9pei1kNJ7UE,2102
|
33
32
|
sanic_api/openapi/__init__.py,sha256=_n-pklcQHcaor8WrJMGxc4HYNggZBfe3mmbkCN57fVI,146
|
34
33
|
sanic_api/openapi/openapi.py,sha256=2Y3J8CJeT5LTLJGsQoCS98QGAZcyE3HgRTKWT2LKoao,4147
|
35
|
-
sanic_api/utils.py,sha256=
|
36
|
-
sanic_api-0.2.
|
37
|
-
sanic_api-0.2.
|
38
|
-
sanic_api-0.2.
|
39
|
-
sanic_api-0.2.
|
34
|
+
sanic_api/utils.py,sha256=9dv_FWHb6ynuzoupOvIFPkar5Y0dlrFF977LjKIysHc,3564
|
35
|
+
sanic_api-0.2.8.dist-info/WHEEL,sha256=B19PGBCYhWaz2p_UjAoRVh767nYQfk14Sn4TpIZ-nfU,87
|
36
|
+
sanic_api-0.2.8.dist-info/METADATA,sha256=hORLgaxUiKD_uM7BP2t0wvNzMxwJHbjper4jUFIWTrw,2312
|
37
|
+
sanic_api-0.2.8.dist-info/licenses/LICENSE.txt,sha256=T20w-F8AfuFO9CHy2mSk_An6T9eV4X4rGA01i-gp4M4,1090
|
38
|
+
sanic_api-0.2.8.dist-info/RECORD,,
|
sanic_api/config/base.py
DELETED
@@ -1,110 +0,0 @@
|
|
1
|
-
import json
|
2
|
-
from configparser import ConfigParser
|
3
|
-
from pathlib import Path
|
4
|
-
from typing import Any, Dict, Tuple
|
5
|
-
|
6
|
-
import yaml
|
7
|
-
from pydantic import BaseSettings
|
8
|
-
from pydantic.env_settings import SettingsSourceCallable
|
9
|
-
|
10
|
-
from sanic_api.utils import getpath_by_root
|
11
|
-
|
12
|
-
|
13
|
-
class CustomSettingsSource:
|
14
|
-
"""
|
15
|
-
自定义的配置文件来源基类
|
16
|
-
"""
|
17
|
-
|
18
|
-
def __init__(self, path: Path):
|
19
|
-
self.path = path
|
20
|
-
|
21
|
-
def __repr__(self) -> str:
|
22
|
-
return f"{self.__class__.__name__}(path={self.path!r})"
|
23
|
-
|
24
|
-
|
25
|
-
class JsonSettingsSource(CustomSettingsSource):
|
26
|
-
"""
|
27
|
-
json文件来源导入配置项
|
28
|
-
"""
|
29
|
-
|
30
|
-
def __call__(self, settings: BaseSettings) -> Dict[str, Any]:
|
31
|
-
encoding = settings.__config__.env_file_encoding
|
32
|
-
return json.loads(self.path.read_text(encoding))
|
33
|
-
|
34
|
-
|
35
|
-
class IniSettingsSource(CustomSettingsSource):
|
36
|
-
"""
|
37
|
-
ini文件来源导入配置项
|
38
|
-
"""
|
39
|
-
|
40
|
-
def __call__(self, settings: BaseSettings) -> Dict[str, Any]:
|
41
|
-
encoding = settings.__config__.env_file_encoding
|
42
|
-
parser = ConfigParser()
|
43
|
-
parser.read(self.path, encoding)
|
44
|
-
return getattr(parser, "_sections", {}).get("settings", {})
|
45
|
-
|
46
|
-
|
47
|
-
class YamlSettingsSource(CustomSettingsSource):
|
48
|
-
"""
|
49
|
-
Yaml文件来源导入配置项
|
50
|
-
"""
|
51
|
-
|
52
|
-
def __call__(self, settings: BaseSettings) -> Dict[str, Any]:
|
53
|
-
encoding = settings.__config__.env_file_encoding
|
54
|
-
return yaml.safe_load(self.path.read_text(encoding))
|
55
|
-
|
56
|
-
|
57
|
-
class SettingsBase(BaseSettings):
|
58
|
-
"""
|
59
|
-
项目设置的基类
|
60
|
-
"""
|
61
|
-
|
62
|
-
class Config:
|
63
|
-
root_config_dir = getpath_by_root("../configs")
|
64
|
-
env_file = root_config_dir / ".env"
|
65
|
-
env_file_encoding = "utf-8"
|
66
|
-
env_nested_delimiter = "__"
|
67
|
-
|
68
|
-
@classmethod
|
69
|
-
def customise_sources(
|
70
|
-
cls,
|
71
|
-
init_settings: SettingsSourceCallable,
|
72
|
-
env_settings: SettingsSourceCallable,
|
73
|
-
file_secret_settings: SettingsSourceCallable,
|
74
|
-
) -> Tuple[SettingsSourceCallable, ...]:
|
75
|
-
"""
|
76
|
-
自定义配置来源
|
77
|
-
Args:
|
78
|
-
init_settings: 初始化设置
|
79
|
-
env_settings:环境变量设置
|
80
|
-
file_secret_settings:加密文件设置
|
81
|
-
|
82
|
-
Returns:
|
83
|
-
|
84
|
-
"""
|
85
|
-
# 默认的设置
|
86
|
-
default_settings = {
|
87
|
-
init_settings,
|
88
|
-
env_settings,
|
89
|
-
file_secret_settings,
|
90
|
-
}
|
91
|
-
|
92
|
-
# json 配置文件
|
93
|
-
json_file = cls.root_config_dir / "settings.json"
|
94
|
-
if json_file.exists():
|
95
|
-
json_settings_source = JsonSettingsSource(json_file)
|
96
|
-
default_settings.add(json_settings_source)
|
97
|
-
|
98
|
-
# ini配置文件
|
99
|
-
ini_file = cls.root_config_dir / "settings.ini"
|
100
|
-
if ini_file.exists():
|
101
|
-
ini_settings_source = IniSettingsSource(ini_file)
|
102
|
-
default_settings.add(ini_settings_source)
|
103
|
-
|
104
|
-
# yaml配置文件
|
105
|
-
yaml_file = cls.root_config_dir / "settings.yaml"
|
106
|
-
if yaml_file.exists():
|
107
|
-
yaml_settings_source = YamlSettingsSource(yaml_file)
|
108
|
-
default_settings.add(yaml_settings_source)
|
109
|
-
|
110
|
-
return tuple(default_settings)
|
File without changes
|
File without changes
|