<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/">
    <channel>
        <title>Cherrymelon’s Blog</title>
        <link>https://cherrymelon.top/</link>
        <description>记录杂七杂八的小站</description>
        <lastBuildDate>Mon, 19 Oct 2026 13:33:01 GMT</lastBuildDate>
        <docs>https://validator.w3.org/feed/docs/rss2.html</docs>
        <generator>https://github.com/jpmonette/feed</generator>
        <language>zh-CN</language>
        <copyright>All rights reserved 2026, Cherrymelon</copyright>
        <item>
            <title><![CDATA[Black的替代者？Ruff的使用教程]]></title>
            <link>https://cherrymelon.top/article/d6e37cda-702f-4f7c-95cb-1a2a36527e9a</link>
            <guid>https://cherrymelon.top/article/d6e37cda-702f-4f7c-95cb-1a2a36527e9a</guid>
            <pubDate>Tue, 16 Apr 2024 00:00:00 GMT</pubDate>
            <content:encoded><![CDATA[<div id="notion-article" class="mx-auto overflow-hidden "><main class="notion light-mode notion-page notion-small-text notion-block-d6e37cda702f4f7c95cb1a2a36527e9a"><div class="notion-viewport"></div><div class="notion-collection-page-properties"></div><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-970045f393c844b6b00c9336c30f7ae5" data-id="970045f393c844b6b00c9336c30f7ae5"><span><div id="970045f393c844b6b00c9336c30f7ae5" class="notion-header-anchor"></div><a class="notion-hash-link" href="#970045f393c844b6b00c9336c30f7ae5" title="前言"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">前言</span></span></h2><div class="notion-text notion-block-a73a7d8e83264ed6bad0a07783fa730c"><a class="notion-link" href="https://github.com/psf/black" target="_blank" rel="noopener noreferrer">Black</a>是一个广泛流行的静态检查和格式化工具，也是常说的linter和 formtter，<a class="notion-link" href="https://github.com/astral-sh/ruff" target="_blank" rel="noopener noreferrer">Ruff</a>也是一款同样功能的工具，不同之处在于Ruff是Rust写的，Black是Python写的。这意味着Ruff相比Black，突出一个高性能，个人体验下来速度确实很快，1w行（谁懂啊）的python代码格式化速度大概做到了四分之一的Pycharm自带格式化性能开销。易用性也ok，兼容Black接近99%的历史代码，个人不太满意的一点就是格式化选项太少。</div><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-539da03ea1244ecf8008772677a03e61" data-id="539da03ea1244ecf8008772677a03e61"><span><div id="539da03ea1244ecf8008772677a03e61" class="notion-header-anchor"></div><a class="notion-hash-link" href="#539da03ea1244ecf8008772677a03e61" title="安装"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">安装</span></span></h2><div class="notion-text notion-block-d39d51db735847d698d15a4cbd556485">很多方式都支持，一般用pip足够了</div><div class="notion-text notion-block-a3e5d2b1bbae4aadb10569d08de949fd"><code class="notion-inline-code">pip install ruff</code></div><div class="notion-text notion-block-9d2714607cd44a41981979a0b1912b56">配置ruff设置</div><div class="notion-text notion-block-ad08008decc94b4fa21674d788abd7fb">在自己喜欢的位置创建<code class="notion-inline-code">pyproject.toml</code>, <code class="notion-inline-code">ruff.toml</code>, 或者<code class="notion-inline-code">.ruff.toml</code> ，样例配置在官网上有,以下是我个人习惯的配置</div><div class="notion-text notion-block-fae7f826b2c74e63a23690a07d1fd4d7">上面有几行自定义的选项可以注意下</div><h4 class="notion-h notion-h3 notion-h-indent-1 notion-block-c21b06d1526b4e6f9caa21c55e51e45d" data-id="c21b06d1526b4e6f9caa21c55e51e45d"><span><div id="c21b06d1526b4e6f9caa21c55e51e45d" class="notion-header-anchor"></div><a class="notion-hash-link" href="#c21b06d1526b4e6f9caa21c55e51e45d" title="lint"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">lint</span></span></h4><div class="notion-text notion-block-5aa14a7a95d149a881219353eeb5103c">select表示启用的检查规则，一般没有特殊需求可以不动，ignore 表示需要忽略的提示，比如有代码报E727了，你又不想一行行写noqa之类，就在这里加入E727</div><h4 class="notion-h notion-h3 notion-h-indent-1 notion-block-532eadaa74b64eac871e3d87dad1beac" data-id="532eadaa74b64eac871e3d87dad1beac"><span><div id="532eadaa74b64eac871e3d87dad1beac" class="notion-header-anchor"></div><a class="notion-hash-link" href="#532eadaa74b64eac871e3d87dad1beac" title="format"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">format</span></span></h4><div class="notion-text notion-block-acc08ae0261048359aa257506fff24f3">quote-style中double表示统一用双引号，这个单引号还是双引号看喜好和团队规范了。</div><div class="notion-text notion-block-8ba36774efd74c59bb55832477d97957">skip-magic-trailing-comma true表示不根据你的尾随逗号来换行</div><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-b99eb4d7be884557bbce68ee9b621e3a" data-id="b99eb4d7be884557bbce68ee9b621e3a"><span><div id="b99eb4d7be884557bbce68ee9b621e3a" class="notion-header-anchor"></div><a class="notion-hash-link" href="#b99eb4d7be884557bbce68ee9b621e3a" title="配置precommit 钩子"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">配置precommit 钩子</span></span></h3><h4 class="notion-h notion-h3 notion-h-indent-2 notion-block-3968716f9304433a9e91d754b626c870" data-id="3968716f9304433a9e91d754b626c870"><span><div id="3968716f9304433a9e91d754b626c870" class="notion-header-anchor"></div><a class="notion-hash-link" href="#3968716f9304433a9e91d754b626c870" title="安装precommit插件"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">安装precommit插件</span></span></h4><div class="notion-text notion-block-94032c7d51e843a5bac5d283842580c2"><code class="notion-inline-code">pip install pre-commit</code> </div><h4 class="notion-h notion-h3 notion-h-indent-2 notion-block-b3a5547412ae46ca9f985fdc1208801d" data-id="b3a5547412ae46ca9f985fdc1208801d"><span><div id="b3a5547412ae46ca9f985fdc1208801d" class="notion-header-anchor"></div><a class="notion-hash-link" href="#b3a5547412ae46ca9f985fdc1208801d" title="新建.precommit.yaml文件"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">新建.precommit.yaml文件</span></span></h4><div class="notion-text notion-block-9729261c21ee4e809c524bda680a89b8">一个典型的例子</div><h4 class="notion-h notion-h3 notion-h-indent-2 notion-block-7be3a13d2dd640dc9475b9771d80e51c" data-id="7be3a13d2dd640dc9475b9771d80e51c"><span><div id="7be3a13d2dd640dc9475b9771d80e51c" class="notion-header-anchor"></div><a class="notion-hash-link" href="#7be3a13d2dd640dc9475b9771d80e51c" title="安装git hook脚本"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">安装git hook脚本</span></span></h4><div class="notion-text notion-block-92644312a3d643e485333863377e9799">注意是在项目的根目录哦
<code class="notion-inline-code">pre-commit install</code> </div><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-0b4d105135794acf90bbb73f5d4ce82b" data-id="0b4d105135794acf90bbb73f5d4ce82b"><span><div id="0b4d105135794acf90bbb73f5d4ce82b" class="notion-header-anchor"></div><a class="notion-hash-link" href="#0b4d105135794acf90bbb73f5d4ce82b" title="运行"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">运行</span></span></h3><div class="notion-text notion-block-7091a1aaffa0476482e37d3f256d52a7">两个常用命令 ruff check 和 ruff format，使用方式是类似的</div><div class="notion-blank notion-block-2c3c414726c04ad3bc6694612456b3cd"> </div><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-c230ac91560443d5969b67f8cd179545" data-id="c230ac91560443d5969b67f8cd179545"><span><div id="c230ac91560443d5969b67f8cd179545" class="notion-header-anchor"></div><a class="notion-hash-link" href="#c230ac91560443d5969b67f8cd179545" title="Pycharm中的使用(可选)"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">Pycharm中的使用(可选)</span></span></h2><div class="notion-text notion-block-970eb6cea52c4bc5a120881d7fcc833a">market下一个插件，ruff，安装之后在设置-tools中找到ruff，可以按需求选择全局ruff还是按项目选择不同ruff。</div><div class="notion-text notion-block-6596214292b44af1a96fa7acf470559f">注意，如果想用 ruff 替换掉 pycharm 的格式化功能的话，记得打开下图红框中的功能</div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-341dc27ecdea49f4a8d82a88b5b9578c"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column;height:100%"><img style="object-fit:cover" src="https://www.notion.so/image/attachment%3A590dd317-5b0b-4ea7-a42a-a29b41db3cc4%3AUntitled.png?table=block&amp;id=341dc27e-cdea-49f4-a8d8-2a88b5b9578c&amp;t=341dc27e-cdea-49f4-a8d8-2a88b5b9578c" alt="notion image" loading="lazy" decoding="async"/></div></figure><div class="notion-blank notion-block-2884ae80834145b6823bf6f796f77a1f"> </div></main></div>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Python 版本兼容踩坑记录]]></title>
            <link>https://cherrymelon.top/article/23f63c66-ac83-8002-92fc-fb4be0c7a00a</link>
            <guid>https://cherrymelon.top/article/23f63c66-ac83-8002-92fc-fb4be0c7a00a</guid>
            <pubDate>Tue, 29 Jul 2025 00:00:00 GMT</pubDate>
            <content:encoded><![CDATA[<div id="notion-article" class="mx-auto overflow-hidden "><main class="notion light-mode notion-page notion-small-text notion-block-23f63c66ac83800292fcfb4be0c7a00a"><div class="notion-viewport"></div><div class="notion-collection-page-properties"></div><div class="notion-callout notion-gray_background_co notion-block-23f63c66ac83809f8459f1f5df5ec742"><div class="notion-page-icon-inline notion-page-icon-span"><span class="notion-page-icon" role="img" aria-label="😀">😀</span></div><div class="notion-callout-text">记录一下pycharm使用远程调试模式时遇到的问题，花了一两个小时的功夫才弄清楚</div></div><div class="notion-text notion-block-23f63c66ac838090b55ac4f26715b09a">昨天晚上在设置一个项目的远程解释器的时候，运行项目提示报错   ImportError: xxx/.venv/lib/python3.12/site-packages/_argon2_cffi_bindings/_ffi.abi3.so: invalid ELF header</div><div class="notion-text notion-block-23f63c66ac8380168664c60bb24cbd7c">服务器上环境为python3.12.2+cryptography45.0.5，cryptography加密库的版本基本上已经是最新的了，最初以为是项目 sync 到服务器的时候把本地 mac的二进制库 sync 到了 linux 服务器上，但是实际上通过 reinstall,卸载重新 build 等操作发现报错依旧，最后以为是版本兼容问题，通过 uv lock —upgrade 升级包依赖还是失败，于是继续尝试升级 python 到 3.12.11,最后成功启动</div><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-23f63c66ac8380bd9883fbd2d5ef4cdb" data-id="23f63c66ac8380bd9883fbd2d5ef4cdb"><span><div id="23f63c66ac8380bd9883fbd2d5ef4cdb" class="notion-header-anchor"></div><a class="notion-hash-link" href="#23f63c66ac8380bd9883fbd2d5ef4cdb" title="📎 参考文章"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">📎 参考文章</span></span></h2><ul class="notion-list notion-list-disc notion-block-23f63c66ac83803294b8c3beacd99637"><li></li></ul><ul class="notion-list notion-list-disc notion-block-23f63c66ac8380098dc4c777862583b8"><li><a class="notion-link" href="https://stackoverflow.com/questions/69319614/invalid-elf-header-argon2-package" target="_blank" rel="noopener noreferrer">引用文章</a></li></ul><div class="notion-blank notion-block-23f63c66ac8380599e09c698d64dd7d7"> </div></main></div>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[UV-易用而快速的Python 包管理工具]]></title>
            <link>https://cherrymelon.top/article/329d45b3-727c-4b7c-be70-72d6725dd81d</link>
            <guid>https://cherrymelon.top/article/329d45b3-727c-4b7c-be70-72d6725dd81d</guid>
            <pubDate>Wed, 04 Sep 2024 00:00:00 GMT</pubDate>
            <content:encoded><![CDATA[<div id="notion-article" class="mx-auto overflow-hidden "><main class="notion light-mode notion-page notion-small-text notion-block-329d45b3727c4b7cbe7072d6725dd81d"><div class="notion-viewport"></div><div class="notion-collection-page-properties"></div><div class="notion-text notion-block-cca57c9e9a1b44b6abeae6ad21c03f99"><a class="notion-link" href="https://github.com/astral-sh/uv" target="_blank" rel="noopener noreferrer">uv</a> 是一款基于 Rust 开发的 Python 包管理工具。</div><div class="notion-text notion-block-5e610874e22847d8be6936006860799e">在尝试了 PDM 与 Poetry 这些复杂且不太友好的包管理工具后，终于迎来了一个类似 Cargo 的 Python 包管理工具。它文档清晰，风格与 Cargo 相似，能与 pip、pip-tools 无缝兼容。初次使用后感觉非常棒，目前在 GitHub 上已获得 19K 星标。</div><h4 class="notion-h notion-h3 notion-h-indent-0 notion-block-ae056b74a19f4c1d97d75f3b04d47565" data-id="ae056b74a19f4c1d97d75f3b04d47565"><span><div id="ae056b74a19f4c1d97d75f3b04d47565" class="notion-header-anchor"></div><a class="notion-hash-link" href="#ae056b74a19f4c1d97d75f3b04d47565" title="特性"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">特性</span></span></h4><ul class="notion-list notion-list-disc notion-block-13dc2ecded934a7aba2d366148143f69"><li>基于 Rust 开发，比 pip快 10-100X，如果是之前看过我的 Ruff 使用之旅，从 Black切换到 Ruff 的同学应该深有体会，顺便一说，Ruff 也是他们团队开发的，利用 Rust 重构 Python 的生态链，看来是一个极其有价值的事情，<a class="notion-link" href="https://github.com/RustPython/RustPython" target="_blank" rel="noopener noreferrer">Rust-Python</a>截止到 24 年9 月，star 也干到 18K star，刚开始的时候 star 才 3k 不到</li></ul><ul class="notion-list notion-list-disc notion-block-48959a7b1f3c42bcb88360f1e5ac611d"><li>自带 Python 环境管理功能，类似 venv</li></ul><ul class="notion-list notion-list-disc notion-block-616bc45477c44e41a072ee8bcc2a7277"><li>提供类似 PDM，Poetry 的包版本管理和锁定功能</li></ul><ul class="notion-list notion-list-disc notion-block-b5a13956b5274ba8abf2677fe3f2797b"><li>提供脚本单独配置运行的包版本，方便多版本使用</li></ul><ul class="notion-list notion-list-disc notion-block-b9477da9feac4f88a69bc181c532a455"><li>提供 cargo 风格的 workspace ，支持大型项目协同管理</li></ul><ul class="notion-list notion-list-disc notion-block-511d1863ef984cf78e839efc3a9026f9"><li>支持 MacOS、Linux、Windows</li></ul><div class="notion-blank notion-block-7db7b2885e3342d3a0ca5a295f523688"> </div><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-4c2841399a594f4bb4c153d59f7eeb3e" data-id="4c2841399a594f4bb4c153d59f7eeb3e"><span><div id="4c2841399a594f4bb4c153d59f7eeb3e" class="notion-header-anchor"></div><a class="notion-hash-link" href="#4c2841399a594f4bb4c153d59f7eeb3e" title="安装"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">安装</span></span></h2><div class="notion-text notion-block-9754eda31f0b4587a0d09d86dcdeb355">uv支持curl 或者pip 的方式安装，参照官网文档</div><div class="notion-text notion-block-4bf9d2e2da1b476b91bb7965e2f75564">安装完毕之后可以用 <code class="notion-inline-code"> uv help</code> 查看相关指令</div><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-7b2150363a8e40aead7e5732896db9be" data-id="7b2150363a8e40aead7e5732896db9be"><span><div id="7b2150363a8e40aead7e5732896db9be" class="notion-header-anchor"></div><a class="notion-hash-link" href="#7b2150363a8e40aead7e5732896db9be" title="使用"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">使用</span></span></h2><div class="notion-text notion-block-da4db26f5c754d83825566a6689d51a7">uv 使用一般有两种场景，从已有项目迁移和创建新项目。</div><h4 class="notion-h notion-h3 notion-h-indent-1 notion-block-5d669650b4f04f76be8c65abf6e38554" data-id="5d669650b4f04f76be8c65abf6e38554"><span><div id="5d669650b4f04f76be8c65abf6e38554" class="notion-header-anchor"></div><a class="notion-hash-link" href="#5d669650b4f04f76be8c65abf6e38554" title="新建新项目"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">新建新项目</span></span></h4><div class="notion-text notion-block-668b2e4fecf844e59a23375c4ab0e94f">cd到项目根目录下，<code class="notion-inline-code">uv init</code></div><div class="notion-text notion-block-5ae9303490d840a4941711fae1385a3b">会发现多了venv 、 pyproject.toml 和 uv.lock ,venv是项目的 python 虚拟环境，toml 是项目配置信息和依赖，uv.lock是用于版本控制的依赖文件。</div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-18730712f8de493f9928a25584d24e62"><div style="position:relative;display:flex;justify-content:center;align-self:start;width:336px;max-width:100%;flex-direction:column"><img style="object-fit:cover" src="https://www.notion.so/image/attachment%3A6ddbe6e3-9182-485f-9190-085f4bccad6f%3Aimage.png?table=block&amp;id=18730712-f8de-493f-9928-a25584d24e62&amp;t=18730712-f8de-493f-9928-a25584d24e62" alt="notion image" loading="lazy" decoding="async"/></div></figure><h4 class="notion-h notion-h3 notion-h-indent-1 notion-block-d0eec6fdf29240edaaefab5ff896c91d" data-id="d0eec6fdf29240edaaefab5ff896c91d"><span><div id="d0eec6fdf29240edaaefab5ff896c91d" class="notion-header-anchor"></div><a class="notion-hash-link" href="#d0eec6fdf29240edaaefab5ff896c91d" title="从已有项目迁移"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">从已有项目迁移</span></span></h4><div class="notion-text notion-block-8c7724a766b84f558b2b5c3c308d9e15">如果是从 potery、PDM管理的项目迁移过来的，利用其他工具翻译 toml 文件就行，如果是用 requirements管理的话，不推荐直接从文件添加，最好理清依赖关系再添加。</div><h4 class="notion-h notion-h3 notion-h-indent-1 notion-block-a4edee141bee4e438e575d5be20d4e25" data-id="a4edee141bee4e438e575d5be20d4e25"><span><div id="a4edee141bee4e438e575d5be20d4e25" class="notion-header-anchor"></div><a class="notion-hash-link" href="#a4edee141bee4e438e575d5be20d4e25" title="多人协作"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">多人协作</span></span></h4><div class="notion-text notion-block-ab74213a403c4469bc415efe0e84a7d2">从 git 上拉取已经用 uv 配置好的项目后，<code class="notion-inline-code">uv venv </code> 创建虚拟环境，<code class="notion-inline-code">uv sync</code> 安装依赖到本地。</div><div class="notion-text notion-block-10b63c66ac8380088641dd91dc028a95">当有新依赖发生修改时，<code class="notion-inline-code">uv lock</code> 锁定依赖版本。</div><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-f8e4be77534146f6befb436b3a53fa6d" data-id="f8e4be77534146f6befb436b3a53fa6d"><span><div id="f8e4be77534146f6befb436b3a53fa6d" class="notion-header-anchor"></div><a class="notion-hash-link" href="#f8e4be77534146f6befb436b3a53fa6d" title="依赖管理"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">依赖管理</span></span></h3><div class="notion-text notion-block-520c7a85f0674cc6a0ab94fccd205aba">uv 的管理概念十分直观，<code class="notion-inline-code">uv add pkg</code> 添加依赖，uv 会自动处理子依赖，<code class="notion-inline-code">uv remove pkg</code> 移出依赖,添加的时候可以指定版本</div><div class="notion-blank notion-block-a2318321be5c4bdf9125eed1361cb01b"> </div><div class="notion-text notion-block-ed04b98e00374230ab231ed8eaad6f6c">下面截图就是我执行了 <code class="notion-inline-code">uv add utilmeta pymysql</code> 之后的结构</div><div class="notion-blank notion-block-4198ab63db4949a99f0225f61091ac29"> </div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-1535aff0435d48f08662a11850f5250f"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column;height:100%"><img style="object-fit:cover" src="https://www.notion.so/image/attachment%3Aec0b325f-f068-4cc3-a6c7-d95ee874965a%3Aimage.png?table=block&amp;id=1535aff0-435d-48f0-8662-a11850f5250f&amp;t=1535aff0-435d-48f0-8662-a11850f5250f" alt="notion image" loading="lazy" decoding="async"/></div></figure><div class="notion-blank notion-block-02e929731a5e4d24b31008eb03e6581f"> </div><h4 class="notion-h notion-h3 notion-h-indent-2 notion-block-6ea2493318f74238a39667967cb18522" data-id="6ea2493318f74238a39667967cb18522"><span><div id="6ea2493318f74238a39667967cb18522" class="notion-header-anchor"></div><a class="notion-hash-link" href="#6ea2493318f74238a39667967cb18522" title="安装并使用 python 包工具"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">安装并使用 python 包工具</span></span></h4><div class="notion-text notion-block-a22dc84dccfb4da882f17084213bbae8">有的人可能不太理解这一节内容是干嘛的，我举个例子，当你使用 ruff 格式化工具和 pre-commit钩子的时候，一般情况下是依赖某个 python 环境下安装的，而这个环境又可能与某个 project 绑定，当你切换到新项目工作时，难道还得重复安装一遍 ruff 或包含全路径的 ruff命令去执行？为了简单起见，可以使用<code class="notion-inline-code">uv tool</code> 相关命令。</div><div class="notion-text notion-block-1f619b572e2e493b8734b8a2d3e1db1f">安装 ruff</div><div class="notion-text notion-block-36ca7afa4c57474fadff6ce79455b69a"><code class="notion-inline-code">uv tool install ruff</code></div><div class="notion-text notion-block-7796752500514376be759995474d4ca9">使用 ruff, <code class="notion-inline-code">uvx</code> 等价于<code class="notion-inline-code"> uv tool run</code></div><div class="notion-text notion-block-29cd7e8b0b7a48338296167146361046"><code class="notion-inline-code">uvx ruff check</code></div><div class="notion-text notion-block-0ccdf7404414485d9136306cdcb0b2d6">查看包安装路径</div><div class="notion-text notion-block-5ee7141bf48441118274d0229c4edab5"><code class="notion-inline-code">uv tool dir</code> </div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-4450dd7fdc8541a89b6b93c32678e486"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column;height:100%"><img style="object-fit:cover" src="https://www.notion.so/image/attachment%3A920183ea-f387-4a70-b37a-7ca23333cc56%3Aimage.png?table=block&amp;id=4450dd7f-dc85-41a8-9b6b-93c32678e486&amp;t=4450dd7f-dc85-41a8-9b6b-93c32678e486" alt="notion image" loading="lazy" decoding="async"/></div></figure><div class="notion-blank notion-block-18068802714647999f5af4aa166e500a"> </div><div class="notion-blank notion-block-697c3fc41db74caabb956375ac9e80f1"> </div><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-400884e8a0b94906ba6052b00592fefc" data-id="400884e8a0b94906ba6052b00592fefc"><span><div id="400884e8a0b94906ba6052b00592fefc" class="notion-header-anchor"></div><a class="notion-hash-link" href="#400884e8a0b94906ba6052b00592fefc" title="📎 参考文章"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">📎 参考文章</span></span></h2><ul class="notion-list notion-list-disc notion-block-16b88f006ca1434bad1a4922cd007ad3"><li><a class="notion-link" href="https://docs.astral.sh/uv/reference" target="_blank" rel="noopener noreferrer">uv  doc</a></li></ul><ul class="notion-list notion-list-disc notion-block-0b25dbc7497343d0810e364667eaa128"><li><a class="notion-link" href="https://github.com/astral-sh/uv" target="_blank" rel="noopener noreferrer">uv github</a></li></ul><div class="notion-blank notion-block-10b63c66ac838042b811f30af652dc2e"> </div></main></div>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[2023年回顾]]></title>
            <link>https://cherrymelon.top/article/e7afe70d-6e11-4b24-8190-4d17360d28e3</link>
            <guid>https://cherrymelon.top/article/e7afe70d-6e11-4b24-8190-4d17360d28e3</guid>
            <pubDate>Sun, 07 Jan 2024 00:00:00 GMT</pubDate>
            <description><![CDATA[2023年的一点回顾]]></description>
            <content:encoded><![CDATA[<div id="notion-article" class="mx-auto overflow-hidden "><main class="notion light-mode notion-page notion-small-text notion-block-e7afe70d6e114b2481904d17360d28e3"><div class="notion-viewport"></div><div class="notion-collection-page-properties"></div><div class="notion-text notion-block-4a4277cb16d64679bac986aa8a3bcb17">  时间过得真快啊，一转眼一年就过去了，2023年春节回家接机的场景仿佛就在昨日，望向日历却发现2024年的春节已慢慢走近。大学室友接连在国庆和元旦拉开了人生中新的阶段，7年的爱情长跑终于修成正果，掐指一算，今年五一应是还有两个婚宴，一个发小玩伴的尽力而去，一个前任初恋的打死不去。根据周边观察，已婚的朋友们有娃的比例出乎意料的低，11对里面3对是有娃或者即将有娃的，还有一对结婚快6年了也还没打算要，只能说是窥见了时代的小小缩影。</div><div class="notion-text notion-block-b1ddf8aae4954aea9f4ad0bcc8aeedad">国庆回了一趟家，发现母亲手上的老人斑已经悄悄浮现，一如当年姥姥的手。在家短短呆了3天的生活算是有滋有味，睡到自然醒，下楼溜达到曾经上学时过早的地方点上一碗熟悉的米线，味道还是原来的味道。</div><div class="notion-text notion-block-6d44199761ef46b786c5e689c8c12d69">这一年见识了房地产开发商的“<em>眼见他</em>起<em>高楼</em>，<em>眼见他宴宾客</em>，<em>眼见他楼塌了</em>”，有人哭有人笑，头部房企重组，沪指下挫历史3000点，这应该是国内经济第一次遇到经济周期低谷，只能说，命运中一切的馈赠都标好了价格，开头简单的路到最后都是难走的。</div><div class="notion-text notion-block-cc05a74fdb8a448ba34d7d60bc0935b6">说到读书，这一年书看的比较杂，什么林政毅的《猫咪家庭医学大百科》，作为一个养猫人，了解一下猫的常见疾病症状。草草浏览了一遍萨缪尔森的第19版《经济学》，读下来的体验不太好，边际效应，比较优势等都是平时了解过的东西，如果有精炼版面向只想看重点的人士更好。《鸟哥的私房菜 第四版》这本书算是挺适合需要学习linux基础知识的人士，至少linux老手最多看下没见过的个别章节就行，因为里面磁盘的部分在机组书上已经见过，文件系统部分在操作系统书上也有。《Python源码剖析》，讲Python2.7解释器的源码，核心思路是与3.6往上区别不大，我只看了前四章，推荐有闲暇的人士看。《Fluent Python 第二版》，与第一版相比新增了3.6-3.10的特性，如typing，async await等，前面大半章节偏基础，后面异步，并发的部分可能实用性更强一点，元编程部分只读了前半部分，后面有遇到有需求的场景再翻书吧，捂脸。另外，b站有个up主，码农高天，做的Python视频挺不错。</div><div class="notion-text notion-block-d80d86ec0a584961bc20f5d8a38e719f">在混乱的后新冠时代，希望大家照顾好自己，照顾好家人，2024年快乐</div><div class="notion-blank notion-block-316b4230711b495194c2490705426ca7"> </div><div class="notion-blank notion-block-52986de8d53b4d309cdbcdc32ab3dfed"> </div></main></div>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[django migration 高级用法]]></title>
            <link>https://cherrymelon.top/article/c6407a53-4a35-41ac-8dae-cb20fa87b7cc</link>
            <guid>https://cherrymelon.top/article/c6407a53-4a35-41ac-8dae-cb20fa87b7cc</guid>
            <pubDate>Fri, 21 Jun 2024 00:00:00 GMT</pubDate>
            <content:encoded><![CDATA[<div id="notion-article" class="mx-auto overflow-hidden "><main class="notion light-mode notion-page notion-block-c6407a534a3541ac8daecb20fa87b7cc"><div class="notion-viewport"></div><div class="notion-collection-page-properties"></div><div class="notion-text notion-block-99899f2347bb4d4f9e677e9fb578d193">最近对于 django 的 migration 迁移因为有不一般的需求，于是搜集了一下不常见的使用场景。</div><h4 class="notion-h notion-h3 notion-h-indent-0 notion-block-5761c80aadce4770b3d2a0c79b7b2cce" data-id="5761c80aadce4770b3d2a0c79b7b2cce"><span><div id="5761c80aadce4770b3d2a0c79b7b2cce" class="notion-header-anchor"></div><a class="notion-hash-link" href="#5761c80aadce4770b3d2a0c79b7b2cce" title="情景一"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">情景一</span></span></h4><div class="notion-text notion-block-aadb37edabe9472698a13a73f4b0e31f">项目丢失 django migration历史记录，django 的 models 与数据库表结构不一致。</div><div class="notion-text notion-block-24222f8e0acd4512b17059557f687efa">这种情况下，数据库的django migration表只能提供有限参考，如果从django migration表的最后一条记录开始手动重建migrate，需要挨个比较每个model与数据库表的差异，然后在空白migrate文件里写入对应的操作，最后执行  <code class="notion-inline-code">python </code><code class="notion-inline-code"><a class="notion-link" href="http://manage.py" target="_blank" rel="noopener noreferrer">manage.py</a></code><code class="notion-inline-code"> migrate someapp 000X</code> ，一般来说成功更新就说明续上了，后续开发直接走make migation → migrate的流程就行了</div><div class="notion-blank notion-block-f3fc856464fd4589943bc4cc1c5122e9"> </div><h4 class="notion-h notion-h3 notion-h-indent-0 notion-block-cdeeebdca0784701a46cc75ff882455d" data-id="cdeeebdca0784701a46cc75ff882455d"><span><div id="cdeeebdca0784701a46cc75ff882455d" class="notion-header-anchor"></div><a class="notion-hash-link" href="#cdeeebdca0784701a46cc75ff882455d" title="情景二"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">情景二</span></span></h4><div class="notion-text notion-block-399438a034084ffa9e9c16a619246e44">项目缺少 migration 文件，但是 models 与当前数据库一致。</div><div class="notion-text notion-block-48278756d0294caab4dc356ddb8c8075">这种情况需要从头开始重建migration文件，一般来说，可以考虑只生成两个文件，0001和0002，0001对应model现状，即一系列表的创建命令，0002作为当前你要增加的修改。对于每个app，首先对0001 执行 <code class="notion-inline-code">python </code><code class="notion-inline-code"><a class="notion-link" href="http://manage.py" target="_blank" rel="noopener noreferrer">manage.py</a></code><code class="notion-inline-code"> migrate someapp 0001 —fake</code>, 这代表更新model到0001的状态但是不实际执行，运行完这个命令后，你的数据库和model应该是一致的，相当于把历史的各个migrate记录压缩到了0001migration里</div><div class="notion-blank notion-block-ef6e1fd816ce47ec815ab02597a8da0b"> </div></main></div>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[git stash 与 git worktree 切换分支方式]]></title>
            <link>https://cherrymelon.top/article/58fddcc4-2a48-4d83-8579-1c7f9c323a54</link>
            <guid>https://cherrymelon.top/article/58fddcc4-2a48-4d83-8579-1c7f9c323a54</guid>
            <pubDate>Thu, 16 Nov 2023 00:00:00 GMT</pubDate>
            <description><![CDATA[除了 git stash ，介绍另一种优雅的切换分支的方式]]></description>
            <content:encoded><![CDATA[<div id="notion-article" class="mx-auto overflow-hidden "><main class="notion light-mode notion-page notion-small-text notion-block-58fddcc42a484d8385791c7f9c323a54"><div class="notion-viewport"></div><div class="notion-collection-page-properties"></div><h4 class="notion-h notion-h3 notion-h-indent-0 notion-block-110ee400f60b4ae4be10f62f0eb2e322" data-id="110ee400f60b4ae4be10f62f0eb2e322"><span><div id="110ee400f60b4ae4be10f62f0eb2e322" class="notion-header-anchor"></div><a class="notion-hash-link" href="#110ee400f60b4ae4be10f62f0eb2e322" title="如果开发中遇到一个紧急修复需求，你会怎么做？"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">如果开发中遇到一个紧急修复需求，你会怎么做？</span></span></h4><div class="notion-text notion-block-3133c225048c4dbeadb82fd51070f4cd">相信不少人看到这个问题下意识的会回答，使用 git stash 暂时存放当前的代码，然后基于最新的发版分支拉出一个 bugfix 分支进行开发。</div><div class="notion-text notion-block-7b098014abc34503befdf2249ae18dc7">有的会选择用 IDEA 全家桶的 shelve changes 功能，有的会选择用 commit 先保存当前工作代码。</div><div class="notion-text notion-block-ff1a8a931a8347b1875bd899d10b58e3">这些方式都可以满足需求，但是 git stash 容易忘记 pop，git commit 不够优雅，IDEA 的 shelve changes 软件限定。</div><div class="notion-text notion-block-ed4094db26504824a4cd6e3218e0c8bf">今天就介绍一下比较冷门的 git worktree，使用方式很简单。<div class="notion-text-children"><div class="notion-text notion-block-c2e38f106fa34c02ab6de605a056d9f8">首先基于你要拉取的分支创建一个新项目目录，<code class="notion-inline-code">git worktree add   your_new_workdir    your_need_pull_branch</code></div><div class="notion-text notion-block-05a792e815714886989c948e52883172">假如我有一个go-hello项目，要基于dev创建 patch新分支就可以这样写</div></div></div><div class="notion-text notion-block-d3e80bf000bd45e085d48ed0c63d092d">这样我们就在 go-hello项目的同级目录下创建了一个新的项目，然后就可以愉快的在新项目进行平行开发了。</div><div class="notion-text notion-block-70fa55a57e7041099063b597f8fc2093">当不用了之后，想要删除掉就输入</div><h4 class="notion-h notion-h3 notion-h-indent-0 notion-block-4959bf07afb24a6caa629da23d7560a3" data-id="4959bf07afb24a6caa629da23d7560a3"><span><div id="4959bf07afb24a6caa629da23d7560a3" class="notion-header-anchor"></div><a class="notion-hash-link" href="#4959bf07afb24a6caa629da23d7560a3" title="这样做优势在哪里？"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">这样做优势在哪里？</span></span></h4><div class="notion-text notion-block-1b7d53be61cf4ca6815b0bf6213187e8">主要有两个方面，一方面是git worktree add 只会复制真正发生改动的文件，未改动的文件指向的是原先的同一文件，对于大项目来说省下了不少磁盘空间。另一方面避免了在 git stash 后忘记切换或者代码有了冲突的情况</div></main></div>]]></content:encoded>
        </item>
    </channel>
</rss>