python-poetry / poetry

Python packaging and dependency management made easy
https://python-poetry.org
MIT License
31.1k stars 2.25k forks source link

Namespace stub-only packages can't be built with Poetry #4621

Closed henribru closed 2 years ago

henribru commented 2 years ago

Issue

PEP561 was recently updated to clarify how to structure stub-only packages for distributions that use namespace packages: https://github.com/python/peps/pull/2083 To summarize, the namespace packages should not have py.typed and __init__.pyi, these should be further down the directory tree in the actual packages. Poetry doesn't support building stub-only packages with this structure, you end up hitting this exception: https://github.com/python-poetry/poetry-core/blob/master/poetry/core/masonry/utils/package_include.py#L83 The reason is that this check is too strict: https://github.com/python-poetry/poetry-core/blob/master/poetry/core/masonry/utils/package_include.py#L49-L54 It expects each file to be either a py.typed in the root or a .pyi, which doesn't hold if you have one or more py.typed files further down the tree. Seems like simply removing the el.parent.name == self.package check would fix this issue, so I'd be happy to do a PR for that (though I'm not sure that it's invalid for stub-only packages to include other file types so the check might still be a bit strict).

breno-jesus-fernandes commented 2 years ago

Issue

When I add scripts to my pyproject.toml for example:

[tool.poetry.scripts]
some-script = "another_pkg:script:my_function"

I got an error showing that my main stub-only-package is not a package.

Error log: https://github.com/BrenoJesusFernandes/poetry-stubs-error/blob/master/error.log

Is it a bug or am I doing something wrong?

henribru commented 2 years ago

@BrenoJesusFernandes That should probably be its own issue but:

  1. Your pyproject.toml says pandas is inside typings, but it's actually just directly in the root?
  2. Your package is called pandas but stub-only packages need to have a -stubs suffix
breno-jesus-fernandes commented 2 years ago

I had no idea about the second one and works!! But tell me when we build for example the pkg pandas-stubs the stubs are gonna be installed inside the pandas normally?

henribru commented 2 years ago

I had no idea about the second one and works!! But tell me when we build for example the pkg pandas-stubs the stubs are gonna be installed inside the pandas normally?

From my understanding it's installed as an entirely separate package and pip and Poetry don't know that pandas and pandas-stubs are related. But your typechecker knows they are so it looks for pandas-stubs to typecheck pandas.

breno-jesus-fernandes commented 2 years ago

Thx for the tip I am new in the world of stubs, I was looking into the pandas stubs project but it was really unclear how things work and I was trying to improve the project by bringing poetry to the battle, do you know why poetry use *-stubs to recognize a stub-only package? Is there a PEP talking about it?

henribru commented 2 years ago

Yeah, should be among the first results if you google "python stub only package"

github-actions[bot] commented 6 months ago

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.