Skip to main content

fw-pip-test

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

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

    后端执行:    python publish.py

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

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

常用问题:

0、如何发布任意项目(如:fw-pip-test)?

解:
    1、将本项目的两个文件(setup.py 和 publish.py)复制到任意项目<<根目录>>,
    2、修改项目名(最重要)、版本号、作者、邮箱、一句话描述、项目网址、关键词 等信息,即可发布任意项目。
    3、新增.env 文件,配置 PYPI_API_TOKEN( PyPI 官方令牌,需提前在 PyPI 官网注册账号并生成 API Token,https://pypi.org/account/)        
    4、执行 publish.py 脚本,即可发布项目到 PyPI。

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

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

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

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

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

解:执行 publish.py 脚本。

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

解:在执行了 publish.py 脚本后,点击控制台返回的 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.py

2. 执行上传脚本

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

./publish.py

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

./publish.py --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.py 中 base_version 参数(如改为 "1.1" 则版本从 1.1.0 开始递增)

注意事项

  1. PyPI 包名全网唯一,若 fw-pip-test 已被占用,需修改 setup.py 和 publish.py 中的包名常量
  2. 作者邮箱需与 PyPI 注册邮箱一致,否则上传会失败
  3. 网络异常时,setup.py 中的版本查询逻辑会抛出异常,可临时改为手动指定版本:
    # 在 setup.py 中替换版本自动获取逻辑
    VERSION = "1.0.0"  # 手动指定版本号
    
  4. 若上传失败,优先使用 --debug 模式重新执行,查看详细错误日志(如令牌无效、包名重复、版本重复等)

许可证

该项目基于 MIT 许可证开源,详见项目根目录 LICENSE 文件(若未创建,可参考 MIT 许可证模板)。

Metadata

Release files for fw-pip-test 1.0.18

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for fw-pip-test 1.0.18
File Size Uploaded Provenance Actions
fw_pip_test-1.0.18.tar.gz 9.0 kB Without provenance Details for fw_pip_test-1.0.18.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for fw-pip-test 1.0.18
File Interpreter ABI Platform Actions
fw_pip_test-1.0.18-py3-none-any.whl Python 3 none any Details for fw_pip_test-1.0.18-py3-none-any.whl

Total release size: 14.6 kB

Release files / fw_pip_test-1.0.18.tar.gz

Download URL fw_pip_test-1.0.18.tar.gz
Size 9.0 kB
Tags Source
SHA-256 checksum
How to use checksums
08b8e00bb74fe05aa8d922b8c195b3d8e27a32b73eff7108b280607f79c02c99
BLAKE2b-256 checksum
How to use checksums
988473e84a2363f27eda5935e3031a14e20a7469c523522353ce0ba71f3a8c86
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.5

Release files / fw_pip_test-1.0.18-py3-none-any.whl

Download URL fw_pip_test-1.0.18-py3-none-any.whl
Size 5.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
eed53c678b1d09863e1d877fbef0228580944668d99fa4d5fc5896a3129fc87a
BLAKE2b-256 checksum
How to use checksums
e210944cb2c2dca28b5ed40ea2b86fb42de3f2d3503b811503e43c6c8bff040c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.5

Security for fw-pip-test 1.0.18

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page