fuwenquant 的第一个测试包(包含add_one和helloworld函数)
Project description
fw-pip-test
fuwenquant 的 Python 测试包,包含基础的数值计算和字符串返回函数(仅用于测试 PyPI 包发布流程,适合新手学习包打包/上传全流程)。
第一次使用也请跳这段,直接详细见后面的功能说明 常用步骤(第n次使用时): PIP 包更新 1、更新代码(如修复bug、新增功能等),执行 upload_pip.sh 脚本
前端使用:
1、pip install fw-pip-test
功能说明
该测试包包含核心基础函数:
add_one(num):接收一个数值,返回数值 +1 的结果helloworld():返回固定字符串 "Hello World (fw-pip-test)"
环境准备
1. 依赖安装
确保本地安装必备工具包:
pip install --upgrade setuptools wheel twine requests packaging
2. 配置 PyPI 令牌
在项目根目录创建 .env 文件,配置 PyPI 官方令牌(需提前在 PyPI 官网 注册账号并生成 API Token):
# .env 文件内容
PYPI_API_TOKEN=your_pypi_api_token_here # 替换为真实的PyPI令牌
包上传流程
1. 赋予脚本执行权限(首次执行)
chmod +x upload_pip.sh
2. 执行上传脚本
普通模式(默认,简洁输出)
./upload_pip.sh
调试模式(详细日志,便于排查问题)
./upload_pip.sh --debug # 或 -d
上传脚本特性
- 自动清理旧打包文件(dist/build/egg-info)
- 支持动态包名(默认取脚本所在目录名)/手动指定包名
- 调试模式保留打包产物,非调试模式自动清理
- 上传失败自动提示排障方案
包使用指南
安装/更新包
# 安装最新版本
pip install fw-pip-test
# 强制更新到最新版本
pip install --upgrade fw-pip-test
基础使用示例
# 导入包内函数
from bin import add_one, helloworld
# 调用 helloworld 函数
print(helloworld()) # 输出:Hello World (fw-pip-test)
# 调用 add_one 函数
result = add_one(99)
print(result) # 输出:100
result2 = add_one(10.5)
print(result2) # 输出:11.5
版本规则
- 版本遵循 语义化版本规范,格式为
主版本.次版本.小版本(如 1.0.0) - 脚本会自动查询 PyPI 上该包的最新版本,自动递增小版本号(首次发布为 1.0.0)
- 若需修改主/次版本,可修改
setup.py中base_version参数(如改为 "1.1" 则版本从 1.1.0 开始递增)
注意事项
- PyPI 包名全网唯一,若
fw-pip-test已被占用,需修改setup.py和upload_pip.sh中的包名常量 - 作者邮箱需与 PyPI 注册邮箱一致,否则上传会失败
- 网络异常时,
setup.py中的版本查询逻辑会抛出异常,可临时改为手动指定版本:# 在 setup.py 中替换版本自动获取逻辑 VERSION = "1.0.0" # 手动指定版本号
- 若上传失败,优先使用
--debug模式重新执行,查看详细错误日志(如令牌无效、包名重复、版本重复等)
许可证
该项目基于 MIT 许可证开源,详见项目根目录 LICENSE 文件(若未创建,可参考 MIT 许可证模板)。
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file fw_pip_test-1.0.1.tar.gz.
File metadata
- Download URL: fw_pip_test-1.0.1.tar.gz
- Upload date:
- Size: 4.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
160bc0b5df2c64af24c4808c7ccdea4d24e54c26c8036c0009d1f2f6ca2def6d
|
|
| MD5 |
7e716ae5389f8ff64a3669f8fd53d2aa
|
|
| BLAKE2b-256 |
7b5b0f9bbb4d0f7ce364e0f38ff446ca7c03119f808568f2a09ed79420cd1962
|
File details
Details for the file fw_pip_test-1.0.1-py3-none-any.whl.
File metadata
- Download URL: fw_pip_test-1.0.1-py3-none-any.whl
- Upload date:
- Size: 4.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3e8c64972962892c0d2cddb342a8b9a5cda96bb141c3241a07bbfd1872a895e3
|
|
| MD5 |
d95f321d03d42c296e015f234f6d0070
|
|
| BLAKE2b-256 |
41cb63a0e3541740e2eb4b73b912268b79eec7b50e848c854dec486a83f3bef1
|