Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
3 tasks done
henribru opened this issue Oct 10, 2021 · 7 comments · Fixed by python-poetry/poetry-core#221
Closed
3 tasks done

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

henribru opened this issue Oct 10, 2021 · 7 comments · Fixed by python-poetry/poetry-core#221
Labels
area/build-system Related to PEP 517 packaging (see poetry-core) kind/bug Something isn't working as expected

Comments

@henribru
Copy link

henribru commented Oct 10, 2021

  • I am on the latest Poetry version.
  • I have searched the issues of this repo and believe that this is not a duplicate.
  • If an exception occurs when executing a command, I executed it again in debug mode (-vvv option).

Issue

PEP561 was recently updated to clarify how to structure stub-only packages for distributions that use namespace packages: python/peps#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).

@henribru henribru added kind/bug Something isn't working as expected status/triage This issue needs to be triaged labels Oct 10, 2021
@finswimmer finswimmer added the area/build-system Related to PEP 517 packaging (see poetry-core) label Dec 28, 2021
@breno-jesus-fernandes
Copy link

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
Copy link
Author

henribru commented Jun 1, 2022

@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
Copy link

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
Copy link
Author

henribru commented Jun 1, 2022

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
Copy link

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
Copy link
Author

henribru commented Jun 4, 2022

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

@mkniewallner mkniewallner removed the status/triage This issue needs to be triaged label Jun 11, 2022
Copy link

github-actions bot commented Mar 1, 2024

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 1, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area/build-system Related to PEP 517 packaging (see poetry-core) kind/bug Something isn't working as expected
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants