Skip to main content

A successful sign for python setup

Project description

NeverLib

一个用于音频处理和VAD(语音活动检测)的Python工具库.

安装

基本安装

pip install neverlib

安装带有VAD功能的版本

pip install neverlib[vad]

安装带有GPU支持的版本

pip install neverlib[gpu]

安装所有功能

pip install neverlib[all]

开发环境配置

Pre-commit 代码格式化

本项目使用 pre-commit 在 git commit 时自动格式化 Python 代码.

安装步骤(首次开发时执行一次):

# 1. 安装 pre-commit 工具
pip install pre-commit

# 2. 在仓库中安装 git hooks
cd /data01/never/Desktop/neverlib
pre-commit install

工作方式

安装后,每次执行 git commit 时会自动执行以下任务:

1. 代码格式化(autopep8)

  • ✅ 自动修复空格问题(a+ba + b
  • ✅ 自动修复缩进问题(统一 4 空格)
  • ✅ 自动修复空行问题(函数间 2 个空行)
  • ✅ 删除行尾空格
  • ✅ 长行自动换行(最大 150 字符)

2. 自动生成 __init__.py 文件

  • ✅ 当 neverlib/ 目录下的 .py 文件有变化时自动触发
  • ✅ 扫描所有子包,提取模块导出项(包括全大写常量,如 EPS
  • ✅ 生成懒加载版本的 __init__.py(支持 IDE 补全)
  • ✅ 智能跳过:只在内容真的改变时才写入文件

正确的提交工作流

# 1. 添加修改的文件
git add your_files

# 2. 第一次提交(可能失败,这是正常的)
git commit -m "your message"

# 3. 如果 pre-commit 提示 "files were modified by this hook"
#    说明文件被自动格式化了,需要重新添加
git add -u  # 添加所有已跟踪文件的修改

# 4. 再次提交(通常会成功)
git commit -m "your message"

说明

  • git add -u 只添加已跟踪文件的修改,不会误添加新文件(如 .env、密钥等)
  • 如果第二次提交仍然失败,检查是否有语法错误或其他问题
  • pre-commit 修改文件是为了确保代码风格一致,这是正常行为

手动检查所有文件(可选):

pre-commit run --all-files

配置文件位于 .pre-commit-config.yaml.

使用示例

import neverlib

# 使用VAD功能
from neverlib import vad

# 使用工具函数
from neverlib import utils

# 发送邮件
from neverlib.message import seed_QQEmail

发布到 PyPI

1. 配置 PyPI 认证(首次发布)

创建 ~/.pypirc 文件(用户 home 目录下):

[distutils]
index-servers =
    pypi
    testpypi

[pypi]
repository = https://upload.pypi.org/legacy/
username = __token__
password = pypi-AgEI...你的token...

[testpypi]
repository = https://test.pypi.org/legacy/
username = __token__
password = pypi-AgEI...你的token...

设置文件权限:

chmod 600 ~/.pypirc

获取 PyPI Token

  1. 登录 PyPITestPyPI
  2. 进入 Account settings → API tokens
  3. 创建新 token,复制到 ~/.pypirc

2. 更新版本号

编辑 pyproject.toml,更新 version 字段:

[project]
name = "neverlib"
version = "x.y.z"  # 修改这里

版本号规范:

  • 补丁版本(Bug 修复):0.3.10.3.2
  • 次版本(新功能):0.3.20.4.0
  • 主版本(重大变更):0.4.01.0.0

3. 构建发布包

# 安装构建工具(首次需要)
pip install build twine

# 清理旧的构建文件
rm -rf dist/ build/ *.egg-info

# 构建源码包和wheel包
python -m build

4. 上传到 PyPI

先上传到 TestPyPI 测试(推荐):

python -m twine upload --repository testpypi dist/*

测试安装:

pip install --index-url https://test.pypi.org/simple/ neverlib

确认无误后,上传到正式 PyPI

python -m twine upload dist/*

5. 验证发布

# 等待几分钟后
pip install --upgrade neverlib

# 验证版本
python -c "import neverlib; print(neverlib.__version__)"

常见问题

Q: 提示 "File already exists" A: 该版本号已存在,需要更新 setup.py 中的版本号

Q: 提示 "Invalid or non-existent authentication" A: 检查 ~/.pypirc 中的 token 是否正确

Q: 上传时需要输入密码 A: 确认 ~/.pypirc 在用户 home 目录(~/.pypirc),而不是项目目录

TODO List

许可证

本项目采用MIT许可证. 详情请参阅LICENSE文件.

作者

凌逆战 | Never

博客:https://www.cnblogs.com/LXP-Never

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

neverlib-0.3.1.tar.gz (11.7 MB view details)

Uploaded Source

Built Distribution

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

neverlib-0.3.1-py3-none-any.whl (11.8 MB view details)

Uploaded Python 3

File details

Details for the file neverlib-0.3.1.tar.gz.

File metadata

  • Download URL: neverlib-0.3.1.tar.gz
  • Upload date:
  • Size: 11.7 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.13

File hashes

Hashes for neverlib-0.3.1.tar.gz
Algorithm Hash digest
SHA256 55bb855bde521b907fc3799c573d54721e7324f21488d798e0cfc54ad13ef8b7
MD5 29ae0164bc5b21b358deb72b4f77a341
BLAKE2b-256 02d08fe2a4b589d5396e40bbf5e29fc6305f2d3f48378f8298012fd2d62ec7ff

See more details on using hashes here.

File details

Details for the file neverlib-0.3.1-py3-none-any.whl.

File metadata

  • Download URL: neverlib-0.3.1-py3-none-any.whl
  • Upload date:
  • Size: 11.8 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.13

File hashes

Hashes for neverlib-0.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 03badedfbc847d186470ff8185de84f575d1a92e8f0af4ada0980d7371662a1e
MD5 cb8073d963411be313991463a11aad45
BLAKE2b-256 1e6c19b2dbc60947063c6d814fa1133ce438b49f59c9cb48725877bdd68f1b0a

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