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

Packages always included even if they are not listed in packages #8213

Closed
3 of 4 tasks
antazoey opened this issue Jul 19, 2023 · 12 comments
Closed
3 of 4 tasks

Packages always included even if they are not listed in packages #8213

antazoey opened this issue Jul 19, 2023 · 12 comments
Labels
kind/bug Something isn't working as expected status/triage This issue needs to be triaged

Comments

@antazoey
Copy link

antazoey commented Jul 19, 2023

  • I am on the latest stable Poetry version, installed using a recommended method.
  • I have searched the issues of this repo and believe that this is not a duplicate.
  • I have consulted the FAQ and blog for any relevant entries or release notes.
  • If an exception occurs when executing a command, I executed it again in debug mode (-vvv option) and have included the output below.

Issue

So the main issue I am having is that if I don't use a src directory to put my packages in and reference them from there, it will always include modules from my root project that I don't want in the Python build. For example, it always includes both scripts and tests which are not part of the package.

By includes, this is what I mean: If I install my project that has this form and I go to my home directory, and I run:

python -c "import scripts; print(scripts.__path__)"

it will print out the path to the project I installed. So I can import tests and scripts from anywhere on my OS, and I am just trying to exclude that from happening.

The only way I have gotten it to work is to put the actual package first in a src directory and reference it like:

packages = [ { include = "my-package", from = "src" } ]

But really , I was hoping to not have to change the project structure. I don't want to have to create a src directory

I would prefer to do this:

packages = [{ include = "apepay" }]

and have it not include tests/ and scripts/.

I have tried every combo of include and exclude and packages but the only that actually works so far is the src directory.

@antazoey antazoey added kind/bug Something isn't working as expected status/triage This issue needs to be triaged labels Jul 19, 2023
@trag1c
Copy link
Member

trag1c commented Jul 19, 2023

Fix the pyproject.toml link

@antazoey
Copy link
Author

Fix the pyproject.toml link

It's fixed now, sorry about that

@dimbleby
Copy link
Contributor

what you are describing is already the default behaviour and you don't have to specify packages at all, please close.

(I suspect you are simply in a virtual environment where the sys.path includes the root of your codebase)

@antazoey
Copy link
Author

Ok thank you, sorry I guess

@antazoey
Copy link
Author

antazoey commented Jul 19, 2023

@dimbleby just note, it doesnt happen when I use setup.py and the include / packages field for find_packages(), I wish it behaved similarly

@antazoey
Copy link
Author

Like I had this same problem when I did:

find_packages(exclide=["scripts"])

but it was fixed when I did:

    packages=["my-package"],

but I tried the equivalent in Poetry and it did not fix

@antazoey
Copy link
Author

antazoey commented Jul 19, 2023

I either have to use setup.py and not poetry, or I have to change my project structure in order install in editable mode for my project (and not have other packages appear in my path), unless I am just missing something or there is a bug.

@antazoey antazoey reopened this Jul 20, 2023
@dimbleby
Copy link
Contributor

you've reopened it, but this is still nothing to do with poetry

the way editable installs work is by creating a .pth file, which causes the directory that it points at to be added to the python sys.path. See https://setuptools.pypa.io/en/latest/userguide/development_mode.html. That's what allows your project to be imported.

so all you are seeing is - as I said - that the root of your repository is in your sys.path.

if you build the wheel you can inspect it and verify that it contains only the files that you expect.

Please close.

@antazoey antazoey reopened this Jul 20, 2023
@dimbleby
Copy link
Contributor

if this is important to you then not using poetry is the right choice.

I have confirmed that a project using pyproject.toml and any backend chosen from flit, hatch, pdm, and setuptools behaves in the same way as poetry, so you'll want to avoid those too.

@dimbleby
Copy link
Contributor

dimbleby commented Jul 20, 2023

please read what I wrote: I specified "a project using pyproject.toml" behaves that way. You have - I think rightly - said that you have to use setup.py to avoid this behaviour.

my point is that this is nothing to do with poetry - all backends that I can find, including setuptools, then give the same behaviour

@antazoey
Copy link
Author

antazoey commented Jul 20, 2023

please read what I wrote: I specified "a project using pyproject.toml" behaves that way. You have - I think rightly - said that you have to use setup.py to avoid this behaviour.

OK, I am sorry.

Copy link

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 Feb 29, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
kind/bug Something isn't working as expected status/triage This issue needs to be triaged
Projects
None yet
Development

No branches or pull requests

3 participants