Search code examples
pythonmonorepopython-poetry

How to correctly attach poetry dependencies during build?


I have a poetry setup like the following:

- libs
  - notreal
    - pyproject.toml
    - notreal
      - __init__.py
      - main.py
- services
  - one
    - pyproject.toml
    - one
      - __init__.py
      - main.py

Within one/main.py, I am doing the following:

from notreal.main import main as notrealfunc

def main():
    notrealfunc()


if __name__ == '__main__':
    main()

where the pyproject.toml is

[tool.poetry]
name = "one"
version = "0.1.0"
description = ""
authors = ["Bob Ross <[email protected]>"]

[tool.poetry.dependencies]
python = "^3.9"
notreal = {path = "./notreal-0.1.0-py3-none-any.whl"}

[tool.poetry.dev-dependencies]
pytest = "^5.2"
notreal = {path = "../../libs/notreal"}

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

When I run poetry run python service_one/main.py, it works as expected.

The issue comes from when I build the project with poetry build, then try to run the installation step from the setup.py file. It does not correctly install the wheel file.

When the service build cmd creates a /dist directory, I do copy over the wheel file from the build output of the library to the /dist of the service.

The output reads as such:

 Invalid URL: notreal-0.1.0-py3-none-any.whl

I have done some research on this, where it appears that this can be resolved by changing the dependency to a dev dependency and running the package with poetry run. I do not want this though, as I plan to ship the application without poetry.

So that brings me to my question. How can I do this correctly? I am basically trying to get a mono repo working with poetry. Where the build of the repo can be packaged and used without poetry installed.


Solution

  • Skip the usage of setup.py generated by poetry, and install the local wheel files directly. After that, it should run with python -m one.main