Skip to main content

破晓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.whl
  • poxiaoai-1.0.0.tar.gz

4. 上传到PyPI

4.1 注册PyPI账号

  1. 访问 PyPI官网
  2. 点击"Register"注册账号
  3. 验证邮箱

4.2 创建API Token(推荐)

  1. 登录PyPI
  2. 进入Account Settings → API tokens
  3. 创建新的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

注意事项

  1. 保护授权码:实际项目中不要将授权码硬编码在源码中
  2. 版本管理:每次更新都要修改版本号
  3. 测试充分:上传前务必在本地测试所有功能
  4. 备份凭证:妥善保管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

poxiaoai-0.0.4.tar.gz (11.9 kB view details)

Uploaded Source

Built Distribution

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

poxiaoai-0.0.4-py3-none-any.whl (10.2 kB view details)

Uploaded Python 3

File details

Details for the file poxiaoai-0.0.4.tar.gz.

File metadata

  • Download URL: poxiaoai-0.0.4.tar.gz
  • Upload date:
  • Size: 11.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.16

File hashes

Hashes for poxiaoai-0.0.4.tar.gz
Algorithm Hash digest
SHA256 720008afc65ccf416b725f99722ed334765a2764d57a81a25d50f8624e3649ef
MD5 3fd8e394da9712d88dbfe7cb243892f5
BLAKE2b-256 8f6c664e963e5a71e6ef4eec31486e51a0999ee744c0571f4c7263362495471b

See more details on using hashes here.

File details

Details for the file poxiaoai-0.0.4-py3-none-any.whl.

File metadata

  • Download URL: poxiaoai-0.0.4-py3-none-any.whl
  • Upload date:
  • Size: 10.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.16

File hashes

Hashes for poxiaoai-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 603ea89033ed3ab8f45c5fcc099c38534161b6ca324205ead65a8370fafad688
MD5 20fccfaa908923ed6cd691d3fe2861b9
BLAKE2b-256 d6d34ff757b8d273386b38001655e95ab36b24ba6024a54b5ea30184bb6369ca

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