python-poetry / python-poetry/poetry

Packages can only contain one destination per file

Open
#3,437 0 comments 0 reactions 1 assignee View on GitHub

@Secrus is already working on this.

Since Oct 13, 2024.

kind/bug status/triage
Dominant language
Python
Stars
34.3k
Forks
2.5k
Avg merge
2d 19h
Merged PRs (30d)
30

Description

Using poetry 1.1.4 on windows 10 / py3.8.

I have created a repo to reproduce the bug and show the workaround here

In a nutshell: a file that is included in a package can only appear in one place in the dist package.

Use case: An old project is using top-level imports (loose python files in a folder without an init file 😱). I am migrating it to be part of a package (called it "helpers" in the example).

Until everyone migrated, I want to publish this library both as a package and as top-level imports, so I thought I'd hack this into my pyproject.toml:

packages = [
    { include = "helpers" },
    { include = "os_helper.py", from = 'helpers' }
]

When I use poetry install to create an environment, I can do both import os_helper and from helpers import os_helper however when I install the package through pip, only the package syntax sill work and the top level import is gone.

The .whl file don't have any file at the root of the archive.

The workaround is to organize the backward compatibility layer in a different folder. Maybe just a symbolic link on the folder would work? 🤷‍♂️ I took this opportunity to throw in some warnings.warn(DeprecationWarning) on the top-level stuff and using "import *" instead of having copies; maybe that's the right way to do it after all! 😅

But this is probably a bug since at the minimum, poetry install and pip install should yield the same end result.

(ref: discord)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.