yonbip-skill-utils 1.0.1__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.
@@ -0,0 +1,6 @@
1
+ Metadata-Version: 2.1
2
+ Name: yonbip-skill-utils
3
+ Version: 1.0.1
4
+ Summary: yonbip的技能脚本工具包
5
+ Author-email: yanglih <yanglih@yonyou.com>
6
+ Requires-Python: >=3.8
@@ -0,0 +1,43 @@
1
+ # yonbip-skill-utils-python
2
+
3
+
4
+
5
+ ## 首次使用需安装打包工具
6
+ 安装打包工具:打开终端,执行这行命令安装打包依赖:
7
+ ```
8
+ pip install build twine
9
+ ```
10
+ ## 生成可安装的包文件
11
+ 进入项目根目录,执行命令:
12
+ ```
13
+ python -m build
14
+ ```
15
+ 执行完会生文件夹:dist/;里面有 .tar.gz 和 .whl 文件(这就是打包好的包)
16
+
17
+ 重新build时记得删除dist中的文件。
18
+
19
+ ## 发布
20
+ ### 1、本地发布(用于测试)
21
+ ```
22
+ # 卸载旧版本(如果有)
23
+ pip uninstall yonbip_skill_utils -y
24
+
25
+ # 本地安装测试
26
+ pip install .
27
+
28
+ # py代码中导入包测试
29
+ from yonbip_skill_utils import requests as yonbip_requests
30
+ ```
31
+ ### 2、发布到 PyPI(全球 pip 可安装)
32
+
33
+ (1)修改pyproject.toml中的version后重新build,否则会报“ERROR HTTPError: 400 Bad Request”。
34
+
35
+ (2)上传包到 PyPI终端执行:
36
+ ```
37
+ twine upload dist/*
38
+ ```
39
+ 其他人安装包最新版本的命令:
40
+ ```
41
+ pip install --upgrade yonbip-skill-utils
42
+ ```
43
+
@@ -0,0 +1,20 @@
1
+ [build-system]
2
+ # 固定写法,指定打包工具
3
+ requires = ["setuptools>=61.0"]
4
+ build-backend = "setuptools.build_meta"
5
+
6
+ [project]
7
+ # 包名(别人pip install 这个名字)
8
+ name = "yonbip-skill-utils"
9
+ # 版本号(每次更新要改)
10
+ version = "1.0.1"
11
+ # 作者信息
12
+ authors = [{ name="yanglih", email="yanglih@yonyou.com" }]
13
+ # 简短描述
14
+ description = "yonbip的技能脚本工具包"
15
+ # 依赖包(如果你的代码需要别人依赖包,如requests,就写这里)
16
+ dependencies = [
17
+ # "requests>=2.25.0", # 示例
18
+ ]
19
+ # Python版本要求
20
+ requires-python = ">=3.8"
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,64 @@
1
+ import logging
2
+ import logging.handlers
3
+ from typing import Optional
4
+ import os
5
+
6
+ # 定义包的根 Logger 名称
7
+ PACKAGE_LOGGER_NAME = "yonbip_skill"
8
+ _LOG_CONFIGURED = False
9
+ # 日志文件保存路径(默认在用户当前目录的 logs 文件夹)
10
+ DEFAULT_LOG_FILE = os.path.join(os.getcwd(), "logs", f"{PACKAGE_LOGGER_NAME}.log")
11
+
12
+
13
+ def get_package_logger(name: Optional[str] = None, log_file: str = None) -> logging.Logger:
14
+ """
15
+ 获取包的 Logger 实例,同时输出到控制台和文件
16
+ :param name: 子模块名称
17
+ :param log_file: 日志文件路径,默认使用 DEFAULT_LOG_FILE
18
+ :return: 配置好的 Logger
19
+ """
20
+ global _LOG_CONFIGURED
21
+ log_file = log_file or DEFAULT_LOG_FILE
22
+
23
+ # 拼接 Logger 名称
24
+ logger_name = f"{PACKAGE_LOGGER_NAME}.{name}" if name else PACKAGE_LOGGER_NAME
25
+ logger = logging.getLogger(logger_name)
26
+
27
+ if not _LOG_CONFIGURED:
28
+ logger.setLevel(logging.INFO)
29
+ logger.propagate = False # 隔离 root Logger
30
+
31
+ # 1. 定义统一的日志格式
32
+ formatter = logging.Formatter(
33
+ fmt="[%(asctime)s] [%(name)s] [%(levelname)s] %(message)s",
34
+ datefmt="%Y-%m-%d %H:%M:%S"
35
+ )
36
+
37
+ # 2. 控制台 Handler
38
+ # console_handler = logging.StreamHandler()
39
+ # console_handler.setFormatter(formatter)
40
+ # logger.addHandler(console_handler) 禁用控制台输出避免AI捕获导致信息混乱
41
+
42
+ # 3. 文件 Handler
43
+ # 创建日志目录(不存在则自动创建)
44
+ log_dir = os.path.dirname(log_file)
45
+ if not os.path.exists(log_dir):
46
+ os.makedirs(log_dir, exist_ok=True)
47
+
48
+ # 配置文件 Handler:支持按大小分割日志
49
+ file_handler = logging.handlers.RotatingFileHandler(
50
+ filename=log_file,
51
+ maxBytes=10 * 1024 * 1024, # 单个文件最大 10MB
52
+ backupCount=5, # 最多保留 5 个备份文件
53
+ encoding="utf-8" # 防止中文乱码
54
+ )
55
+ file_handler.setFormatter(formatter)
56
+ logger.addHandler(file_handler)
57
+
58
+ _LOG_CONFIGURED = True
59
+
60
+ return logger
61
+
62
+
63
+ # 导出默认 Logger 实例
64
+ logger = get_package_logger()
@@ -0,0 +1,16 @@
1
+ import requests
2
+ from .logging import get_package_logger
3
+
4
+ logger = get_package_logger("utils.requests")
5
+
6
+
7
+ def get(skill_info, url, params=None, **kwargs):
8
+ response = requests.get(url, params=params, **kwargs)
9
+ logger.info(f"response.status_code:{response.status_code}")
10
+ return response
11
+
12
+
13
+ def post(skill_info, url, data=None, json=None, **kwargs):
14
+ response = requests.post(url, data=data, json=json, **kwargs)
15
+ logger.info(f"response.status_code:{response.status_code}")
16
+ return response
@@ -0,0 +1,6 @@
1
+ Metadata-Version: 2.1
2
+ Name: yonbip-skill-utils
3
+ Version: 1.0.1
4
+ Summary: yonbip的技能脚本工具包
5
+ Author-email: yanglih <yanglih@yonyou.com>
6
+ Requires-Python: >=3.8
@@ -0,0 +1,9 @@
1
+ README.md
2
+ pyproject.toml
3
+ yonbip_skill_utils/__init__.py
4
+ yonbip_skill_utils/logging.py
5
+ yonbip_skill_utils/requests.py
6
+ yonbip_skill_utils.egg-info/PKG-INFO
7
+ yonbip_skill_utils.egg-info/SOURCES.txt
8
+ yonbip_skill_utils.egg-info/dependency_links.txt
9
+ yonbip_skill_utils.egg-info/top_level.txt
@@ -0,0 +1 @@
1
+ yonbip_skill_utils