1 Star 0 Fork 0

坐公交也用券/ColorInfo

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
UploadToPypi.py 2.40 KB
一键复制 编辑 原始数据 按行查看 历史
MagicBook 提交于 2022-11-17 10:39 . 更新说明
#!/usr/bin/env python3
# -*- encoding: utf-8 -*-
"""
@File : UploadToPypi.py
@Time : 2022-10-25 11:54
@Author : 坐公交也用券
@Version : 1.0
@Contact : faith01238@hotmail.com
@Homepage : https://liumou.site
@Desc : 当前文件作用
"""
import platform
from os import system, path, getenv, getcwd
from shutil import rmtree
class UploadToPypi:
def __init__(self):
"""
上传项目到pypi
"""
self.work = getcwd()
self.dist = path.join(self.work, 'dist')
self.egg = path.join(self.work, 'ColorInfo.egg-info')
self.build_dir = path.join(self.work, 'build')
self.home = getenv('HOME')
if platform.system().lower() == 'windows':
self.home = path.expanduser("~")
print(self.home)
# 这是保存用户密码的文件,将pypi的账号保存到这个文件即可(第一行: 用户名,第二行: 密码)
file = path.join(self.home, 'pypi.txt')
r = open(file=file, mode='r', encoding='utf-8')
data = r.read()
r.close()
self.user = str(data).split("\n")[0]
self.pd = str(data).split("\n")[1]
def install_twine(self):
"""
:return:
"""
cmd = "pip install twine -i https://pypi.tuna.tsinghua.edu.cn/simple"
if self.check_twine():
if platform.system().lower() == 'linux':
cmd = "pip3 install twine -i https://pypi.tuna.tsinghua.edu.cn/simple"
system(cmd)
def check_twine(self):
"""
检查是否需要安装twine工具
:return:
"""
cmd = "twine -h"
res = system(cmd)
if int(res) == 0:
return False
return True
def delete(self, dir_=None):
"""
删除文件夹
:param dir_:
:return:
"""
if dir_ is None:
dir_ = self.dist
if path.exists(dir_):
try:
rmtree(dir_)
except Exception as e:
print(e)
def build(self):
"""
开始构建
:return:
"""
c = "python setup.py sdist bdist_wheel"
if platform.system().lower() == 'linux':
c = "python3 setup.py sdist bdist_wheel"
res = system(c)
if int(res) == 0:
print("构建成功")
res = system(f"twine upload -u {self.user} -p {self.pd} dist/* ")
if int(res) == 0:
print("上传成功")
else:
print("上传失败")
else:
print("构建失败")
def start(self):
"""
开始处理
:return:
"""
self.install_twine()
self.delete()
self.delete(self.egg)
self.delete(self.build_dir)
self.build()
self.delete()
self.delete(self.egg)
self.delete(self.build_dir)
if __name__ == "__main__":
upload = UploadToPypi()
upload.start()
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/liumou_site/ColorInfo.git
git@gitee.com:liumou_site/ColorInfo.git
liumou_site
ColorInfo
ColorInfo
master

搜索帮助