要想将自己的包开源得先准备材料:
先解释下这个文件中文件的由来:
1.loggingtool这是一个包(切记包,也就是说里面必须有__init__.py文件),这个包是你要开源的包,也就是开发者自己写的Python代码,这是基础哈
2.setup.py这是用于生成图中dist和loggingtool.egg-info这个两个文件夹的,其中dist里面会是一个开源的压缩包
先展示下setup.py这个文件的内容:
#!/usr/bin/env python
# _*_ coding:utf-8 _*_
"""
File: LogTool.py
Author: Lijiacai ([email protected])
Date: 2018-11-20
Description:
setup tool
"""
import os
import sys
cur_dir = os.path.split(os.path.realpath(__file__))[0]
sys.path.append("%s/" % cur_dir)
from setuptools import setup
from setuptools import find_packages
setup(
name="loggingtool", # 这里是pip 项目名称
version="18.11.22", # 发布的版本号,如果更新改库,那么会优先下载数值大的
keywords=("pip", "logging", "loggingtool"), # 搜索关键字
description="The package for logging",
long_description="The package uses the dictionary method of " +
"logging module to achieve log rollback and other output.",
license="MIT License", # 这个可以不要哈
url="https://github.com/lijiacaigit/LogTool", # 这个是pip上的homepage,就是你源码的位置
author="Lijiacai", # 作者
author_email="[email protected]",
packages=find_packages(),
include_package_data=True,
platforms="any",
install_requires=["logging"] # 这个项目需要的第三方库
)
运行Python setup.py sdist就可以生成dist loggingtool.egg-info文件夹了
3.将打包好的文件上传至pypi
这里需要大家自行去注册pypi账号,上传过程中需要输入账号和密码
工具:twine
pip install twine
使用命令行:
twine upload dist/loggingtool-18.11.22.tar.gz
上传过程中需要输入账号密码哟
4.下载上传成功的包
pip install loggingtool
然后就能使用这个第三方库了,别人也能用!!!
5.相关信息
一般发布pip项目,都会在github上配置文件用来方便读者看源码,比如我的:
github地址