-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
default pyproject.toml from poetry init -n improperly handles src layout; reports installation success even though it cannot actually be imported #7609
Comments
packages = [
{ include = "poetry", from = "src" }
] per poetry's own usage It's impossible for I expect docs improvements explaining this would be welcome, please contribute! |
Okay, was that changed recently? I must have done this sequence of commands dozens of times and I never ran into this problem before. Also I think the "does not contain any element" error message would be clearer as "directory does not exist"? since it's looking for a nonexistent |
not so far as I know |
Okay I'm not crazy, I tested it and the following works on Poetry version 1.1.15, like how I remember: #! /usr/bin/bash
set -euo pipefail
cd /tmp
rm -rf fancy-project
mkdir fancy-project
cd fancy-project
touch README.md
mkdir -p src/fancy_project
touch src/fancy_project/__init__.py
echo 'def hello():' >> src/fancy_project/something.py
echo ' print("this is a fancy project!")' >> src/fancy_project/something.py
poetry init -n
poetry install
poetry run python -c 'from fancy_project.something import hello; hello()' The culprit seems to be that 1.1.15 doesn't populate the [tool.poetry]
name = "fancy-project"
version = "0.1.0"
description = ""
authors = ["aaaa <[email protected]>"]
[tool.poetry.dependencies]
python = "^3.10"
[tool.poetry.dev-dependencies]
[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api" I looked in the release notes but I can't figure out why this was changed. The default config used to be able to figure out src layouts but now it can't. |
it's because you're using a name with a dash in it. You can probably make it skip the explicit package by making this comparison be against edit: or possibly it would be better the other way round, and the comparison should be against again, contributions welcome |
Yes you're right, it works when I change everything to I'll see if I can figure out a PR for it. |
Thank you for this issue. I've stumbled across the same error, and sure it is confusing! In my case, my |
you - and all readers - are invited to submit an MR with a fix as outlined at #7609 (comment) |
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. |
-vvv
option) and have included the output below.Issue
Trying to make simple hello-word package in src layout. The default pyproject.toml created with
poetry init -n
does not let me install it properly.To begin with, my file structure is like this:
The
__init__.py
file is blank. Thesomething.py
file contains this:When I run
poetry init -n
, it generates the following (sanitized)pyproject.toml
.When I run
poetry install
, I get this error:When I amend
pyproject.toml
to change theinclude = "fancy_project"
toinclude = "src"
, thepoetry install
command seems to succeed:However, the package is not actually importable:
I tried changing the include line to say
include = "src/fancy_project"
. It similarly reports a successful install, but the import fails just the same.I tried removing the
packages
line frompyproject.toml
entirely. This time it works:But I don't understand why. I don't remember ever having to muck around with the
packages
line; everything "just worked" the last time I tried this with a src layout.I believe there is at least one bug here:
poetry init -n
should make a pyproject.toml that can work with src layoutpoetry install
should not say that an installation succeeded when it actually didn'tpackages
don't clear up any of this confusion(PS: I ran
rm -rf .venv
before everypoetry install
command, to start from a clean slate each time)EDIT:
bash script to precisely reproduce the problem:
The text was updated successfully, but these errors were encountered: