Project isn't updated to the directory set by "directory" argument
Description
I am not sure if it is, but it looks like a bug, when I run poetry --directory path/to/project build I get an error:
WARNING: No build backend defined. Please define one in the pyproject.toml. ...
(backend is set under "path/to/project/pyproject.toml")
... Readme path
path/to/project/README.mddoes not exist.
It's weird because if I run Poetry from said directory by changing directory on shell it does work correctly without any issues: poetry build.
Maybe my understanding about this is wrong.
Workarounds
- Changing directory to project manually and running build works:
cd path/to/project && poetry build - Appending
--project ./seems to work as well. This is weird, I'd assume project is automatically set to "currect directory" when it is changed with--directorybut it's not. So you have to manually switch it by doing something like this:
poetry --directory path/to/project --project ./ build
which seems to work correctly as well.
Poetry Installation Method
pip
Operating System
RHEL9
Poetry Version
2.1.1
Poetry Configuration
Fully vanilla config, only changes are source repositories which are PyPi mirrors.
Python Sysconfig
No response
Example pyproject.toml
[tool.poetry]
name = "poetry-demo"
version = "0.1.0"
description = ""
authors = ["My name", "[email protected]"]
readme = "README.md"
package-mode = true
packages = [
{ include = "src" }
]
[tool.poetry.dependencies]
python = "^3.9"
boto3 = "^1.35.54"
poethepoet = "^0.33.0"
requests = "^2.32.3"
[[tool.poetry.source]]
name = "nexus"
url = "https://nexus.net/repo/repository/pypi/simple/"
priority = "primary"
[tool.poetry.group.dev.dependencies]
nox = "^2024.10.9"
poethepoet = "^0.33.0"
pytest = "^8.3.5"
nox-poetry = "^1.2.0"
[tool.poetry.requires-plugins]
poetry-plugin-export = ">=1.8"
[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
Poetry Runtime Logs
Sorry, I can't get these right now, let me know if these are mandatory.
I found that publish command has the same behavior in regard to this.
I can confirm this with poetry 2.1.1 under windows and the build command. The problem only occurs, when specifying packages with an explicit "src" in it. Like in the example of @Levelleor:
packages = [
{ include = "src" }
]
And in my example:
packages = [
{ include = "sub_package" , to = "minimal.sub_package", from = "minimal"}
]
Reproduce
Here is a minimal Example to repdoduce this error:
Steps
- Unzip
- run
poetry --no-interaction build --output dist- Works, as expected
- run
poetry --directory "." --no-interaction build --output dist- Fails with
FileNotFoundError, expected same behavior
- Fails with
EDIT: fixed the uploaded zip
EDIT2: Narrow down the problem (only when specifying src)
Oh, this seems a bit more complex than I have expected. Thank you, @the-working-rene, for the reproducible example, hopefully we get some attention on it. Wouldn't want the fix (if one is expected) to break things though.
Hey,
I cannot reproduce the original reported issue, but see a different one:
$ poetry build --directory ../i10582
Building i10582 (0.1.0)
Building sdist
- Building sdist
- Built i10582-0.1.0.tar.gz
Building wheel
- Building wheel
'/home/finswimmer/tmp/poetry/i10582/i10582/src/i10582/__init__.py' is not in the subpath of '/home/finswimmer/tmp/poetry/i10582/src' OR one path is relative and the other is absolute.
We can fix it by returning an absolute Path here: https://github.com/python-poetry/poetry/blob/17db1da55ab6aac011e33434e8d80a76780ff056/src/poetry/utils/helpers.py#L261
But I'm not sure if we fix the root cause this way or there is something we need to fix in poetry-core for handling relative paths. (The wrong path shown above is created here: https://github.com/python-poetry/poetry-core/blob/185ea749d2caebbcfce8a4c526dd650b69b11b27/src/poetry/core/masonry/builders/builder.py#L361)
fin swimmer