question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue
  • 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: 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).

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6

github_iconTop GitHub Comments

1reaction
henribrucommented, 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.

1reaction
henribrucommented, 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
Read more comments on GitHub >

github_iconTop Results From Across the Web

Python namespace packages with Poetry - Stack Overflow
My problem happens when I start to build a second package, that needs the first one as dependency. The structure remains the same:...
Read more >
History | Poetry - Python dependency management and ...
Fix an issue where experimental.system-git-client could not be used via environment ... Ensured that when complete packages are created dependency inherits ...
Read more >
Running mypy and managing imports
If --no-namespace-packages is set, mypy will rely solely upon the presence ... You cannot point to a stub-only package (PEP 561) via the...
Read more >
PEP 561 – Distributing and Packaging Type Information
-stubs suffix on only the root namespace package. All stub-only namespace packages should omit · __init__.pyi files. · py.typed ...
Read more >
Dependency Management With Python Poetry
Poetry created the pyproject.toml file with two keys in place: requires : a list of dependencies that are required to build the package,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found