Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I correctly include a path dependency in pyproject.toml?

I have 2 projects structured as below:

/abc-lib
  / abc
    / __init__.py
    / main.py
  / pyproject.toml


/abc-web-api
  / src
    / __init__.py
    / main.py
  / pyproject.toml

I attempted to include abc-lib as a dependency in abc-web-api, thus having a abc-web-api/pyproject.toml as below:

[tool.poetry]
name = "abc-web-api"
version = "0.0.1"
description = "Some description."
authors = ["Someone <[email protected]>"]
repository = "https://github.com/someone/abc-web-api"
readme = "README.md"


[tool.poetry.scripts]
serve = "src.main:app"


[tool.poetry.dependencies]
python = "~3.6.8"
abc-lib = { path="../abc-lib" }


[tool.poetry.dev-dependencies]
pytest = "^3.10.1"
yapf = "^0.30.0"
flake8 = "^3.8.3"


[build-system]
requires = ["poetry>=0.12"]
build-backend = "poetry.masonry.api"

When I execute poetry install, I receive the following message:

Package operations: 1 installs, 0 updates, 0 removals

  - Installing abc-lib (1.0.0 ../abc-lib)

[ModuleOrPackageNotFound]
No file/folder found for package abc-lib

The version number shown in the "Installing" statement is correct, so I am quite confused about the meaning of [ModuleOrPackageNotFound].

Does anyone know how can I resolve it? Thanks

like image 646
clifflau1120 Avatar asked Jul 28 '20 07:07

clifflau1120


1 Answers

Your folder structure looks a bit weird. It looks like your prefer the "src" variant. So I would suggest the following:

./
├── abc-lib
│   ├── pyproject.toml
│   └── src
│       └── abc_lib
│           ├── __init__.py
│           └── main.py
└── abc-web-api
    ├── pyproject.toml
    └── src
        └── abc_web_api
            ├── __init__.py
            └── main.py

With this pyproject.toml in abc-lib:

[tool.poetry]
name = "abc-lib"
version = "0.1.0"
description = ""
authors = ["Someone <[email protected]>"]


[tool.poetry.dependencies]
python = "^3.6"

[tool.poetry.dev-dependencies]

[build-system]
requires = ["poetry>=1.0"]
build-backend = "poetry.masonry.api"

And this in abc-web-api:

[tool.poetry]
name = "abc-web-api"
version = "0.1.0"
description = ""
authors = ["Someone <[email protected]>"]


[tool.poetry.dependencies]
python = "^3.6"
abc-lib = {path = "../abc-lib"}

[tool.poetry.dev-dependencies]

[build-system]
requires = ["poetry>=1.0"]
build-backend = "poetry.masonry.api"
like image 115
finswimmer Avatar answered Nov 15 '22 16:11

finswimmer