包结构
准备工作
-
twine 安装
pip3 install twine
-
pypi 账号注册 https://pypi.org/account/register/, 注册成功后,记得到邮箱激活,否则无法使用
三个文件
-
setup.py
import setuptools
with open("README.md", 'r', encoding='utf-8') as f:
long_description = f.read()
with open("requirements.txt", 'r', encoding='utf-8') as f:
requirements = f.read().split()
setuptools.setup(
name="air-df", # pip install name
version="0.0.7", # 版本,每次更新需修改,否则无法上传
author="Damon",
author_email="527439@qq.com",
description="常用插件",
long_description=long_description,
long_description_content_type="text/markdown",
url="https://github.com/Air-df", # git-hup 项目地址, 这里只放了主页地址,这个参数不重要
packages=['air'], # 文件夹名
install_requires=requirements, # 依赖库,发布后,pip install过程中自动安装该参数下的依赖
classifiers=[
"Programming Language :: Python :: 3.9",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
],
py_modules=[ # 打包的具体文件
'air.base_handler', 'air.plugins'
]
)
2.README.md
关于包的介绍
3.LICENSE
证书文件,自己新建,拷贝下面到文件里就ok
Copyright (c) 2018 The Python Packaging Authority
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
两个命令
在包根目录下执行
- 打包
python setup.py sdist bdist_wheel
- 发布到pypi – 需要账号、密码
python -m twine upload dist/*
完事儿
安装调用