代码拉取完成,页面将自动刷新
#!/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()
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。