触发依赖更新时重新安装本地诗歌

huangapple go评论59阅读模式
英文:

Triggering a local poetry reinstall on dependency update

问题

当依赖项发生更改时,我需要代码失败以便我注意到并运行 poetry install。有没有更好的方法来做这个?理想情况下,当我运行 poetry 时,如果 pyproject.toml 与已安装的内容不匹配,我希望它能够注意到并要么警告我,要么继续更新包版本。

英文:

Right now, if a dependency changes, I need the code to fail for me to notice and run a poetry install. Is there a better way to do this?
Ideally, when I run poetry and the pyproject.toml doesn't match what's installed I'd like it to notice and either warn me or go ahead and update package versions.

答案1

得分: 1

通常这些问题会通过以下方式解决:

  • 使用像Github Actions这样的持续集成服务

  • 设置拉取请求工作流程

  • 配置一个自动为更新的依赖项打开新拉取请求的机器人

查看Github的Dependabot

英文:

Usually these are dealth with

  • Having a continuous integration service like Github Actions

  • Have a pull request workflow

  • Have a bot that automatically opens new pull request for updated dependencies

See Dependabot by Github.

答案2

得分: 1

我假设您想使用Poetry在本地virtualenv中更新依赖,每当您切换到一个分支时,该分支可能具有已修改的Poetry锁定文件。

这可以通过使用git post-checkout hook来完成,它在您检出分支或拉取新提交时运行。

要配置它以运行 poetry install --sync,您需要创建(或修改现有的)文件 .git/hooks/post-checkout(并添加 +x 权限):

#!/bin/sh
poetry install --sync

不足之处在于,它还会在您检出(还原)单个文件时运行。您可以通过检查第三个参数,并仅在检出分支时运行来防止这种情况:

#!/bin/sh
flag=$3
if [[ "$flag" -eq 1 ]]; then
  poetry install --sync
fi

对于一个单一代码仓库,您可以为每个相对路径创建一个调用,如下所示:

#!/bin/sh
flag=$3
if [[ "$flag" -eq 1 ]]; then
  echo "updating root project"
  poetry install --sync
  echo "updating subproject"
  poetry -C $(pwd)/sub-project-A install --sync
fi

如果没有 $(pwd),您可能会遇到Poetry错误 relative path can't be expressed as a file URI

英文:

I assume you want to update your local virtualenv with poetry, whenever you checkout a branch with (possibly) modified poetry lock files.

This can be done with a git post-checkout hook, which runs whenever you check out a branch, or pulling in new commits.

To configure it to run a poetry install --sync, you need to create (or modify an existing) file .git/hooks/post-checkout (with +x):

#!/bin/sh
poetry install --sync

The downside is that it also runs when you checkout (revert) a single file. That can be prevented by checking the 3rd argument, and only running when a branch is checked out:

#!/bin/sh
flag=$3
if [[ "$flag" -eq 1 ]];then
  poetry install --sync
fi

For a mono-repo you could create an invocation for every relative path as follows:

#!/bin/sh
flag=$3
if [[ "$flag" -eq 1 ]];then
  echo "updating root project"
  poetry install --sync
  echo "updating subproject"
  poetry -C $(pwd)/sub-project-A install --sync
fi

Without the $(pwd) you (can) get the poetry error relative path can't be expressed as a file URI.

huangapple
  • 本文由 发表于 2023年6月27日 19:38:06
  • 转载请务必保留本文链接:https://go.coder-hub.com/76564465.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定