首先在 https://pypi.org/ 注册一个账号,然后在 https://pypi.org/manage/account/ 添加一个token
~/.pypirc
[distutils]
index-servers =
pypi
[pypi]
repository = https://upload.pypi.org/legacy/
username = __token__
password = pypi-Ag*******中间省略*******EX_84SF8M3HZg
|____LICENSE
|____pyproject.toml
|____tests # 留空即可
|____README.md
|____MANIFEST.in # 配置项目包含文件(setuptools打包方式生效)
|____test # 测试目录,留空
|____mditor # 项目名称,pyproject.toml 中一致,也可以不一致
| |____项目文件
| |____views.py
需要在 pyproject.toml 中使用 setuptools 方式打包,并在 MANIFEST.in 声明
pyproject.toml
[build-system]
# 方式一:通过 MANIFEST.in 声明项目包含的文件
requires = ["setuptools>=61.0"]
build-backend = "setuptools.build_meta"
# 方式二:暂时不知道如何包含文件夹
# requires = ["hatchling"]
# build-backend = "hatchling.build"
[project]
name = "mditor"
version = "0.0.1"
authors = [
{ name="XiaoBing Jing", email="[email protected]" },
]
description = "描述"
readme = "README.md"
license = { file="LICENSE" }
requires-python = ">=3.7"
classifiers = [
"Programming Language :: Python :: 3",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
]
[project.urls]
"Homepage" = "https://github.com/ju4t/mditor"
"Bug Tracker" = "https://github.com/ju4t/mditor/issues"
LICENSE
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.
MANIFEST.in
include LICENSE
include README.md
recursive-include mditor/static *
recursive-include mditor/templates *
使用方法参考:https://packaging.python.org/en/latest/guides/using-manifest-in/
构建及发布命令
# 命令汇总
$ python3 -m pip install --upgrade build
$ python3 -m pip install --upgrade twine
$ python3 -m build
$ python3 -m twine upload --repository pypi dist/*
需要 build 和 twine 两个包
# 安装 build 包
$ python3 -m pip install --upgrade build
python3 -m pip install --upgrade build
Looking in indexes: https://mirrors.aliyun.com/pypi/simple/
Requirement already satisfied: build in /Users/ju4t/.virtualenvs/django-mditor/lib/python3.7/site-packages (0.8.0)
Requirement already satisfied: importlib-metadata>=0.22 in /Users/ju4t/.virtualenvs/django-mditor/lib/python3.7/site-packages (from build) (4.12.0)
Requirement already satisfied: packaging>=19.0 in /Users/ju4t/.virtualenvs/django-mditor/lib/python3.7/site-packages (from build) (21.3)
Requirement already satisfied: pep517>=0.9.1 in /Users/ju4t/.virtualenvs/django-mditor/lib/python3.7/site-packages (from build) (0.13.0)
Requirement already satisfied: tomli>=1.0.0 in /Users/ju4t/.virtualenvs/django-mditor/lib/python3.7/site-packages (from build) (2.0.1)
Requirement already satisfied: zipp>=0.5 in /Users/ju4t/.virtualenvs/django-mditor/lib/python3.7/site-packages (from importlib-metadata>=0.22->build) (3.8.1)
Requirement already satisfied: typing-extensions>=3.6.4 in /Users/ju4t/.virtualenvs/django-mditor/lib/python3.7/site-packages (from importlib-metadata>=0.22->build) (4.3.0)
Requirement already satisfied: pyparsing!=3.0.5,>=2.0.2 in /Users/ju4t/.virtualenvs/django-mditor/lib/python3.7/site-packages (from packaging>=19.0->build) (3.0.9)
# 安装 twine 包
python3 -m pip install --upgrade twine
Looking in indexes: https://mirrors.aliyun.com/pypi/simple/
Requirement already satisfied: twine in /Users/ju4t/.virtualenvs/django-mditor/lib/python3.7/site-packages (4.0.1)
Requirement already satisfied: rich>=12.0.0 in /Users/ju4t/.virtualenvs/django-mditor/lib/python3.7/site-packages (from twine) (12.5.1)
Requirement already satisfied: readme-renderer>=35.0 in /Users/ju4t/.virtualenvs/django-mditor/lib/python3.7/site-packages (from twine) (37.0)
Requirement already satisfied: keyring>=15.1 in /Users/ju4t/.virtualenvs/django-mditor/lib/python3.7/site-packages (from twine) (23.9.0)
Requirement already satisfied: rfc3986>=1.4.0 in /Users/ju4t/.virtualenvs/django-mditor/lib/python3.7/site-packages (from twine) (2.0.0)
Requirement already satisfied: importlib-metadata>=3.6 in /Users/ju4t/.virtualenvs/django-mditor/lib/python3.7/site-packages (from twine) (4.12.0)
Requirement already satisfied: pkginfo>=1.8.1 in /Users/ju4t/.virtualenvs/django-mditor/lib/python3.7/site-packages (from twine) (1.8.3)
Requirement already satisfied: requests-toolbelt!=0.9.0,>=0.8.0 in /Users/ju4t/.virtualenvs/django-mditor/lib/python3.7/site-packages (from twine) (0.9.1)
Requirement already satisfied: requests>=2.20 in /Users/ju4t/.virtualenvs/django-mditor/lib/python3.7/site-packages (from twine) (2.28.1)
Requirement already satisfied: urllib3>=1.26.0 in /Users/ju4t/.virtualenvs/django-mditor/lib/python3.7/site-packages (from twine) (1.26.12)
Requirement already satisfied: typing-extensions>=3.6.4 in /Users/ju4t/.virtualenvs/django-mditor/lib/python3.7/site-packages (from importlib-metadata>=3.6->twine) (4.3.0)
Requirement already satisfied: zipp>=0.5 in /Users/ju4t/.virtualenvs/django-mditor/lib/python3.7/site-packages (from importlib-metadata>=3.6->twine) (3.8.1)
Requirement already satisfied: jaraco.classes in /Users/ju4t/.virtualenvs/django-mditor/lib/python3.7/site-packages (from keyring>=15.1->twine) (3.2.2)
Requirement already satisfied: docutils>=0.13.1 in /Users/ju4t/.virtualenvs/django-mditor/lib/python3.7/site-packages (from readme-renderer>=35.0->twine) (0.19)
Requirement already satisfied: bleach>=2.1.0 in /Users/ju4t/.virtualenvs/django-mditor/lib/python3.7/site-packages (from readme-renderer>=35.0->twine) (5.0.1)
Requirement already satisfied: Pygments>=2.5.1 in /Users/ju4t/.virtualenvs/django-mditor/lib/python3.7/site-packages (from readme-renderer>=35.0->twine) (2.13.0)
Requirement already satisfied: charset-normalizer<3,>=2 in /Users/ju4t/.virtualenvs/django-mditor/lib/python3.7/site-packages (from requests>=2.20->twine) (2.1.1)
Requirement already satisfied: idna<4,>=2.5 in /Users/ju4t/.virtualenvs/django-mditor/lib/python3.7/site-packages (from requests>=2.20->twine) (3.3)
Requirement already satisfied: certifi>=2017.4.17 in /Users/ju4t/.virtualenvs/django-mditor/lib/python3.7/site-packages (from requests>=2.20->twine) (2022.6.15)
Requirement already satisfied: commonmark<0.10.0,>=0.9.0 in /Users/ju4t/.virtualenvs/django-mditor/lib/python3.7/site-packages (from rich>=12.0.0->twine) (0.9.1)
Requirement already satisfied: webencodings in /Users/ju4t/.virtualenvs/django-mditor/lib/python3.7/site-packages (from bleach>=2.1.0->readme-renderer>=35.0->twine) (0.5.1)
Requirement already satisfied: six>=1.9.0 in /Users/ju4t/.virtualenvs/django-mditor/lib/python3.7/site-packages (from bleach>=2.1.0->readme-renderer>=35.0->twine) (1.16.0)
Requirement already satisfied: more-itertools in /Users/ju4t/.virtualenvs/django-mditor/lib/python3.7/site-packages (from jaraco.classes->keyring>=15.1->twine) (8.14.0)
$ python3 -m build
* Creating venv isolated environment...
* Installing packages in isolated environment... (setuptools>=61.0)
* Getting dependencies for sdist...
running egg_info
creating django_mditor.egg-info
writing django_mditor.egg-info/PKG-INFO
writing dependency_links to django_mditor.egg-info/dependency_links.txt
writing top-level names to django_mditor.egg-info/top_level.txt
writing manifest file 'django_mditor.egg-info/SOURCES.txt'
reading manifest file 'django_mditor.egg-info/SOURCES.txt'
reading manifest template 'MANIFEST.in'
adding license file 'LICENSE'
writing manifest file 'django_mditor.egg-info/SOURCES.txt'
* Building sdist...
running sdist
running egg_info
writing django_mditor.egg-info/PKG-INFO
writing dependency_links to django_mditor.egg-info/dependency_links.txt
writing top-level names to django_mditor.egg-info/top_level.txt
reading manifest file 'django_mditor.egg-info/SOURCES.txt'
reading manifest template 'MANIFEST.in'
adding license file 'LICENSE'
writing manifest file 'django_mditor.egg-info/SOURCES.txt'
running check
creating django-mditor-0.0.11
creating django-mditor-0.0.11/django_mditor.egg-info
creating django-mditor-0.0.11/mditor
creating django-mditor-0.0.11/mditor/static
creating django-mditor-0.0.11/mditor/static/mditor
creating django-mditor-0.0.11/mditor/static/mditor/css
creating django-mditor-0.0.11/mditor/static/mditor/font
creating django-mditor-0.0.11/mditor/static/mditor/js
creating django-mditor-0.0.11/mditor/templates
creating django-mditor-0.0.11/mditor/templates/mditor
copying files to django-mditor-0.0.11...
copying LICENSE -> django-mditor-0.0.11
copying MANIFEST.in -> django-mditor-0.0.11
copying README.md -> django-mditor-0.0.11
copying pyproject.toml -> django-mditor-0.0.11
copying django_mditor.egg-info/PKG-INFO -> django-mditor-0.0.11/django_mditor.egg-info
copying django_mditor.egg-info/SOURCES.txt -> django-mditor-0.0.11/django_mditor.egg-info
copying django_mditor.egg-info/dependency_links.txt -> django-mditor-0.0.11/django_mditor.egg-info
copying django_mditor.egg-info/top_level.txt -> django-mditor-0.0.11/django_mditor.egg-info
copying mditor/__init__.py -> django-mditor-0.0.11/mditor
copying mditor/configs.py -> django-mditor-0.0.11/mditor
copying mditor/fields.py -> django-mditor-0.0.11/mditor
copying mditor/urls.py -> django-mditor-0.0.11/mditor
copying mditor/views.py -> django-mditor-0.0.11/mditor
copying mditor/widgets.py -> django-mditor-0.0.11/mditor
copying mditor/static/mditor/css/highlight.css -> django-mditor-0.0.11/mditor/static/mditor/css
copying mditor/static/mditor/css/highlight.min.css -> django-mditor-0.0.11/mditor/static/mditor/css
copying mditor/static/mditor/css/mditor.css -> django-mditor-0.0.11/mditor/static/mditor/css
copying mditor/static/mditor/css/mditor.min.css -> django-mditor-0.0.11/mditor/static/mditor/css
copying mditor/static/mditor/font/674f50d287a8c48dc19ba404d20fe713.eot -> django-mditor-0.0.11/mditor/static/mditor/font
copying mditor/static/mditor/font/912ec66d7572ff821749319396470bde.svg -> django-mditor-0.0.11/mditor/static/mditor/font
copying mditor/static/mditor/font/a48ac41620cd818c5020d0f4302489ff.ttf -> django-mditor-0.0.11/mditor/static/mditor/font
copying mditor/static/mditor/font/af7ae505a9eed503f8b8e6982036873e.woff2 -> django-mditor-0.0.11/mditor/static/mditor/font
copying mditor/static/mditor/font/b06871f281fee6b241d60582ae9369b9.ttf -> django-mditor-0.0.11/mditor/static/mditor/font
copying mditor/static/mditor/font/fee66e712a8a08eef5805a46892932ad.woff -> django-mditor-0.0.11/mditor/static/mditor/font
copying mditor/static/mditor/js/mditor.js -> django-mditor-0.0.11/mditor/static/mditor/js
copying mditor/static/mditor/js/mditor.min.js -> django-mditor-0.0.11/mditor/static/mditor/js
copying mditor/templates/mditor/widget.html -> django-mditor-0.0.11/mditor/templates/mditor
Writing django-mditor-0.0.11/setup.cfg
Creating tar archive
removing 'django-mditor-0.0.11' (and everything under it)
* Building wheel from sdist
* Creating venv isolated environment...
* Installing packages in isolated environment... (setuptools>=61.0)
* Getting dependencies for wheel...
running egg_info
writing django_mditor.egg-info/PKG-INFO
writing dependency_links to django_mditor.egg-info/dependency_links.txt
writing top-level names to django_mditor.egg-info/top_level.txt
reading manifest file 'django_mditor.egg-info/SOURCES.txt'
reading manifest template 'MANIFEST.in'
adding license file 'LICENSE'
writing manifest file 'django_mditor.egg-info/SOURCES.txt'
* Installing packages in isolated environment... (wheel)
* Building wheel...
running bdist_wheel
running build
running build_py
creating build
creating build/lib
creating build/lib/mditor
copying mditor/configs.py -> build/lib/mditor
copying mditor/fields.py -> build/lib/mditor
copying mditor/__init__.py -> build/lib/mditor
copying mditor/widgets.py -> build/lib/mditor
copying mditor/urls.py -> build/lib/mditor
copying mditor/views.py -> build/lib/mditor
running egg_info
writing django_mditor.egg-info/PKG-INFO
writing dependency_links to django_mditor.egg-info/dependency_links.txt
writing top-level names to django_mditor.egg-info/top_level.txt
reading manifest file 'django_mditor.egg-info/SOURCES.txt'
reading manifest template 'MANIFEST.in'
adding license file 'LICENSE'
writing manifest file 'django_mditor.egg-info/SOURCES.txt'
creating build/lib/mditor/static
creating build/lib/mditor/static/mditor
creating build/lib/mditor/static/mditor/css
copying mditor/static/mditor/css/highlight.css -> build/lib/mditor/static/mditor/css
copying mditor/static/mditor/css/highlight.min.css -> build/lib/mditor/static/mditor/css
copying mditor/static/mditor/css/mditor.css -> build/lib/mditor/static/mditor/css
copying mditor/static/mditor/css/mditor.min.css -> build/lib/mditor/static/mditor/css
creating build/lib/mditor/static/mditor/js
copying mditor/static/mditor/js/mditor.js -> build/lib/mditor/static/mditor/js
copying mditor/static/mditor/js/mditor.min.js -> build/lib/mditor/static/mditor/js
creating build/lib/mditor/static/mditor/font
copying mditor/static/mditor/font/674f50d287a8c48dc19ba404d20fe713.eot -> build/lib/mditor/static/mditor/font
copying mditor/static/mditor/font/912ec66d7572ff821749319396470bde.svg -> build/lib/mditor/static/mditor/font
copying mditor/static/mditor/font/a48ac41620cd818c5020d0f4302489ff.ttf -> build/lib/mditor/static/mditor/font
copying mditor/static/mditor/font/af7ae505a9eed503f8b8e6982036873e.woff2 -> build/lib/mditor/static/mditor/font
copying mditor/static/mditor/font/b06871f281fee6b241d60582ae9369b9.ttf -> build/lib/mditor/static/mditor/font
copying mditor/static/mditor/font/fee66e712a8a08eef5805a46892932ad.woff -> build/lib/mditor/static/mditor/font
creating build/lib/mditor/templates
creating build/lib/mditor/templates/mditor
copying mditor/templates/mditor/widget.html -> build/lib/mditor/templates/mditor
installing to build/bdist.macosx-12-x86_64/wheel
running install
running install_lib
creating build/bdist.macosx-12-x86_64
creating build/bdist.macosx-12-x86_64/wheel
creating build/bdist.macosx-12-x86_64/wheel/mditor
copying build/lib/mditor/configs.py -> build/bdist.macosx-12-x86_64/wheel/mditor
copying build/lib/mditor/fields.py -> build/bdist.macosx-12-x86_64/wheel/mditor
copying build/lib/mditor/__init__.py -> build/bdist.macosx-12-x86_64/wheel/mditor
copying build/lib/mditor/widgets.py -> build/bdist.macosx-12-x86_64/wheel/mditor
creating build/bdist.macosx-12-x86_64/wheel/mditor/static
creating build/bdist.macosx-12-x86_64/wheel/mditor/static/mditor
creating build/bdist.macosx-12-x86_64/wheel/mditor/static/mditor/css
copying build/lib/mditor/static/mditor/css/mditor.min.css -> build/bdist.macosx-12-x86_64/wheel/mditor/static/mditor/css
copying build/lib/mditor/static/mditor/css/highlight.css -> build/bdist.macosx-12-x86_64/wheel/mditor/static/mditor/css
copying build/lib/mditor/static/mditor/css/highlight.min.css -> build/bdist.macosx-12-x86_64/wheel/mditor/static/mditor/css
copying build/lib/mditor/static/mditor/css/mditor.css -> build/bdist.macosx-12-x86_64/wheel/mditor/static/mditor/css
creating build/bdist.macosx-12-x86_64/wheel/mditor/static/mditor/js
copying build/lib/mditor/static/mditor/js/mditor.min.js -> build/bdist.macosx-12-x86_64/wheel/mditor/static/mditor/js
copying build/lib/mditor/static/mditor/js/mditor.js -> build/bdist.macosx-12-x86_64/wheel/mditor/static/mditor/js
creating build/bdist.macosx-12-x86_64/wheel/mditor/static/mditor/font
copying build/lib/mditor/static/mditor/font/a48ac41620cd818c5020d0f4302489ff.ttf -> build/bdist.macosx-12-x86_64/wheel/mditor/static/mditor/font
copying build/lib/mditor/static/mditor/font/af7ae505a9eed503f8b8e6982036873e.woff2 -> build/bdist.macosx-12-x86_64/wheel/mditor/static/mditor/font
copying build/lib/mditor/static/mditor/font/674f50d287a8c48dc19ba404d20fe713.eot -> build/bdist.macosx-12-x86_64/wheel/mditor/static/mditor/font
copying build/lib/mditor/static/mditor/font/b06871f281fee6b241d60582ae9369b9.ttf -> build/bdist.macosx-12-x86_64/wheel/mditor/static/mditor/font
copying build/lib/mditor/static/mditor/font/912ec66d7572ff821749319396470bde.svg -> build/bdist.macosx-12-x86_64/wheel/mditor/static/mditor/font
copying build/lib/mditor/static/mditor/font/fee66e712a8a08eef5805a46892932ad.woff -> build/bdist.macosx-12-x86_64/wheel/mditor/static/mditor/font
creating build/bdist.macosx-12-x86_64/wheel/mditor/templates
creating build/bdist.macosx-12-x86_64/wheel/mditor/templates/mditor
copying build/lib/mditor/templates/mditor/widget.html -> build/bdist.macosx-12-x86_64/wheel/mditor/templates/mditor
copying build/lib/mditor/urls.py -> build/bdist.macosx-12-x86_64/wheel/mditor
copying build/lib/mditor/views.py -> build/bdist.macosx-12-x86_64/wheel/mditor
running install_egg_info
Copying django_mditor.egg-info to build/bdist.macosx-12-x86_64/wheel/django_mditor-0.0.11-py3.7.egg-info
running install_scripts
adding license file "LICENSE" (matched pattern "LICEN[CS]E*")
creating build/bdist.macosx-12-x86_64/wheel/django_mditor-0.0.11.dist-info/WHEEL
creating '/Volumes/Data/Dev/python/django-mditor/dist/tmp828s103b/django_mditor-0.0.11-py3-none-any.whl' and adding 'build/bdist.macosx-12-x86_64/wheel' to it
adding 'mditor/__init__.py'
adding 'mditor/configs.py'
adding 'mditor/fields.py'
adding 'mditor/urls.py'
adding 'mditor/views.py'
adding 'mditor/widgets.py'
adding 'mditor/static/mditor/css/highlight.css'
adding 'mditor/static/mditor/css/highlight.min.css'
adding 'mditor/static/mditor/css/mditor.css'
adding 'mditor/static/mditor/css/mditor.min.css'
adding 'mditor/static/mditor/font/674f50d287a8c48dc19ba404d20fe713.eot'
adding 'mditor/static/mditor/font/912ec66d7572ff821749319396470bde.svg'
adding 'mditor/static/mditor/font/a48ac41620cd818c5020d0f4302489ff.ttf'
adding 'mditor/static/mditor/font/af7ae505a9eed503f8b8e6982036873e.woff2'
adding 'mditor/static/mditor/font/b06871f281fee6b241d60582ae9369b9.ttf'
adding 'mditor/static/mditor/font/fee66e712a8a08eef5805a46892932ad.woff'
adding 'mditor/static/mditor/js/mditor.js'
adding 'mditor/static/mditor/js/mditor.min.js'
adding 'mditor/templates/mditor/widget.html'
adding 'django_mditor-0.0.11.dist-info/LICENSE'
adding 'django_mditor-0.0.11.dist-info/METADATA'
adding 'django_mditor-0.0.11.dist-info/WHEEL'
adding 'django_mditor-0.0.11.dist-info/top_level.txt'
adding 'django_mditor-0.0.11.dist-info/RECORD'
removing build/bdist.macosx-12-x86_64/wheel
Successfully built django-mditor-0.0.11.tar.gz and django_mditor-0.0.11-py3-none-any.whl
至此 已经在 dist目录下生成了 django-mditor-0.0.11.tar.gz and django_mditor-0.0.11-py3-none-any.whl,以及 django_mditor.egg-info
$ python3 -m twine upload --repository pypi dist/*
Uploading distributions to https://upload.pypi.org/legacy/
Uploading django_mditor-0.0.11-py3-none-any.whl
100% ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 762.8/762.8 kB • 00:02 • 522.9 kB/s
Uploading django-mditor-0.0.11.tar.gz
100% ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 759.8/759.8 kB • 00:00 • 18.5 MB/s
View at:
https://pypi.org/project/django-mditor/0.0.11/
至此,大约1分钟后就可以通过 pip install django-mditor 来安装了
$ pip show django-mditor
Name: django-mditor
Version: 0.0.11
Summary: 描述
Home-page:
Author:
Author-email: 敬晓兵 <[email protected]>
License: MIT License
Location: /Users/ju4t/.virtualenvs/django-mditor/lib/python3.7/site-packages
Requires:
Required-by:
但是国内镜像更新没有那么快,所以使用镜像加速的暂时不行。
也可以在本地配置好镜像加速后,通过 pip install django-mditor==0.0.11 指定版本号的方法来触发更新,更新时间不确定。
当 https://mirrors.aliyun.com/pypi/simple/django-mditor/ 有安装包后 就可以通过 加速镜像 安装了
构建及发布时确保网络正常,推荐使用国内镜像
macOS 阿里云配置如下 ~/.pip/pip.conf
[global]
index-url=https://mirrors.aliyun.com/pypi/simple/
[install]
trusted-host=mirrors.aliyun.com
转载自:https://labdoc.cc/article/8/