破晓AI工具类
Project description
poxiaoai Python工具包开发与发布指南
项目概述
创建一个名为 poxiaoai 的Python工具包,该包需要授权激活才能使用。
项目结构
poxiaoai-project/
├── setup.py
├── README.md
├── LICENSE
└── poxiaoai/
├── __init__.py
├── auth.py
└── cli.py
1. 创建项目文件
1.1 创建项目目录
mkdir poxiaoai-project
cd poxiaoai-project
mkdir poxiaoai
1.2 创建 poxiaoai/__init__.py
"""
poxiaoai - 需要授权激活的Python工具包
"""
__version__ = "1.0.0"
__author__ = "poxiaoai"
1.3 创建 poxiaoai/auth.py
import os
import json
from pathlib import Path
class ActivationManager:
def __init__(self):
self.config_dir = Path.home() / ".poxiaoai"
self.config_file = self.config_dir / "activation.json"
self.expected_key = "test" # 授权码
def is_activated(self):
"""检查是否已激活"""
if not self.config_file.exists():
return False
try:
with open(self.config_file, 'r') as f:
data = json.load(f)
return data.get('activated', False)
except:
return False
def activate(self, activation_code):
"""激活软件"""
if activation_code.strip() == self.expected_key:
# 创建配置目录
self.config_dir.mkdir(exist_ok=True)
# 保存激活信息
activation_data = {'activated': True}
with open(self.config_file, 'w') as f:
json.dump(activation_data, f)
print("✅ 激活成功!软件功能已解锁。")
return True
else:
print("❌ 激活码错误!请检查后重试。")
return False
# 全局激活管理器
_activation_manager = ActivationManager()
def is_activated():
return _activation_manager.is_activated()
def activate(activation_code):
return _activation_manager.activate(activation_code)
1.4 创建 poxiaoai/cli.py
import argparse
import getpass
import sys
from .auth import activate, is_activated
def main():
parser = argparse.ArgumentParser(description='poxiaoai 工具包')
subparsers = parser.add_subparsers(dest='command', help='可用命令')
# 激活命令
activate_parser = subparsers.add_parser('code', help='输入激活码')
# 状态命令
status_parser = subparsers.add_parser('status', help='查看激活状态')
args = parser.parse_args()
if args.command == 'code':
activation_code = getpass.getpass("请输入激活码: ")
if activate(activation_code):
sys.exit(0)
else:
sys.exit(1)
elif args.command == 'status':
if is_activated():
print("✅ 软件已激活")
else:
print("❌ 软件未激活")
print("请运行 'poxiaoai code' 进行激活")
else:
parser.print_help()
if __name__ == '__main__':
main()
1.5 创建 setup.py
from setuptools import setup, find_packages
with open("README.md", "r", encoding="utf-8") as fh:
long_description = fh.read()
setup(
name="poxiaoai",
version="1.0.0",
author="poxiaoai",
author_email="your_email@example.com",
description="一个需要授权激活的Python工具包",
long_description=long_description,
long_description_content_type="text/markdown",
packages=find_packages(),
classifiers=[
"Development Status :: 4 - Beta",
"Intended Audience :: Developers",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
],
python_requires=">=3.7",
entry_points={
"console_scripts": [
"poxiaoai=poxiaoai.cli:main",
],
},
keywords="tools, utilities, activation",
)
1.6 创建 README.md
# poxiaoai
一个需要授权激活的Python工具包。
## 安装
```bash
pip install poxiaoai
激活
安装后,首先需要激活:
poxiaoai code
然后输入授权码:test
使用
查看激活状态:
poxiaoai status
许可证
MIT License
### 1.7 创建 `LICENSE`
MIT License
Copyright (c) 2024 poxiaoai
Permission is hereby granted...
## 2. 本地测试
### 2.1 安装开发版本
```bash
# 在项目根目录执行
pip install -e .
2.2 测试功能
# 查看帮助
poxiaoai --help
# 查看状态(应该显示未激活)
poxiaoai status
# 激活(输入授权码:test)
poxiaoai code
# 再次查看状态(应该显示已激活)
poxiaoai status
3. 打包项目
3.1 安装打包工具
pip install setuptools wheel twine
3.2 构建包
python setup.py sdist bdist_wheel
这会在 dist/ 目录生成两个文件:
poxiaoai-1.0.0-py3-none-any.whlpoxiaoai-1.0.0.tar.gz
4. 上传到PyPI
4.1 注册PyPI账号
- 访问 PyPI官网
- 点击"Register"注册账号
- 验证邮箱
4.2 创建API Token(推荐)
- 登录PyPI
- 进入Account Settings → API tokens
- 创建新的token,scope选择"Entire account"
4.3 配置PyPI凭证
创建 ~/.pypirc 文件(Linux/Mac)或 %USERPROFILE%\.pypirc(Windows):
[pypi]
username = __token__
password = pypi-你的token内容
4.4 上传包
twine upload dist/*
5. 安装测试
5.1 从PyPI安装
pip install poxiaoai
5.2 测试功能
# 激活
poxiaoai code
# 输入: poxiaoai
# 查看状态
poxiaoai status
6. 版本更新流程
当需要更新版本时:
6.1 修改版本号
在 setup.py 中更新版本号:
version="1.0.1", # 增加版本号
6.2 重新打包
python setup.py sdist bdist_wheel
6.3 上传新版本
twine upload dist/*
常见问题
Q: 上传时遇到"File already exists"错误
A: 需要更新版本号,PyPI不允许重复版本
Q: 激活状态文件在哪里?
A: 在用户主目录的 .poxiaoai/activation.json
Q: 如何重置激活状态?
A: 删除 ~/.poxiaoai/activation.json 文件
Q: 如何卸载包?
A: pip uninstall poxiaoai
注意事项
- 保护授权码:实际项目中不要将授权码硬编码在源码中
- 版本管理:每次更新都要修改版本号
- 测试充分:上传前务必在本地测试所有功能
- 备份凭证:妥善保管PyPI API token
下一步扩展
- 添加更多工具功能
- 实现网络验证授权
- 添加使用期限限制
- 实现更复杂的加密保护
这样就完成了从开发到发布的完整流程!
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 poxiaoai-0.0.3.tar.gz.
File metadata
- Download URL: poxiaoai-0.0.3.tar.gz
- Upload date:
- Size: 9.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.16
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
93fa39797d5d80850d3bbfefc865047f5a3ebbd33a1c97d01d3821709480ed06
|
|
| MD5 |
65b438933302e0e208e7d8db4d2290c8
|
|
| BLAKE2b-256 |
49ae49a3496c633a19f73a3a2bb77816dc7b50b970744d39cdd8b9954ee552e8
|
File details
Details for the file poxiaoai-0.0.3-py3-none-any.whl.
File metadata
- Download URL: poxiaoai-0.0.3-py3-none-any.whl
- Upload date:
- Size: 8.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.16
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c566eca4e2975933f5d4d4d949cf54777e959f599e292ea4de9ee0442e36bae5
|
|
| MD5 |
c662180b8ea049f1a9660c012865c6fa
|
|
| BLAKE2b-256 |
cf55673a9b946d93c02005a0ad0ad301ebd1dc15bbfb6bf6bca23fe49ea4a094
|