我应该单独提交 .lock 文件更改吗?我应该为提交消息写什么?
Should I commit .lock file changes separately? What should I write for the commit message?
我正在为我的 Python 包管理器使用 poetry,但我相信这适用于任何编程实践。
我一直在做这件事,却不知道自己在做什么,或者我应该怎么做。
当您使用包管理器并安装新包时,通常会更改 .lock
文件以确保您的构建具有确定性。
通常,我会像这样提交这些更改:
$ git add poetry.lock pyproject.toml
$ git commit -m "Install packages: beautifulsoup4"
即,我每次 install/remove 一个包时都会提交一次。我这样做是因为我觉得这是我应该做的,但我不知道这是否真的是处理这个问题的正确方法。
我过得好吗?还是我应该遵守任何其他特定的约定和规则,以使其尽可能遵循最佳实践?
如果您开发可部署的应用程序(而不是库),official recommendation of the poetry maintainers 是提交锁定文件。
也就是说,我的个人经验是没有必要将锁定文件提交给 VCS。 pyproject.toml
文件是正确 构建指令 的参考,锁定文件是单个成功 部署 的参考。现在,我不知道 poetry.lock
的规范是什么,但在与同事合作的过程中,我经常遇到适得其反的情况,只删除它们就可以解决问题。
一个常见的问题是,使用不同的操作系统或 python 版本会导致不同的锁定文件,这就是行不通。我很乐意让我们的 CI 构建并保留一个权威的引用锁定文件以启用重新构建,但它仍然不会提交到存储库。
如果根据您的工作流程维护共享锁文件是可行的 - 太好了!您避免了管道中的一个步骤,少了一个需要担心的工件,并大大减少了构建时间(即使是中等规模的项目也可能需要几分钟才能完成完整的依赖关系解析)。
但就最佳实践而言,我会考虑将 poetry.lock
添加到 .gitignore
中 比您所做的更好的 实践,并且仅添加依赖项时提交 pyproject.toml
更改。
诗歌实际上在他们的网站上有一个关于这个的部分:https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
他们认为实际提交此文件很重要,因为这将显示在提交时使用了哪些版本的库。
Committing this file to VC is important because it will cause anyone who sets up the project to use the exact same versions of the dependencies that you are using. Your CI server, production machines, other developers in your team, everything and everyone runs on the same dependencies, which mitigates the potential for bugs affecting only some parts of the deployments. Even if you develop alone, in six months when reinstalling the project you can feel confident the dependencies installed are still working even if your dependencies released many new versions since then. (See note below about using the update command.)
For libraries it is not necessary to commit the lock file.
Commit your poetry.lock
file to version control. Committing this file to VC is important because it will cause anyone
who sets up the project to use the exact same versions of the
dependencies that you are using. Your CI server, production machines,
other developers in your team, everything and everyone runs on the
same dependencies, which mitigates the potential for bugs affecting
only some parts of the deployments. Even if you develop alone, in six
months when reinstalling the project you can feel confident the
dependencies installed are still working even if your dependencies
released many new versions since then... For libraries, it is not necessary to commit the lock file.
但是,如果您的团队使用不同的操作系统、hardware/CPU 类型等,并且您没有使用 Docker 等容器技术进行开发。我建议不要提交锁定文件,因为这会给团队带来很多问题。如果您的团队使用 Docker 进行构建,那很好。例如,如果您的锁定文件包含有关专门为 Linux 构建的库的信息,Windows 上 [从锁定文件安装] 就会出现问题。
我正在为我的 Python 包管理器使用 poetry,但我相信这适用于任何编程实践。
我一直在做这件事,却不知道自己在做什么,或者我应该怎么做。
当您使用包管理器并安装新包时,通常会更改 .lock
文件以确保您的构建具有确定性。
通常,我会像这样提交这些更改:
$ git add poetry.lock pyproject.toml
$ git commit -m "Install packages: beautifulsoup4"
即,我每次 install/remove 一个包时都会提交一次。我这样做是因为我觉得这是我应该做的,但我不知道这是否真的是处理这个问题的正确方法。
我过得好吗?还是我应该遵守任何其他特定的约定和规则,以使其尽可能遵循最佳实践?
如果您开发可部署的应用程序(而不是库),official recommendation of the poetry maintainers 是提交锁定文件。
也就是说,我的个人经验是没有必要将锁定文件提交给 VCS。 pyproject.toml
文件是正确 构建指令 的参考,锁定文件是单个成功 部署 的参考。现在,我不知道 poetry.lock
的规范是什么,但在与同事合作的过程中,我经常遇到适得其反的情况,只删除它们就可以解决问题。
一个常见的问题是,使用不同的操作系统或 python 版本会导致不同的锁定文件,这就是行不通。我很乐意让我们的 CI 构建并保留一个权威的引用锁定文件以启用重新构建,但它仍然不会提交到存储库。
如果根据您的工作流程维护共享锁文件是可行的 - 太好了!您避免了管道中的一个步骤,少了一个需要担心的工件,并大大减少了构建时间(即使是中等规模的项目也可能需要几分钟才能完成完整的依赖关系解析)。
但就最佳实践而言,我会考虑将 poetry.lock
添加到 .gitignore
中 比您所做的更好的 实践,并且仅添加依赖项时提交 pyproject.toml
更改。
诗歌实际上在他们的网站上有一个关于这个的部分:https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
他们认为实际提交此文件很重要,因为这将显示在提交时使用了哪些版本的库。
Committing this file to VC is important because it will cause anyone who sets up the project to use the exact same versions of the dependencies that you are using. Your CI server, production machines, other developers in your team, everything and everyone runs on the same dependencies, which mitigates the potential for bugs affecting only some parts of the deployments. Even if you develop alone, in six months when reinstalling the project you can feel confident the dependencies installed are still working even if your dependencies released many new versions since then. (See note below about using the update command.)
For libraries it is not necessary to commit the lock file.
Commit your
poetry.lock
file to version control. Committing this file to VC is important because it will cause anyone who sets up the project to use the exact same versions of the dependencies that you are using. Your CI server, production machines, other developers in your team, everything and everyone runs on the same dependencies, which mitigates the potential for bugs affecting only some parts of the deployments. Even if you develop alone, in six months when reinstalling the project you can feel confident the dependencies installed are still working even if your dependencies released many new versions since then... For libraries, it is not necessary to commit the lock file.
但是,如果您的团队使用不同的操作系统、hardware/CPU 类型等,并且您没有使用 Docker 等容器技术进行开发。我建议不要提交锁定文件,因为这会给团队带来很多问题。如果您的团队使用 Docker 进行构建,那很好。例如,如果您的锁定文件包含有关专门为 Linux 构建的库的信息,Windows 上 [从锁定文件安装] 就会出现问题。