Skip to main content

fuwenquant 的一个PYPI测试包(包含add_one和helloworld函数)

Project description

fw-pip-test

fuwenquant 的 Python 测试包,包含基础的数值计算和字符串返回函数(仅用于测试 PyPI 包发布流程,适合新手学习包打包/上传全流程)。

第一次使用也请跳这段,直接详细见后面的功能说明 常用步骤(第n次使用时): PIP 包更新 1、更新代码(如修复bug、新增功能等),执行 publish.sh 脚本

    前端使用:   pip install fw-pip-test    

    查看包信息:  pip show fw-pip-test

常用问题:

1、如何修改 pip 包的名称(创建新的 pip包)?

解:在 setup.py 中 setup() 函数修改 PIP包名 参数,如 `PIP包名="fuwenquant-pip-test"`

2、如何修改 pip 包的版本号?

解:一般默认会自动更新版本号,如果 硬要指定,请设置 setup.py中的`版本号` 变量,如 `版本号 = "1.0.2"`。

3、如何发行新包(更新)

解:执行 publish.sh 脚本。

4、如何查看已发行成功的包?

解:在执行了 publish.sh 脚本后,点击控制台返回的 URL
即可查看已发行成功的包。,如:https://pypi.org/project/fw-pip-test/1.0.2/

img.png

5、遇到 发包错误 HTTPError: 403

解:换个包名,再试试(见问题 1)

img_1.png

-----------------------------------------------------------------------------

功能说明

该测试包包含核心基础函数:

  • 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 publish.sh

2. 执行上传脚本

普通模式(默认,简洁输出)

./publish.sh

调试模式(详细日志,便于排查问题)

./publish.sh --debug  # 或 -d

上传脚本特性

  • 自动清理旧打包文件(dist/build/egg-info)
  • 支持动态包名(默认取脚本所在目录名)/手动指定包名
  • 调试模式保留打包产物,非调试模式自动清理
  • 上传失败自动提示排障方案

包使用指南

安装/更新包

# 安装最新版本
pip install fw-pip-test

# 强制更新到最新版本
pip install --upgrade fw-pip-test

基础使用示例

# 导入包内函数
from fw_pip 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.pybase_version 参数(如改为 "1.1" 则版本从 1.1.0 开始递增)

注意事项

  1. PyPI 包名全网唯一,若 fw-pip-test 已被占用,需修改 setup.pypublish.sh 中的包名常量
  2. 作者邮箱需与 PyPI 注册邮箱一致,否则上传会失败
  3. 网络异常时,setup.py 中的版本查询逻辑会抛出异常,可临时改为手动指定版本:
    # 在 setup.py 中替换版本自动获取逻辑
    VERSION = "1.0.0"  # 手动指定版本号
    
  4. 若上传失败,优先使用 --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

fuwen-1.0.1.tar.gz (5.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

fuwen-1.0.1-py3-none-any.whl (4.9 kB view details)

Uploaded Python 3

File details

Details for the file fuwen-1.0.1.tar.gz.

File metadata

  • Download URL: fuwen-1.0.1.tar.gz
  • Upload date:
  • Size: 5.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.11

File hashes

Hashes for fuwen-1.0.1.tar.gz
Algorithm Hash digest
SHA256 1c426637602cce1c6491f8162d926a82ea433b9cadfefd88e3123a957576a903
MD5 de92c349680fa6f1157fc8590d1fab7a
BLAKE2b-256 49480247691444b86593920a76cc67499baa9c3a799f048ee9117112e23a8218

See more details on using hashes here.

File details

Details for the file fuwen-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: fuwen-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 4.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.11

File hashes

Hashes for fuwen-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 3fe12ce2cdb1ba5b5af225342319a97ff7f12b321946ef67ffbf07180897cf41
MD5 c59a367c093b49a5ab3a7749739fa258
BLAKE2b-256 03037e488f88108654b86af2d3d4cfbadde7aa1acabffec439fcf4d160a99e6e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page