Search code examples
python-3.xdependenciespython-poetry

Cannot specify dependency in parent folder with Poetry


I have the following file hierarchy:

./
├── abc
│   ├── pyproject.toml
│   ├── main.py
│   └── xyz 
│      ├── __init__.py
│      └── other.py
└── common-lib
    ├── pyproject.toml
    └── common
        ├── __init__.py
        └── lib1.py

In pyproject.toml file of abc, I cannot seem to add common-lib as a dependency no matter how I try. One example is as below. I checked many similar questions.

[tool.poetry]
packages = [{ include = "common", from = "common-lib" }]
[tool.poetry.dependencies]
common-lib = { path = "../common-lib", develop=true}

I receive the following error.

Updating dependencies
Resolving dependencies...

Package operations: 1 install, 0 updates, 0 removals

  • Installing common-lib (0.1.0 somePath/common-lib)

  ModuleOrPackageNotFound

  No file/folder found for package common-lib

  at ~\AppData\Roaming\Python\Python310\site-packages\poetry\core\masonry\utils\module.py:63 in __init__
       59│                             "from": str(src.relative_to(self._path)),
       60│                         }
       61│                     ]
       62│                 else:
    →  63│                     raise ModuleOrPackageNotFound(
       64│                         "No file/folder found for package {}".format(name)
       65│                     )
       66│
       67│         for package in packages:

Could you help me solving this problem?


Solution

  • I managed to solve the issue with the following settings in the pyproject.toml.

    [tool.poetry]
    packages = [{ include = "common", from = "../common-lib"}]
    [tool.poetry.dependencies]
    common-lib = "../common-lib"