效果

D:\Program\Python310\python.exe D:\data\git\PythonLinuxBasicModule\upload.py
C:\Users\刘某
usage: twine [-h] [--version] [--no-color] {register,check,upload}positional arguments:{register,check,upload}options:-h, --help            show this help message and exit--version             show program's version number and exit--no-color            disable colored output
running sdist
running egg_info
creating plbm.egg-info
writing plbm.egg-info\PKG-INFO
writing dependency_links to plbm.egg-info\dependency_links.txt
writing requirements to plbm.egg-info\requires.txt
writing top-level names to plbm.egg-info\top_level.txt
writing manifest file 'plbm.egg-info\SOURCES.txt'
reading manifest file 'plbm.egg-info\SOURCES.txt'
writing manifest file 'plbm.egg-info\SOURCES.txt'
running check
creating plbm-1.0.2
creating plbm-1.0.2\plbm.egg-info
copying files to plbm-1.0.2...
copying README.md -> plbm-1.0.2
copying setup.py -> plbm-1.0.2
copying plbm.egg-info\PKG-INFO -> plbm-1.0.2\plbm.egg-info
copying plbm.egg-info\SOURCES.txt -> plbm-1.0.2\plbm.egg-info
copying plbm.egg-info\dependency_links.txt -> plbm-1.0.2\plbm.egg-info
copying plbm.egg-info\requires.txt -> plbm-1.0.2\plbm.egg-info
copying plbm.egg-info\top_level.txt -> plbm-1.0.2\plbm.egg-info
Writing plbm-1.0.2\setup.cfg
creating dist
Creating tar archive
removing 'plbm-1.0.2' (and everything under it)
running bdist_wheel
running build
C:\Users\刘某\AppData\Roaming\Python\Python310\site-packages\setuptools\command\install.py:34: SetuptoolsDeprecationWarning: setup.py install is deprecated. Use build and pip and other standards-based tools.warnings.warn(
installing to build\bdist.win-amd64\wheel
running install
running install_egg_info
Copying plbm.egg-info to build\bdist.win-amd64\wheel\.\plbm-1.0.2-py3.10.egg-info
running install_scripts
creating build\bdist.win-amd64\wheel\plbm-1.0.2.dist-info\WHEEL
creating 'dist\plbm-1.0.2-py3-none-any.whl' and adding 'build\bdist.win-amd64\wheel' to it
adding 'plbm-1.0.2.dist-info/METADATA'
adding 'plbm-1.0.2.dist-info/WHEEL'
adding 'plbm-1.0.2.dist-info/top_level.txt'
adding 'plbm-1.0.2.dist-info/RECORD'
removing build\bdist.win-amd64\wheel
构建成功
Uploading distributions to https://upload.pypi.org/legacy/
Uploading plbm-1.0.2-py3-none-any.whl
100% ---------------------------------------- 10.6/10.6 kB • 00:02 • ?
Uploading plbm-1.0.2.tar.gz
100% ---------------------------------------- 10.7/10.7 kB • 00:00 • ?View at:
https://pypi.org/project/plbm/1.0.2/
上传成功

源码

#!/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    :   当前文件作用
"""
from os import system, chdir, path, getenv
from shutil import rmtree
import platformclass UploadToPypi:def __init__(self):"""上传项目到pypi"""self.work = './plbm'self.dist = path.join(self.work, 'dist')self.egg = path.join(self.work, 'plbm.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 Falsereturn Truedef delete(self, dir_=None):"""删除文件夹:param dir_::return:"""if dir_ is None:dir_ = self.distif path.exists(dir_):try:rmtree(dir_)except Exception as e:print(e)def build(self):"""开始构建:return:"""chdir(self.work)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()if __name__ == "__main__":upload = UploadToPypi()upload.start()

Python3自动化打包项目发布到pypi相关推荐

  1. iOS中使用Fastlane实现自动化打包和发布

    iOS中使用Fastlane实现自动化打包和发布 2017-05-19 14:46 编辑: sasukeo 分类:iOS开发 来源:iOS_小松哥的简书 1 1241 iOS开发自动化fastlane ...

  2. iOS自动化探索(九)使用Jenkins自动化打包并发布iOS App

    继前一篇: Mac环境下安装Jenkins Jenkins安装好后, 我们试着创建一个iOS自动打包并发布的任务 iOS App构建必须在MAC上面使用xcode进行,所以我们要安装下xcode集成插 ...

  3. 搭建基于.NetFrameWork的私有nuget服务端及打包项目发布上传

    一.私有Nuget服务端搭建 1.创建一个.NetFramework web项目 2.在nuget管理中 安装 nuget.server包 3.安装完成后修改web.config里面的 apikey ...

  4. 详解Python 3.6.x程序打包并发布至pypi的完整过程

    以我昨天刚编写的一个投票小程序tkinter_vote.py为例. 第一步,在命令行中安装所需要的工具,pip install setuptools wheel twine 第二步,编写相应的setu ...

  5. 把自己的项目布到服务器,如何把自己的开源项目发布到Pypi服务器

    众所周知,Python社区最吸引人的地方之一就是社区提供了非常丰富的第三方库,任何人都可以往上面提交自己写的开源工具包,如果希望用户可以直接通过 pip 命令下载安装的话,作为开发者,我们就可以把自己 ...

  6. Python编程:twine模块打包python项目上传pypi

    注册账号(重要) https://pypi.org 可以配置到$HOME/.pypirc文件中,就不用多次输入了 [pypi] username = <username> password ...

  7. React Native项目自动化打包发布

    今天这篇文章的目的是在rn项目的构建,并不会涉及到rn框架或者使用的讲解,说起构建,特别是前端构建大家应该很快会想到webpack.Grunt. Gulp等.而这些工具在rn项目中就显得有些鸡肋.所以 ...

  8. linux maven 发布项目,Linux下基于Maven的自动化打包发布项目

    基于Maven的自动化打包发布项目 1.配置项目文件 prolist.config svn://10.1.23.215/Hive/HiveUDFIK hive-ik jar 10.130.2.245 ...

  9. python代码写完怎么运行-Python 项目代码写完了,然后怎么打包和发布?

    你把你的代码写完了,是不是要给别人使用下,怎么打包你的项目代码呢? 喂,开源么? 接下来小帅b就跟你说说,如何打包你的代码. 就拿我们上次演示的 用 Python 开发一个 「个人计划 todolis ...

最新文章

  1. 亚马逊云科技在中国区域上线机器学习新服务,打造广泛而深入的人工智能与机器学习工具集
  2. xpwin7下的CMD命令
  3. 网元查看一个无厘头的core dump问题定位
  4. javascript 语言标准 es6简介
  5. 【Java Web开发指南】线程安全和单线程
  6. SDUT 2127 树-堆结构练习——合并果子之哈夫曼树(优先队列)
  7. drupal 7 连接多个数据库
  8. 基于OpenCV的图像阴影去除,你会吗?
  9. Linux升级glibc版本汉字乱码,Linux CentOS6升级glibc库过程
  10. hadoop--windows环境配置hadoop-3.2.2
  11. opencv mat赋值_【3】OpenCV图像处理模块(18)重映射
  12. keil5函数 默认返回值_Python列表有什么内置函数可以使用,怎么使用这些函数
  13. 仿百度手机助手标题栏透明度随ListView或ScrollView滚动改变的实现方法
  14. 【Python实例第29讲】递归的特征排除法
  15. 联想重装系统去掉保护_联想硬盘保护系统,小编告诉你联想硬盘保护系统怎么安装...
  16. 现代opengl 设计 assimp 3D 模型加载库
  17. 小僧尽知他的备细出 水浒
  18. bzoj1022 约翰的游戏 反SG-博弈
  19. 【深度学习】实例分割网络
  20. 儒家、道家、释家思想之异同(上)

热门文章

  1. 狮子鱼团购社区模拟器显示没内容的解决方法
  2. SpringCloud Alibaba——精读Nacos+CMDB+核心源码阅读(7w字长篇)
  3. 深入理解空间坐标系的矩阵变换
  4. 很认真的聊一聊程序员的自我修养(转自博客园)
  5. 【Java工具类】HutoolUtil
  6. 【面经】2022社招软件测试面试(3)-腾讯CSIG云网络测试开发
  7. CC2530 定时器应用
  8. 大家好!我是屁孩君儿子,今天给大家带来一个 1085 球弹跳高度的计算
  9. cocos creator 调用相机相册裁剪图片并上传到服务器
  10. 入门深度学习OCR(Optical character recognition)开发