pythonpython-packagingpython-poetrysdist

Python: How to make Poetry include a package/module that's not on a subpath?


I have, in a single repo, two Python projects that both depend on a shared utility package. My goal is to package each of the two projects in a software distribution package (i.e. a .tzr.gz file)

I am currently getting this done using setuptools and setup.py files and having a hard time of it. I would much rather use Poetry to manage and package each of the two projects separately.

Please consider this "minimal repro" of my problem:

repo
    project1/ 
        __init__.py
        main_module.py
        pyproject.toml
    project2/ 
        __init__.py
        main_module.py
        pyproject.toml
    util/
        __init__.py
        util_module.py

I tried to get Poetry to include the util package when building project1 by modifying its project.toml this way:

[tool.poetry]
name = "project1"
version = "0.1.0"
description = ""
authors = [""]
packages = [
    { include = "../util/*.py" }
]

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

[tool.poetry.dev-dependencies]
pytest = "^5.2"

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

When I run poetry build I get this error:

Building project1 (0.1.0)
  - Building sdist

  ValueError

  'C:\\repo\\util\\__init__.py' is not in the subpath of 'C:\\repo\\project1' OR one path is relative and the other is absolute.

  at ~\.pyenv\pyenv-win\versions\3.9.6\lib\pathlib.py:929 in relative_to
       925│         n = len(to_abs_parts)
       926│         cf = self._flavour.casefold_parts
       927│         if (root or drv) if n == 0 else cf(abs_parts[:n]) != cf(to_abs_parts):
       928│             formatted = self._format_parsed_parts(to_drv, to_root, to_parts)
    →  929│             raise ValueError("{!r} is not in the subpath of {!r}"
       930│                     " OR one path is relative and the other is absolute."
       931│                              .format(str(self), str(formatted)))
       932│         return self._from_parsed_parts('', root if n == 1 else '',
       933│                                        abs_parts[n:])

Doesn't poetry support my use-case? If not, what am I missing?

Alternatively, please suggest another approach to package my two projects separately, but both packages must include the shared util package.


Solution

  • This seems to be a issue with poetry. Check this out https://github.com/python-poetry/poetry/issues/5621.