实时开发 Python 外部库,但 Poetry 不起作用

发布于 2025-01-21 03:39:57 字数 1508 浏览 1 评论 0原文

我有一个项目使用存储在单独存储库中的库。这个库 my-lib 包含我的应用程序使用的一些功能。我想将该库与我的主项目链接起来以实时开发它。换句话说,我想启动我的主项目并在后台编辑库,从而导致项目根据更改进行重建。我花了一些时间试图弄清楚,但没有运气。

这就是我所做的:

  1. 假设我有一个 Repo 文件夹,其中包含项目和 lib:
/Repo/my-lib/
/Repo/my-app/backend/
  1. my-app 内,我做了 poetry add ../。 ./my-lib (根据 THIS ),其中添加了依赖项里面的一个条目pypoetry.toml 文件:
my-lib = { path = "../../my-lib" }
  1. 我手动修改了此条目以:
my-lib = { path = "../../my-lib", develop = true }
  1. 启动我的项目并编辑库。

不幸的是,my-lib 中的更改并未反映在项目中。即使尝试poetry update my-lib也无济于事。

所以我检查了 .venv/site-packages 文件夹。我想知道 my-lib 是否是该文件夹的符号链接或物理副本,它是第二个。我希望这里应该发生某种链接。我在网上搜索了许多问题和主题,对我来说它看起来应该可以工作...

我正在从事的项目(特别是 lib 部分)非常困难,并且一直需要大量调试,因此删除 .venv/site-packages/my-lib 并一遍又一遍地重新安装 my-lib 确实很烦人和耗时。

也许,我的文件夹结构有问题?我的项目文件夹中有 virtualenv,因此整个项目结构如下所示:

/Repo/my-lib/
  pyproject.toml

/Repo/my-app/backend/
  .venv/
    lib
      python3.8/
        site-packages/
          my-lib/
  pyproject.toml

我正在使用最新版本的 [email protected] 并且它是使用他们的脚本安装的(而不是通过pip)。

I have a project that uses a library stored in a separate repository. This library my-lib contains some features that are used by my application. I want to link the lib with my main project to develop it in realtime. In other words, I want to start my main project and edit the lib in the background causing the project to rebuild on changes. I have spent some time trying to figure it out, but no luck.

This what I did:

  1. Suppose I have a Repo folder that contains both, the project and the lib:
/Repo/my-lib/
/Repo/my-app/backend/
  1. Inside my-app I did poetry add ../../my-lib (according to THIS), which added an entry in dependencies inside pypoetry.toml file:
my-lib = { path = "../../my-lib" }
  1. I modified this entry manually to:
my-lib = { path = "../../my-lib", develop = true }
  1. Started my project and edited the lib.

Unfortunately, changes in my-lib are not reflected in the project. Even trying poetry update my-lib does not help.

So I checked .venv/site-packages folder. I wanted to know if my-lib is a symlink or physical copy of the folder and it is the 2nd one. I would expect that some kind of linking should happen here. I searched through many issues and topics in the Web and for me it looks like it should work...

The project I'm working on (especially lib part) is very hard and needs much of debugging all the time, so removing .venv/site-packages/my-lib and reinstalling my-lib over and over again is really annoying and time consuming.

Maybe, my folder structure is a problem here? I have virtualenv inside my project folder, so the whole project structure looks like:

/Repo/my-lib/
  pyproject.toml

/Repo/my-app/backend/
  .venv/
    lib
      python3.8/
        site-packages/
          my-lib/
  pyproject.toml

I'm using the newest version of [email protected] and it was installed using their script (not via pip).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

风月客 2025-01-28 03:39:57

我最终使用的解决方案是:

my-lib = { path = "../../my-lib", develop = true }

但我还做了一些始终有效的附加步骤:

  1. 删除 .venv 文件夹
  2. poetry cacheclear --all .
  3. poetry lock --no-update
  4. poetry install

在这些步骤之后,一切都工作正常。

The solution I ended up finally is using:

my-lib = { path = "../../my-lib", develop = true }

But I also do some additional steps that work always:

  1. Delete .venv folder
  2. poetry cache clear --all .
  3. poetry lock --no-update
  4. poetry install

After these steps everything always works fine.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文