
之前写过一篇如何用 Python 标准库快速比较两个巨复杂的 JSON 之间的内容值的差异不是简单对比行之间的差距而是对比那些值有差异主要用在某个内部服务中做版本管理的。使用效果大概是这样的文件行数为21772行$ wc -l test_left.json21772 test_left.json要尽可能快的比较出来$ time json-diff test_left.json test_right.json[{“path”: “variables[3].spec.sort”,“kind”: “modified”,“left”: “alphabeticalAsc123”,“right”: “alphabeticalAsc”}]耗时 0.04 秒json-diff test_left.json test_right.json 0.04s user 0.02s system 99% cpu 0.055 total当时有人问能否打包发到 PyPI 上于是我动手稍微改了下做了一半后来给其他事情耽搁了拖了那么久也忘了 PyPI 怎么发包的了正好借此整理下步骤。想尝试的小伙伴也可以安装下试试python -m pip install quick-json-diff代码pyproject.toml有多种项目构建方式基于 pyproject.toml 是其中一种。如果用 uv 的话那么基于 uv 生成的 pyproject.toml 稍作修改会更方便点。基本需要的配置如下其中 [build-system] 用来声明构建后端可替换为其它多种构建后端具体可见底部关于 pyproject.toml 的参考链接。[project]name “quick-json-diff”version “1.0.0”description “Compare two JSON files quickly using Python standard library.”readme “README.md”requires-python “3.9”license { file “LICENSE” }[build-system]requires [“setuptools 77.0.3”]build-backend “setuptools.build_meta”代码布局对于我这个 SDK我用的是src/ 结构布局也就是└─ src└─ quick_json_diff本地构建安装构建工具。build 用来构建twine 用来上传 PyPIpython -m pip install --upgrade build twine构建。构建结果会生成在 dist/ 目录下python -m build上传 PyPI 前用 twine 检查包元数据$ twine check dist/*Checking dist/quick_json_diff-1.0.0-py3-none-any.whl: PASSEDChecking dist/quick_json_diff-1.0.0.tar.gz: PASSED上传上传 TestPyPItwine upload --repository-url https://test.pypi.org/legacy/ dist/*从 TestPyPI 下载测试pip install -i https://test.pypi.org/simple/ quick-json-diff上传 PyPItwine upload dist/*本地安装测试python -m pip install dist/quick_json_diff-1.0.0-py3-none-any.whl发布到 PyPI上传到 PyPI 之前最好先发布到 TestPyPI 作为测试验证展示页和安装体验。先到 test.pypi.org 和 pypi.org 注册账号。分别创建 API Token发布到 TestPyPI。上传时会提示输入 API Tokentwine upload --repository-url https://test.pypi.org/legacy/ dist/*测试安装python -m pip install-i https://test.pypi.org/simple/quick-json-diff前面测试没问题的话再上传到 PyPItwine upload dist/*结束补充后续发新版需要修改 pyproject.toml 中的 version然后重新构建、上传。